From fa443249c9341f3ffe3bdef357c5fb2c35478cc3 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 28 Jul 2015 16:43:23 -0700 Subject: [PATCH] GUAC-1195: Use color scheme constants and names. --- src/protocols/ssh/client.c | 3 +-- src/protocols/telnet/client.c | 3 +-- src/terminal/terminal.c | 41 ++++++++++++++++++++++++++++++++--- src/terminal/terminal.h | 39 +++++++++++++++++++++++---------- 4 files changed, 67 insertions(+), 19 deletions(-) diff --git a/src/protocols/ssh/client.c b/src/protocols/ssh/client.c index 087ce762..9eb902fd 100644 --- a/src/protocols/ssh/client.c +++ b/src/protocols/ssh/client.c @@ -24,7 +24,6 @@ #include "client.h" #include "clipboard.h" -#include "display.h" #include "guac_handlers.h" #include "ssh_client.h" #include "terminal.h" @@ -175,7 +174,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) { client_data->font_name, client_data->font_size, client->info.optimal_resolution, client->info.optimal_width, client->info.optimal_height, - GUAC_TERMINAL_COLOR_GRAY, GUAC_TERMINAL_COLOR_BLACK); + GUAC_TERMINAL_SCHEME_GRAY_BLACK); /* Fail if terminal init failed */ if (client_data->term == NULL) { diff --git a/src/protocols/telnet/client.c b/src/protocols/telnet/client.c index c0996db2..d24a0bf6 100644 --- a/src/protocols/telnet/client.c +++ b/src/protocols/telnet/client.c @@ -23,7 +23,6 @@ #include "config.h" #include "client.h" #include "clipboard.h" -#include "display.h" #include "guac_handlers.h" #include "telnet_client.h" #include "terminal.h" @@ -202,7 +201,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) { client_data->font_name, client_data->font_size, client->info.optimal_resolution, client->info.optimal_width, client->info.optimal_height, - GUAC_TERMINAL_COLOR_GRAY, GUAC_TERMINAL_COLOR_BLACK); + GUAC_TERMINAL_SCHEME_GRAY_BLACK); /* Fail if terminal init failed */ if (client_data->term == NULL) { diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index c7c64ac7..cf7d84fe 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -226,10 +226,45 @@ static void guac_terminal_paint_background(guac_terminal* terminal, guac_terminal* guac_terminal_create(guac_client* client, const char* font_name, int font_size, int dpi, - int width, int height, - int default_foreground, - int default_background) { + int width, int height, const char* color_scheme) { + int default_foreground; + int default_background; + + /* Default to "gray-black" color scheme if no scheme provided */ + if (color_scheme == NULL || color_scheme[0] == '\0') { + default_foreground = GUAC_TERMINAL_COLOR_GRAY; + default_background = GUAC_TERMINAL_COLOR_BLACK; + } + + /* Otherwise, parse color scheme */ + else if (strcmp(color_scheme, GUAC_TERMINAL_SCHEME_GRAY_BLACK) == 0) { + default_foreground = GUAC_TERMINAL_COLOR_GRAY; + default_background = GUAC_TERMINAL_COLOR_BLACK; + } + else if (strcmp(color_scheme, GUAC_TERMINAL_SCHEME_BLACK_WHITE) == 0) { + default_foreground = GUAC_TERMINAL_COLOR_BLACK; + default_background = GUAC_TERMINAL_COLOR_WHITE; + } + else if (strcmp(color_scheme, GUAC_TERMINAL_SCHEME_GREEN_BLACK) == 0) { + default_foreground = GUAC_TERMINAL_COLOR_DARK_GREEN; + default_background = GUAC_TERMINAL_COLOR_BLACK; + } + else if (strcmp(color_scheme, GUAC_TERMINAL_SCHEME_WHITE_BLACK) == 0) { + default_foreground = GUAC_TERMINAL_COLOR_WHITE; + default_background = GUAC_TERMINAL_COLOR_BLACK; + } + + /* If invalid, default to "gray-black" */ + else { + guac_client_log(client, GUAC_LOG_WARNING, + "Invalid color scheme: \"%s\". Defaulting to \"gray-black\".", + color_scheme); + default_foreground = GUAC_TERMINAL_COLOR_GRAY; + default_background = GUAC_TERMINAL_COLOR_BLACK; + } + + /* Build default character using default colors */ guac_terminal_char default_char = { .value = 0, .attributes = { diff --git a/src/terminal/terminal.h b/src/terminal/terminal.h index 43a1be92..488692d6 100644 --- a/src/terminal/terminal.h +++ b/src/terminal/terminal.h @@ -65,6 +65,26 @@ */ #define GUAC_TERMINAL_CLIPBOARD_MAX_LENGTH 262144 +/** + * The name of the color scheme having black foreground and white background. + */ +#define GUAC_TERMINAL_SCHEME_BLACK_WHITE "black-white" + +/** + * The name of the color scheme having gray foreground and black background. + */ +#define GUAC_TERMINAL_SCHEME_GRAY_BLACK "gray-black" + +/** + * The name of the color scheme having green foreground and black background. + */ +#define GUAC_TERMINAL_SCHEME_GREEN_BLACK "green-black" + +/** + * The name of the color scheme having white foreground and black background. + */ +#define GUAC_TERMINAL_SCHEME_WHITE_BLACK "white-black" + typedef struct guac_terminal guac_terminal; /** @@ -368,16 +388,12 @@ struct guac_terminal { * @param height * The height of the terminal, in pixels. * - * @param default_foreground - * The default foreground color for all glyphs whose foreground has not - * been explicitly set through terminal codes. This color is the color - * index within the terminal palette - a value between 0 and 15 inclusive. - * - * @param default_background - * The default background color for all glyphs whose background has not - * been explicitly set through terminal codes, and the background of the - * terminal as a whole. This color is the color index within the terminal - * palette - a value between 0 and 15 inclusive. + * @param color_scheme + * The name of the color scheme to use. This string must be one of the + * names defined by the GUAC_TERMINAL_SCHEME_* constants. If blank or NULL, + * the default scheme of GUAC_TERMINAL_SCHEME_GRAY_BLACK will be used. If + * invalid, a warning will be logged, and the terminal will fall back on + * GUAC_TERMINAL_SCHEME_GRAY_BLACK. * * @return * A new guac_terminal having the given font, dimensions, and attributes @@ -385,8 +401,7 @@ struct guac_terminal { */ guac_terminal* guac_terminal_create(guac_client* client, const char* font_name, int font_size, int dpi, - int width, int height, - int default_foreground, int default_background); + int width, int height, const char* color_scheme); /** * Frees all resources associated with the given terminal.