From 791ffe863314eba863f6f870c9451125bc5327cc Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Wed, 3 Jan 2024 15:33:09 +0600 Subject: [PATCH] printf color code macros --- src/kprint/kprint.c | 6 ++---- src/kprint/kprint_colors.h | 2 ++ src/kprint/kprintf.h | 43 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/kprint/kprint.c b/src/kprint/kprint.c index 11aed81..92e8246 100644 --- a/src/kprint/kprint.c +++ b/src/kprint/kprint.c @@ -89,8 +89,7 @@ void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects){ #include #define FOREGROUND_YELLOW FOREGROUND_GREEN | FOREGROUND_RED -DWORD kp_fgColor_toWin(kp_fgColor f){ - //kprintf("fg: %x\n", f); +DWORD kp_fgColor_toWin(kp_fgColor f){ switch(f){ case kp_fgBlack: return 0; case kp_fgRedD: return FOREGROUND_RED; @@ -112,8 +111,7 @@ DWORD kp_fgColor_toWin(kp_fgColor f){ } } -DWORD kp_bgColor_toWin(kp_bgColor f){ - //kprintf("bg: %x\n", f); +DWORD kp_bgColor_toWin(kp_bgColor f){ switch(f){ case kp_bgBlack: return 0; case kp_bgRedD: return BACKGROUND_RED; diff --git a/src/kprint/kprint_colors.h b/src/kprint/kprint_colors.h index 5131651..ae9ac0d 100644 --- a/src/kprint/kprint_colors.h +++ b/src/kprint/kprint_colors.h @@ -4,6 +4,8 @@ extern "C" { #endif +#include "../base/type_system/typedef_macros.h" + // 10000000 00000000 00000000 00000000 // ^ ^^^^ // | color num diff --git a/src/kprint/kprintf.h b/src/kprint/kprintf.h index d4df677..56eef30 100644 --- a/src/kprint/kprintf.h +++ b/src/kprint/kprintf.h @@ -9,6 +9,49 @@ extern "C" { // cross-platform printf analog void kprintf(const char* format, ...); +// printf format terminal color sequence +#define _PRINTF_COLOR(N) "\e["#N"m" + +// foreground dark color codes +#define FBLK _PRINTF_COLOR(30) +#define FREDD _PRINTF_COLOR(31) +#define FGRND _PRINTF_COLOR(32) +#define FYELD _PRINTF_COLOR(33) +#define FBLUD _PRINTF_COLOR(34) +#define FMAGD _PRINTF_COLOR(35) +#define FCYND _PRINTF_COLOR(36) +#define FGRY _PRINTF_COLOR(37) + +// foreground bright color codes +#define FGRYD _PRINTF_COLOR(90) +#define FRED _PRINTF_COLOR(91) +#define FGRN _PRINTF_COLOR(92) +#define FYEL _PRINTF_COLOR(93) +#define FBLU _PRINTF_COLOR(94) +#define FMAG _PRINTF_COLOR(95) +#define FCYN _PRINTF_COLOR(96) +#define FWHI _PRINTF_COLOR(97) + +// background dark color codes +#define BBLK _PRINTF_COLOR(40) +#define BREDD _PRINTF_COLOR(41) +#define BGRND _PRINTF_COLOR(42) +#define BYELD _PRINTF_COLOR(43) +#define BBLUD _PRINTF_COLOR(44) +#define BMAGD _PRINTF_COLOR(45) +#define BCYND _PRINTF_COLOR(46) +#define BGRY _PRINTF_COLOR(47) + +// background bright color codes +#define BGRYD _PRINTF_COLOR(100) +#define BRED _PRINTF_COLOR(101) +#define BGRN _PRINTF_COLOR(102) +#define BYEL _PRINTF_COLOR(103) +#define BBLU _PRINTF_COLOR(104) +#define BMAG _PRINTF_COLOR(105) +#define BCYN _PRINTF_COLOR(106) +#define BWHI _PRINTF_COLOR(107) + #if __cplusplus } #endif \ No newline at end of file