Handle bold, underscore. Proper handling of reverse video (should not be in *_set())

This commit is contained in:
Michael Jumper 2011-08-05 14:30:10 -07:00
parent e0f38ded99
commit 8892c018e0
3 changed files with 51 additions and 9 deletions

View File

@ -72,6 +72,8 @@ struct ssh_guac_terminal {
int foreground; int foreground;
int background; int background;
int reverse; int reverse;
int bold;
int underscore;
int default_foreground; int default_foreground;
int default_background; int default_background;

View File

@ -85,7 +85,9 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client) {
term->foreground = term->default_foreground = 7; /* White */ term->foreground = term->default_foreground = 7; /* White */
term->background = term->default_background = 0; /* Black */ term->background = term->default_background = 0; /* Black */
term->reverse = 0; /* Normal video */ term->reverse = 0; /* Normal video */
term->bold = 0; /* Normal intensity */
term->underscore = 0; /* No underline */
term->cursor_row = 0; term->cursor_row = 0;
term->cursor_col = 0; term->cursor_col = 0;
@ -198,13 +200,6 @@ int ssh_guac_terminal_set(ssh_guac_terminal* term, int row, int col,
guac_layer* glyph = __ssh_guac_terminal_get_glyph(term, c); guac_layer* glyph = __ssh_guac_terminal_get_glyph(term, c);
const ssh_guac_terminal_color* background_color; const ssh_guac_terminal_color* background_color;
/* Handle reverse video */
if (term->reverse) {
int swap = background;
background = foreground;
foreground = swap;
}
/* Get background color */ /* Get background color */
background_color = &ssh_guac_terminal_palette[background]; background_color = &ssh_guac_terminal_palette[background];

View File

@ -44,6 +44,9 @@
int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) { int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) {
int foreground = term->foreground;
int background = term->background;
/* Wrap if necessary */ /* Wrap if necessary */
if (term->cursor_col >= term->term_width) { if (term->cursor_col >= term->term_width) {
term->cursor_col = 0; term->cursor_col = 0;
@ -88,10 +91,22 @@ int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) {
/* Displayable chars */ /* Displayable chars */
default: default:
/* Handle reverse video */
if (term->reverse) {
int swap = background;
background = foreground;
foreground = swap;
}
/* Handle bold */
if (term->bold && foreground <= 7)
foreground += 8;
ssh_guac_terminal_set(term, ssh_guac_terminal_set(term,
term->cursor_row, term->cursor_row,
term->cursor_col, term->cursor_col,
c, term->foreground, term->background); c, foreground, background);
/* Advance cursor */ /* Advance cursor */
term->cursor_col++; term->cursor_col++;
@ -187,8 +202,18 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
term->foreground = term->default_foreground; term->foreground = term->default_foreground;
term->background = term->default_background; term->background = term->default_background;
term->reverse = 0; term->reverse = 0;
term->underscore = 0;
term->bold = 0;
} }
/* Bold */
else if (value == 1)
term->bold = 1;
/* Underscore on */
else if (value == 4)
term->underscore = 1;
/* Foreground */ /* Foreground */
else if (value >= 30 && value <= 37) else if (value >= 30 && value <= 37)
term->foreground = value - 30; term->foreground = value - 30;
@ -197,6 +222,22 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
else if (value >= 40 && value <= 47) else if (value >= 40 && value <= 47)
term->background = value - 40; term->background = value - 40;
/* Underscore on, default foreground */
else if (value == 38) {
term->underscore = 1;
term->foreground = term->default_foreground;
}
/* Underscore off, default foreground */
else if (value == 39) {
term->underscore = 0;
term->foreground = term->default_foreground;
}
/* Reset background */
else if (value == 49)
term->background = term->default_background;
/* Reverse video */ /* Reverse video */
else if (value == 7) else if (value == 7)
term->reverse = 1; term->reverse = 1;
@ -205,6 +246,10 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
else if (value == 27) else if (value == 27)
term->reverse = 0; term->reverse = 0;
/* Reset intensity */
else if (value == 27)
term->bold = 0;
else else
guac_log_info("Unhandled graphics rendition: %i", value); guac_log_info("Unhandled graphics rendition: %i", value);