diff --git a/protocols/ssh/include/ssh_terminal.h b/protocols/ssh/include/ssh_terminal.h index 0c4f83cc..025d38c0 100644 --- a/protocols/ssh/include/ssh_terminal.h +++ b/protocols/ssh/include/ssh_terminal.h @@ -91,7 +91,8 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client); void ssh_guac_terminal_free(ssh_guac_terminal* term); int ssh_guac_terminal_write(ssh_guac_terminal* term, const char* c, int size); -int ssh_guac_terminal_send_glyph(ssh_guac_terminal* term, int row, int col, char c); +int ssh_guac_terminal_set(ssh_guac_terminal* term, int row, int col, + char c, int foreground, int background); int ssh_guac_terminal_copy(ssh_guac_terminal* term, int src_row, int src_col, int rows, int cols, diff --git a/protocols/ssh/src/ssh_terminal.c b/protocols/ssh/src/ssh_terminal.c index 0cb506fd..f32027c6 100644 --- a/protocols/ssh/src/ssh_terminal.c +++ b/protocols/ssh/src/ssh_terminal.c @@ -123,7 +123,7 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client) { /* Clear with background color */ ssh_guac_terminal_clear(term, - 0, 0, term->term_width, term->term_height, + 0, 0, term->term_height, term->term_width, term->background); return term; @@ -190,16 +190,56 @@ guac_layer* __ssh_guac_terminal_get_glyph(ssh_guac_terminal* term, char c) { } -int ssh_guac_terminal_send_glyph(ssh_guac_terminal* term, int row, int col, char c) { +int ssh_guac_terminal_set(ssh_guac_terminal* term, int row, int col, + char c, int foreground, int background) { GUACIO* io = term->client->io; guac_layer* glyph = __ssh_guac_terminal_get_glyph(term, c); - return guac_send_copy(io, - glyph, 0, 0, term->char_width, term->char_height, - GUAC_COMP_SRC, GUAC_DEFAULT_LAYER, - term->char_width * col, - term->char_height * row); + /* Get background color */ + const ssh_guac_terminal_color* background_color = + &ssh_guac_terminal_palette[background]; + + guac_send_copy(io, + glyph, 0, 0, term->char_width, term->char_height, + GUAC_COMP_SRC, GUAC_DEFAULT_LAYER, + term->char_width * col, + term->char_height * row); + + /* If foreground different from default, colorize */ + if (foreground != term->default_foreground) { + + /* Get color */ + const ssh_guac_terminal_color* color = + &ssh_guac_terminal_palette[foreground]; + + /* Colorize letter */ + guac_send_rect(io, + GUAC_COMP_ATOP, GUAC_DEFAULT_LAYER, + + term->char_width * col, term->char_height * row, + term->char_width, term->char_height, + + color->red, + color->green, + color->blue, + 255); + + } + + /* Set background */ + guac_send_rect(io, + GUAC_COMP_ROVER, GUAC_DEFAULT_LAYER, + + term->char_width * col, term->char_height * row, + term->char_width, term->char_height, + + background_color->red, + background_color->green, + background_color->blue, + 255); + + return 0; } diff --git a/protocols/ssh/src/ssh_terminal_handlers.c b/protocols/ssh/src/ssh_terminal_handlers.c index 7dcc0e43..0ecee494 100644 --- a/protocols/ssh/src/ssh_terminal_handlers.c +++ b/protocols/ssh/src/ssh_terminal_handlers.c @@ -88,10 +88,10 @@ int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) { /* Displayable chars */ default: - ssh_guac_terminal_send_glyph(term, + ssh_guac_terminal_set(term, term->cursor_row, term->cursor_col, - c); + c, term->foreground, term->background); /* Advance cursor */ term->cursor_col++; @@ -158,6 +158,8 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) { /* Any non-digit stops the parameter, and possibly the sequence */ else { + int i; + /* At most 16 parameters */ if (argc < 16) { @@ -173,6 +175,34 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) { /* Handle CSI functions */ switch (c) { + /* m: Set graphics rendition */ + case 'm': + + for (i=0; iforeground = term->default_foreground; + term->background = term->default_background; + } + + /* Foreground */ + else if (value >= 30 && value <= 37) + term->foreground = value - 30; + + /* Background */ + else if (value >= 40 && value <= 47) + term->background = value - 40; + + else + guac_log_info("Unhandled graphics rendition: %i", value); + + } + + break; + /* H: Move cursor */ case 'H': term->cursor_row = argv[0] - 1;