feat: pretty colors!

This commit is contained in:
2026-10-09 16:41:04 +02:00
parent 7dc85ea994
commit 2396e4c869
2 changed files with 100 additions and 16 deletions

View File

@@ -9,6 +9,7 @@
#include <errno.h>
#include <termios.h>
#include "ansi.h"
#define ESC \x1B
@@ -36,18 +37,6 @@ void pretty_path_home(char** path) {
}
#define ANSI_UNKNOWN -1
#define ANSI_CURSOR_LEFT 0
#define ANSI_CURSOR_RIGHT 1
#define ANSI_CURSOR_UP 2
#define ANSI_CURSOR_DOWN 3
#define ANSI_DELETE_WORD 4
#define ANSI_CURSOR_LEFT_WORD 5
#define ANSI_CURSOR_RIGHT_WORD 6
#define ANSI_CURSOR_UP_WORD 7
#define ANSI_CURSOR_DOWN_WORD 8
int read_ansi() {
switch (getchar()) {
case '[':
@@ -133,6 +122,16 @@ size_t strnocspn(char* str, size_t n, size_t o, char* reject) {
}
char* status_string(int status) {
switch (status) {
case 0:
return "";
}
return "❗";
}
int main(int argc, char** argv) {
int retval = 0;
char* tokens[LINESIZE] = {};
@@ -190,10 +189,27 @@ int main(int argc, char** argv) {
pretty_path_home(&pwd_disp);
if (laststatus != 0) {
fprintf(stdout, "❌");
}
snprintf(prompt, LINESIZE, "%s@%s %s$ ", user, host, pwd_disp);
snprintf(
prompt,
LINESIZE,
ANSI_BG_BLUE ANSI_FG_BLACK
"%s" // status
" %s" // user
"@"
ANSI_FG_BLACK
"%s " // host
ANSI_COLOR_RESET ANSI_FG_BLUE
""
ANSI_FG_BLUE
"%s" // directory
ANSI_COLOR_RESET
"$ "
ANSI_COLOR_RESET,
status_string(laststatus), user, host, pwd_disp
);
printf("%s", prompt);