Working colors in CSI

This commit is contained in:
Michael Jumper 2011-08-05 12:41:21 -07:00
parent 5f59ccf5c1
commit 18cdf2808d
3 changed files with 81 additions and 10 deletions

View File

@ -91,7 +91,8 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client);
void ssh_guac_terminal_free(ssh_guac_terminal* term); 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_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 ssh_guac_terminal_copy(ssh_guac_terminal* term,
int src_row, int src_col, int rows, int cols, int src_row, int src_col, int rows, int cols,

View File

@ -123,7 +123,7 @@ ssh_guac_terminal* ssh_guac_terminal_create(guac_client* client) {
/* Clear with background color */ /* Clear with background color */
ssh_guac_terminal_clear(term, ssh_guac_terminal_clear(term,
0, 0, term->term_width, term->term_height, 0, 0, term->term_height, term->term_width,
term->background); term->background);
return term; return term;
@ -190,17 +190,57 @@ 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; GUACIO* io = term->client->io;
guac_layer* glyph = __ssh_guac_terminal_get_glyph(term, c); guac_layer* glyph = __ssh_guac_terminal_get_glyph(term, c);
return guac_send_copy(io, /* 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, glyph, 0, 0, term->char_width, term->char_height,
GUAC_COMP_SRC, GUAC_DEFAULT_LAYER, GUAC_COMP_SRC, GUAC_DEFAULT_LAYER,
term->char_width * col, term->char_width * col,
term->char_height * row); 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;
} }
int ssh_guac_terminal_write(ssh_guac_terminal* term, const char* c, int size) { int ssh_guac_terminal_write(ssh_guac_terminal* term, const char* c, int size) {

View File

@ -88,10 +88,10 @@ int ssh_guac_terminal_echo(ssh_guac_terminal* term, char c) {
/* Displayable chars */ /* Displayable chars */
default: default:
ssh_guac_terminal_send_glyph(term, ssh_guac_terminal_set(term,
term->cursor_row, term->cursor_row,
term->cursor_col, term->cursor_col,
c); c, term->foreground, term->background);
/* Advance cursor */ /* Advance cursor */
term->cursor_col++; 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 */ /* Any non-digit stops the parameter, and possibly the sequence */
else { else {
int i;
/* At most 16 parameters */ /* At most 16 parameters */
if (argc < 16) { if (argc < 16) {
@ -173,6 +175,34 @@ int ssh_guac_terminal_csi(ssh_guac_terminal* term, char c) {
/* Handle CSI functions */ /* Handle CSI functions */
switch (c) { switch (c) {
/* m: Set graphics rendition */
case 'm':
for (i=0; i<argc; i++) {
int value = argv[i];
/* Reset attributes */
if (value == 0) {
term->foreground = 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 */ /* H: Move cursor */
case 'H': case 'H':
term->cursor_row = argv[0] - 1; term->cursor_row = argv[0] - 1;