GUAC-1195: Use color scheme constants and names.

This commit is contained in:
Michael Jumper 2015-07-28 16:43:23 -07:00
parent b2c2779465
commit fa443249c9
4 changed files with 67 additions and 19 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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 = {

View File

@ -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.