diff options
author | Benji Dial <benji6283@gmail.com> | 2021-02-18 11:56:08 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-02-18 11:56:08 -0500 |
commit | 00cc8736f10098dedf6b856b9ad8bd0094211263 (patch) | |
tree | 4cd252a614b26cb3dcf4a20c142feeffbb4c3c2a /src/user/highway/line.c | |
parent | 9d8ce7688f051fc5cd9e917faf3b1e49a3e620ab (diff) | |
download | portland-os-00cc8736f10098dedf6b856b9ad8bd0094211263.tar.gz |
vbe support, truecolor window manager pixbufs
Diffstat (limited to 'src/user/highway/line.c')
-rw-r--r-- | src/user/highway/line.c | 31 |
1 files changed, 23 insertions, 8 deletions
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) { |