Skip to content

Commit

Permalink
Update cprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
Moe-hacker committed Nov 29, 2024
1 parent cb209c5 commit ea5f6d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/cprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define true ((_Bool) + 1u)
#define false ((_Bool) + 0u)
#endif
char *cprintf_base_color = "254;228;208";
static void print_rgb_fg_color(const char *_Nonnull color)
{
/*
Expand Down Expand Up @@ -153,7 +154,7 @@ static const char *cfprintf_print_fg_color(FILE *_Nonnull stream, const char *_N
} else if (strcmp(color, "{white}") == 0) {
fprintf(stream, "\033[37m");
} else if (strcmp(color, "{base}") == 0) {
fprintf(stream, "%s", CPRINTF_BASE_FG_COLOR);
fprintf(stream, "\033[1;38;2;%sm", cprintf_base_color);
} else if (strcmp(color, "{underline}") == 0) {
fprintf(stream, "\033[4m");
} else if (strcmp(color, "{highlight}") == 0) {
Expand Down Expand Up @@ -205,7 +206,7 @@ static const char *cprintf_print_fg_color(const char *_Nonnull buf)
} else if (strcmp(color, "{white}") == 0) {
printf("\033[37m");
} else if (strcmp(color, "{base}") == 0) {
printf("%s", CPRINTF_BASE_FG_COLOR);
printf("\033[1;38;2;%sm", cprintf_base_color);
} else if (strcmp(color, "{underline}") == 0) {
printf("\033[4m");
} else if (strcmp(color, "{highlight}") == 0) {
Expand Down Expand Up @@ -257,7 +258,7 @@ static const char *cfprintf_print_bg_color(FILE *_Nonnull stream, const char *_N
} else if (strcmp(color, "[white]") == 0) {
fprintf(stream, "\033[47m");
} else if (strcmp(color, "[base]") == 0) {
fprintf(stream, "%s", CPRINTF_BASE_BG_COLOR);
fprintf(stream, "\033[1;48;2;%sm", cprintf_base_color);
} else if (strcmp(color, "[underline]") == 0) {
fprintf(stream, "\033[4m");
} else if (strcmp(color, "[highlight]") == 0) {
Expand Down Expand Up @@ -309,7 +310,7 @@ static const char *cprintf_print_bg_color(const char *_Nonnull buf)
} else if (strcmp(color, "[white]") == 0) {
printf("\033[47m");
} else if (strcmp(color, "[base]") == 0) {
printf("%s", CPRINTF_BASE_BG_COLOR);
printf("\033[1;48;2;%sm", cprintf_base_color);
} else if (strcmp(color, "[underline]") == 0) {
printf("\033[4m");
} else if (strcmp(color, "[highlight]") == 0) {
Expand Down
5 changes: 2 additions & 3 deletions src/include/cprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ void __cfprintf(FILE *_Nonnull stream, const char *_Nonnull buf);
// We call snprintf() twice, but never mind, it's fast enough.
#define cprintf_get_bufsize(format, ...) (snprintf(NULL, 0, format, ##__VA_ARGS__) > 0 ? (size_t)snprintf(NULL, 0, format, ##__VA_ARGS__) + 514 : 0)
// The `base` color.
#define CPRINTF_BASE_FG_COLOR "\033[1;38;2;254;228;208m"
#define CPRINTF_BASE_BG_COLOR "\033[1;48;2;254;228;208m"
extern char *cprintf_base_color;
/*
* cprintf() is a macro,
* first, we get the size of the string to print,
Expand Down Expand Up @@ -78,4 +77,4 @@ void __cfprintf(FILE *_Nonnull stream, const char *_Nonnull buf);
} \
}
#define CPRINTF_MAJOR 1
#define CPRINTF_MINOR 3
#define CPRINTF_MINOR 4

0 comments on commit ea5f6d1

Please sign in to comment.