Use color support where appropriate.

Color choice might still be refined, as could support for 8 bit colors.
This commit is contained in:
Érico Nogueira 2021-07-17 19:40:16 -03:00
parent 765316cf81
commit 089bb40acc
4 changed files with 16 additions and 5 deletions

9
ep.c
View File

@ -15,6 +15,7 @@
#include <errno.h>
#include <pthread.h>
#include "colors.h"
#include "info_strings.h"
#include "ep.h"
@ -81,7 +82,7 @@ int main(int argc, char **argv)
/* show we are on a different machine */
print_ssh();
print_pwd(home, pwd);
use_color(bcyan, print_pwd(home, pwd));
/* git status */
void *git_info;
@ -117,7 +118,7 @@ int main(int argc, char **argv)
if (n > 1) {
/* jobs emoji is wide */
p(" ");
p(shell_jobs);
use_color(blue, p(shell_jobs));
}
}
}
@ -140,13 +141,13 @@ int main(int argc, char **argv)
} else {
snprintf(dur, sizeof(dur), " %llds", command_duration);
}
p(dur);
use_color(green, p(dur));
}
/* 127 means command not found, that prints a big enough message already */
if (exit_status && exit_status != 127) {
char ex[256];
snprintf(ex, sizeof(ex), " [%d]", exit_status);
p(ex);
use_color(green, p(ex));
}
p(PROMPT);

5
git.c
View File

@ -5,6 +5,7 @@
#include <stdlib.h>
#include <pthread.h>
#include "colors.h"
#include "ep.h"
struct git_info {
@ -17,13 +18,15 @@ void print_git(void *arg)
if (git_info->git_branch_name) {
p(" ");
p(git_info->git_branch_name);
use_color(magenta, p(git_info->git_branch_name));
fg_color(blue);
if (git_info->git_status) {
p(" [");
p(git_info->git_status);
p("]");
}
reset_color();
}
}

4
lang.c
View File

@ -4,6 +4,7 @@
#include <stdint.h>
#include <fnmatch.h>
#include "colors.h"
#include "ep.h"
enum lang_index {
@ -49,11 +50,14 @@ const struct lang_check l[] = {
/* bitmap of 1<<lang_index */
void print_lang(uint64_t mask) {
/* only change color if we're going to print something */
if (mask) fg_color(red);
for (int i = 0; i < lang_index_n; i++) {
if (mask & (1 << i)) {
p(l[i].display);
}
}
if (mask) reset_color();
}
void *lang_thread(void *arg)

3
ssh.c
View File

@ -1,6 +1,7 @@
#include <stdlib.h>
#include <sys/utsname.h>
#include "colors.h"
#include "ep.h"
void print_ssh(void)
@ -16,8 +17,10 @@ void print_ssh(void)
if (uname(&u) || !u.nodename[0])
return;
fg_color(yellow);
p("(");
p(u.nodename);
p(") ");
reset_color();
}
}