Merge pull request 'color' (#4) from color into master

Reviewed-on: #4
This commit is contained in:
Chris Cromer 2021-06-20 12:06:34 -04:00
commit de03ca1417
2 changed files with 39 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "color.h"
/** /**
* Get the logged in user's username. * Get the logged in user's username.
@ -53,7 +54,7 @@ char *get_working_directory() {
void print_input_line() { void print_input_line() {
char *name = get_user(); char *name = get_user();
char *cwd = get_working_directory(); char *cwd = get_working_directory();
printf("%s:%s $ ", name, cwd); printf(BRIGHT_CYAN "%s" MAGENTA "@" RED "localhost" MAGENTA ":" BLUE "%s" MAGENTA "$ " RESET, name, cwd);
free(name); free(name);
free(cwd); free(cwd);
} }

37
src/include/color.h Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright 2021 Christopher Cromer
* Copyright 2021 Raúl Hernandez
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _MYSHELLIN_COLOR
#define _MYSHELLIN_COLOR
#define BLACK "\x1B[30m"
#define BRIGHT_BLACK "\x1B[30;1m"
#define RED "\x1B[31m"
#define BRIGHT_RED "\x1B[31;1m"
#define GREEN "\x1B[32m"
#define BRIGHT_GREEN "\x1B[32;1m"
#define YELLLOW "\x1B[33m"
#define BRIGHT_YELLOW "\x1B[33;1m"
#define BLUE "\x1B[34m"
#define BRIGHT_BLUE "\x1B[34;1m"
#define MAGENTA "\x1B[35m"
#define BRIGHT_MAGENTA "\x1B[35;1m"
#define CYAN "\x1B[36m"
#define BRIGHT_CYAN "\x1B[36;1m"
#define WHITE "\x1B[37m"
#define BRIGHT_WHITE "\x1B[37;1m"
#define RESET "\x1B[0m"
#endif