diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2020-08-29 14:05:22 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2020-08-29 14:05:22 +0200 |
commit | 567e0df2434b270411d3356b8e362fc881113335 (patch) | |
tree | 843da4160e3001bdd9f792d52a21f31c485f5215 /src/color.c | |
parent | 57b73d286ad68a71547cdfbb31c772fb46c96c67 (diff) | |
download | AsciiMap-567e0df2434b270411d3356b8e362fc881113335.tar.gz |
first working
Diffstat (limited to 'src/color.c')
-rw-r--r-- | src/color.c | 9 |
1 files changed, 5 insertions, 4 deletions
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; } |