diff options
Diffstat (limited to 'termbox')
-rw-r--r-- | termbox/README | 4 | ||||
-rw-r--r-- | termbox/termbox.c | 44 | ||||
-rw-r--r-- | termbox/termbox.h | 17 |
3 files changed, 17 insertions, 48 deletions
diff --git a/termbox/README b/termbox/README index bb97525c..d97cae4e 100644 --- a/termbox/README +++ b/termbox/README @@ -1,2 +1,2 @@ -Fork of https://github.com/nsf/termbox as of 2015-05-09 -git hash c5b8b598f17fe60477ba0bb57d24bf8dae11ef92 +Fork of https://github.com/nsf/termbox as of 2015-06-05 +git hash 252bef01264a2aeef22ebe5bae0b5893a58947f3 diff --git a/termbox/termbox.c b/termbox/termbox.c index 0e4d5a9f..6bd14213 100644 --- a/termbox/termbox.c +++ b/termbox/termbox.c @@ -47,12 +47,10 @@ static int lasty = LAST_COORD_INIT; static int cursor_x = -1; static int cursor_y = -1; -static uint16_t background = TB_DEFAULT; -static uint16_t foreground = TB_DEFAULT; +static uint16_t background = TB_BLACK; +static uint16_t foreground = TB_WHITE; static void write_cursor(int x, int y); -static void write_sgr_fg(uint16_t fg); -static void write_sgr_bg(uint16_t bg); static void write_sgr(uint16_t fg, uint16_t bg); static void cellbuf_init(struct cellbuf *buf, int width, int height); @@ -310,26 +308,13 @@ static void write_cursor(int x, int y) { WRITE_LITERAL("H"); } -static void write_sgr_fg(uint16_t fg) { - char buf[32]; - WRITE_LITERAL("\033[3"); - WRITE_INT(fg-1); - WRITE_LITERAL("m"); -} - -static void write_sgr_bg(uint16_t bg) { - char buf[32]; - WRITE_LITERAL("\033[4"); - WRITE_INT(bg-1); - WRITE_LITERAL("m"); -} - static void write_sgr(uint16_t fg, uint16_t bg) { char buf[32]; - WRITE_LITERAL("\033[3"); - WRITE_INT(fg-1); - WRITE_LITERAL(";4"); - WRITE_INT(bg-1); + WRITE_LITERAL("\033[38;5;"); + WRITE_INT(fg); + WRITE_LITERAL("m"); + WRITE_LITERAL("\033[48;5;"); + WRITE_INT(bg); WRITE_LITERAL("m"); } @@ -412,8 +397,8 @@ static void send_attr(uint16_t fg, uint16_t bg) if (fg != lastfg || bg != lastbg) { bytebuffer_puts(&output_buffer, funcs[T_SGR0]); - uint16_t fgcol = fg & 0x0F; - uint16_t bgcol = bg & 0x0F; + uint16_t fgcol = fg & 0xFF; + uint16_t bgcol = bg & 0xFF; if (fg & TB_BOLD) bytebuffer_puts(&output_buffer, funcs[T_BOLD]); @@ -423,16 +408,7 @@ static void send_attr(uint16_t fg, uint16_t bg) bytebuffer_puts(&output_buffer, funcs[T_UNDERLINE]); if ((fg & TB_REVERSE) || (bg & TB_REVERSE)) bytebuffer_puts(&output_buffer, funcs[T_REVERSE]); - - if (fgcol != TB_DEFAULT) { - if (bgcol != TB_DEFAULT) - write_sgr(fgcol, bgcol); - else - write_sgr_fg(fgcol); - } else if (bgcol != TB_DEFAULT) { - write_sgr_bg(bgcol); - } - + write_sgr(fgcol, bgcol); lastfg = fg; lastbg = bg; } diff --git a/termbox/termbox.h b/termbox/termbox.h index ac31230a..9b7fd772 100644 --- a/termbox/termbox.h +++ b/termbox/termbox.h @@ -11,20 +11,13 @@ extern "C" { /* The screen is a 2D array of cells. */ struct tb_cell { uint32_t ch; /* unicode character */ - uint16_t fg; /* foreground color and attributes */ - uint16_t bg; /* background color and attributes */ + uint16_t fg; /* foreground color (0-255) and attributes */ + uint16_t bg; /* background color (0-255) and attributes */ }; -/* Possible colors in tb_cell.fg and tb_cell.bg. */ -#define TB_DEFAULT 0x00 -#define TB_BLACK 0x01 -#define TB_RED 0x02 -#define TB_GREEN 0x03 -#define TB_YELLOW 0x04 -#define TB_BLUE 0x05 -#define TB_MAGENTA 0x06 -#define TB_CYAN 0x07 -#define TB_WHITE 0x08 +/* Names for some colors in tb_cell.fg and tb_cell.bg. */ +#define TB_BLACK 232 +#define TB_WHITE 255 /* Colors in tb_cell can be combined using bitwise-OR with multiple * of the following attributes. */ |