diff --git a/protocols/ssh/include/ssh_terminal.h b/protocols/ssh/include/ssh_terminal.h index 025d38c0..6a0adea3 100644 --- a/protocols/ssh/include/ssh_terminal.h +++ b/protocols/ssh/include/ssh_terminal.h @@ -71,6 +71,7 @@ struct ssh_guac_terminal { int foreground; int background; + int reverse; int default_foreground; int default_background; diff --git a/protocols/ssh/src/ssh_terminal.c b/protocols/ssh/src/ssh_terminal.c index f32027c6..9ca19e4d 100644 --- a/protocols/ssh/src/ssh_terminal.c +++ b/protocols/ssh/src/ssh_terminal.c @@ -85,6 +85,7 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client) { term->foreground = term->default_foreground = 7; /* White */ term->background = term->default_background = 0; /* Black */ + term->reverse = 0; /* Normal video */ term->cursor_row = 0; term->cursor_col = 0; @@ -195,10 +196,17 @@ int ssh_guac_terminal_set(ssh_guac_terminal* term, int row, int col, GUACIO* io = term->client->io; guac_layer* glyph = __ssh_guac_terminal_get_glyph(term, c); + const ssh_guac_terminal_color* background_color; + + /* Handle reverse video */ + if (term->reverse) { + int swap = background; + background = foreground; + foreground = swap; + } /* Get background color */ - const ssh_guac_terminal_color* background_color = - &ssh_guac_terminal_palette[background]; + background_color = &ssh_guac_terminal_palette[background]; guac_send_copy(io, glyph, 0, 0, term->char_width, term->char_height, diff --git a/protocols/ssh/src/ssh_terminal_handlers.c b/protocols/ssh/src/ssh_terminal_handlers.c index 0ecee494..fb098541 100644 --- a/protocols/ssh/src/ssh_terminal_handlers.c +++ b/protocols/ssh/src/ssh_terminal_handlers.c @@ -186,6 +186,7 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) { if (value == 0) { term->foreground = term->default_foreground; term->background = term->default_background; + term->reverse = 0; } /* Foreground */ @@ -196,6 +197,14 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) { else if (value >= 40 && value <= 47) term->background = value - 40; + /* Reverse video */ + else if (value == 7) + term->reverse = 1; + + /* Reset reverse video */ + else if (value == 27) + term->reverse = 0; + else guac_log_info("Unhandled graphics rendition: %i", value);