From 567e0df2434b270411d3356b8e362fc881113335 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Sat, 29 Aug 2020 14:05:22 +0200 Subject: first working --- src/color.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/color.c') diff --git a/src/color.c b/src/color.c index d0fbe1b..d7b3cdf 100644 --- a/src/color.c +++ b/src/color.c @@ -64,12 +64,13 @@ char* calc_col(uint8_t R, uint8_t G, uint8_t B) return colors[ nearest_num ].no; } //TODO consolidate -char* calc_col_ansi(uint8_t R, uint8_t G, uint8_t B) +char* calc_col_ansi(uint8_t R, uint8_t G, uint8_t B, uint8_t _mode) { + int mode = _mode == COLOR_BG ? 4 : 3; int num = 36 * (R/51) + 6 * (G/51) + (B/51); - char *c = malloc(9); - snprintf( c, 6, "38;5;" ); - snprintf( c + 5, 4, "%i", num + 16 ); + char *c = malloc(12); + snprintf( c, 8, "\e[%i8;5;", mode ); + snprintf( c + 7, 5, "%im", num + 16 ); return c; } -- cgit v1.2.3