GUACAMOLE-630: Persist semantics of default foreground/background with dedicated palette pseudo-indexes.

This commit is contained in:
Michael Jumper 2018-09-24 01:25:30 -07:00
parent 2f16eadb35
commit dcab540839
4 changed files with 50 additions and 6 deletions

View File

@ -247,5 +247,10 @@ void guac_terminal_parse_color_scheme(guac_client* client,
(const guac_terminal_color(*)[256]) palette, color_target)) (const guac_terminal_color(*)[256]) palette, color_target))
return; /* Parsing failed. */ return; /* Parsing failed. */
} }
/* Persist pseudo-index for foreground/background colors */
foreground->palette_index = GUAC_TERMINAL_COLOR_FOREGROUND;
background->palette_index = GUAC_TERMINAL_COLOR_BACKGROUND;
} }

View File

@ -78,7 +78,12 @@ int __guac_terminal_set_colors(guac_terminal_display* display,
} }
display->glyph_foreground = *foreground; display->glyph_foreground = *foreground;
guac_terminal_display_lookup_color(display,
foreground->palette_index, &display->glyph_foreground);
display->glyph_background = *background; display->glyph_background = *background;
guac_terminal_display_lookup_color(display,
background->palette_index, &display->glyph_background);
/* Modify color if half-bright (low intensity) */ /* Modify color if half-bright (low intensity) */
if (attributes->half_bright && !attributes->bold) { if (attributes->half_bright && !attributes->bold) {
@ -315,6 +320,18 @@ int guac_terminal_display_assign_color(guac_terminal_display* display,
int guac_terminal_display_lookup_color(guac_terminal_display* display, int guac_terminal_display_lookup_color(guac_terminal_display* display,
int index, guac_terminal_color* color) { int index, guac_terminal_color* color) {
/* Use default foreground if foreground pseudo-index is given */
if (index == GUAC_TERMINAL_COLOR_FOREGROUND) {
*color = display->default_foreground;
return 0;
}
/* Use default background if background pseudo-index is given */
if (index == GUAC_TERMINAL_COLOR_BACKGROUND) {
*color = display->default_background;
return 0;
}
/* Lookup fails if out-of-bounds */ /* Lookup fails if out-of-bounds */
if (index < 0 || index > 255) if (index < 0 || index > 255)
return 1; return 1;
@ -658,11 +675,15 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
int rect_width, rect_height; int rect_width, rect_height;
/* Color of the rectangle to draw */ /* Color of the rectangle to draw */
const guac_terminal_color* color; guac_terminal_color color;
if (current->character.attributes.reverse != current->character.attributes.cursor) if (current->character.attributes.reverse != current->character.attributes.cursor)
color = &current->character.attributes.foreground; color = current->character.attributes.foreground;
else else
color = &current->character.attributes.background; color = current->character.attributes.background;
/* Rely only on palette index if defined */
guac_terminal_display_lookup_color(display,
color.palette_index, &color);
/* Current row within a subrect */ /* Current row within a subrect */
guac_terminal_operation* rect_current_row; guac_terminal_operation* rect_current_row;
@ -685,7 +706,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
/* If not identical operation, stop */ /* If not identical operation, stop */
if (rect_current->type != GUAC_CHAR_SET if (rect_current->type != GUAC_CHAR_SET
|| guac_terminal_has_glyph(rect_current->character.value) || guac_terminal_has_glyph(rect_current->character.value)
|| guac_terminal_colorcmp(joining_color, color) != 0) || guac_terminal_colorcmp(joining_color, &color) != 0)
break; break;
/* Next column */ /* Next column */
@ -730,7 +751,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
/* Mark clear operations as NOP */ /* Mark clear operations as NOP */
if (rect_current->type == GUAC_CHAR_SET if (rect_current->type == GUAC_CHAR_SET
&& !guac_terminal_has_glyph(rect_current->character.value) && !guac_terminal_has_glyph(rect_current->character.value)
&& guac_terminal_colorcmp(joining_color, color) == 0) && guac_terminal_colorcmp(joining_color, &color) == 0)
rect_current->type = GUAC_CHAR_NOP; rect_current->type = GUAC_CHAR_NOP;
/* Next column */ /* Next column */
@ -750,7 +771,7 @@ void __guac_terminal_display_flush_clear(guac_terminal_display* display) {
row * display->char_height, row * display->char_height,
rect_width * display->char_width, rect_width * display->char_width,
rect_height * display->char_height, rect_height * display->char_height,
color->red, color->green, color->blue, color.red, color.green, color.blue,
0xFF); 0xFF);
} /* end if clear operation */ } /* end if clear operation */

View File

@ -289,6 +289,10 @@ const guac_terminal_color GUAC_TERMINAL_INITIAL_PALETTE[256] = {
int guac_terminal_colorcmp(const guac_terminal_color* a, int guac_terminal_colorcmp(const guac_terminal_color* a,
const guac_terminal_color* b) { const guac_terminal_color* b) {
/* Compare palette index alone if not unknown */
if (a->palette_index != -1 && b->palette_index != -1)
return a->palette_index - b->palette_index;
/* Consider red component highest order ... */ /* Consider red component highest order ... */
if (a->red != b->red) if (a->red != b->red)
return a->red - b->red; return a->red - b->red;

View File

@ -24,6 +24,20 @@
#include <stdint.h> #include <stdint.h>
/**
* The pseudo-index of the color set as the the default foreground color for
* the terminal. Regardless of what changes are made to the palette, this index
* will always return the current default foreground color.
*/
#define GUAC_TERMINAL_COLOR_FOREGROUND -2
/**
* The pseudo-index of the color set as the the default background color for
* the terminal. Regardless of what changes are made to the palette, this index
* will always return the current default background color.
*/
#define GUAC_TERMINAL_COLOR_BACKGROUND -3
/** /**
* The index of black within the terminal color palette. * The index of black within the terminal color palette.
*/ */