aboutsummaryrefslogtreecommitdiff
path: root/src/color.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/color.c')
-rw-r--r--src/color.c9
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;
}