Skip to content

Commit

Permalink
1530 - switch to termbox's 256-color mode
Browse files Browse the repository at this point in the history
  • Loading branch information
akkartik committed Jun 5, 2015
1 parent 70023f5 commit 10a3b8c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 55 deletions.
10 changes: 5 additions & 5 deletions 070display.cc
Expand Up @@ -54,7 +54,7 @@ Recipe_number["clear-line-on-display"] = CLEAR_LINE_ON_DISPLAY;
case CLEAR_LINE_ON_DISPLAY: {
long long int width = tb_width();
for (long long int x = Display_column; x < width; ++x) {
tb_change_cell(x, Display_row, ' ', TB_WHITE, TB_DEFAULT);
tb_change_cell(x, Display_row, ' ', TB_WHITE, TB_BLACK);
}
tb_set_cursor(Display_column, Display_row);
tb_present();
Expand Down Expand Up @@ -86,22 +86,22 @@ case PRINT_CHARACTER_TO_DISPLAY: {
}
if (c == '\b') {
if (Display_column > 0) {
tb_change_cell(Display_column-1, Display_row, ' ', TB_WHITE, TB_DEFAULT);
tb_change_cell(Display_column-1, Display_row, ' ', TB_WHITE, TB_BLACK);
--Display_column;
tb_set_cursor(Display_column, Display_row);
tb_present();
}
break;
}
int color = TB_DEFAULT;
int color = TB_BLACK;
if (SIZE(ingredients) > 1) {
assert(scalar(ingredients.at(1)));
color = ingredients.at(1).at(0)+1/*skip default*/;
color = ingredients.at(1).at(0);
//? tb_shutdown(); //? 1
//? cerr << "AAA " << color << '\n'; //? 1
//? exit(1); //? 1
}
tb_change_cell(Display_column, Display_row, c, color, TB_DEFAULT);
tb_change_cell(Display_column, Display_row, c, color, TB_BLACK);
if (Display_column < width-1) {
++Display_column;
tb_set_cursor(Display_column, Display_row);
Expand Down
4 changes: 2 additions & 2 deletions 077trace_browser.cc
Expand Up @@ -192,9 +192,9 @@ void render_line(int screen_row, const string& s) {
for (col = 0; col < tb_width() && col < SIZE(s); ++col) {
char c = s.at(col);
if (c == '\n') c = ';'; // replace newlines with semi-colons
tb_change_cell(col, screen_row, c, TB_WHITE, TB_DEFAULT);
tb_change_cell(col, screen_row, c, TB_WHITE, TB_BLACK);
}
for (; col < tb_width(); ++col) {
tb_change_cell(col, screen_row, ' ', TB_WHITE, TB_DEFAULT);
tb_change_cell(col, screen_row, ' ', TB_WHITE, TB_BLACK);
}
}
4 changes: 2 additions & 2 deletions 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
44 changes: 10 additions & 34 deletions termbox/termbox.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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]);
Expand All @@ -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;
}
Expand Down
17 changes: 5 additions & 12 deletions termbox/termbox.h
Expand Up @@ -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. */
Expand Down

0 comments on commit 10a3b8c

Please sign in to comment.