From 00cc8736f10098dedf6b856b9ad8bd0094211263 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 18 Feb 2021 11:56:08 -0500 Subject: vbe support, truecolor window manager pixbufs --- src/user/highway/line.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/user/highway/line.c') diff --git a/src/user/highway/line.c b/src/user/highway/line.c index 5d1e543..3bc3bf2 100644 --- a/src/user/highway/line.c +++ b/src/user/highway/line.c @@ -12,18 +12,33 @@ #define LINE_SIZE 4096 static char line[LINE_SIZE]; -static inline uint8_t hex_to_int(char ch) { +static inline uint8_t hex_digit_to_int(char ch) { return ch - (ch <= '9' ? '0' : 'a' - 10); } +static inline uint8_t hex_byte_to_int(const char *ch) { + return (hex_digit_to_int(ch[0]) << 4) | hex_digit_to_int(ch[1]); +} + +static inline _pixel_t hex_to_pixel(const char *ch) { + return (_pixel_t){ + .r = hex_byte_to_int(ch), + .g = hex_byte_to_int(ch + 2), + .b = hex_byte_to_int(ch + 4) + }; +} + void ensure_color() { - const struct no_null_sn *color = get_var((struct no_null_sn){.data = "_color", .length = 6}); - //fgbg - if (color) - term_set_color( - (hex_to_int(color->data[0]) << 4) | hex_to_int(color->data[1]), - (hex_to_int(color->data[2]) << 4) | hex_to_int(color->data[3]) - ); + const struct no_null_sn *color; +get_color: + color = get_var((struct no_null_sn){.data = "_color", .length = 6}); + if (color && (color->length == 12)) + //rgb, fgbg + term_set_color(hex_to_pixel(color->data), hex_to_pixel(color->data + 6)); + else { + new_color(); + goto get_color; + } } static void line_replace(const char *from) { -- cgit v1.2.3