GUACAMOLE-278: Move terminal palette/color definitions into dedicated files.

This commit is contained in:
Michael Jumper 2017-04-23 11:38:49 -07:00
parent 48fc4afc5b
commit eaa71f5717
10 changed files with 236 additions and 180 deletions

View File

@ -27,6 +27,7 @@ noinst_HEADERS = \
terminal/char_mappings.h \ terminal/char_mappings.h \
terminal/common.h \ terminal/common.h \
terminal/display.h \ terminal/display.h \
terminal/palette.h \
terminal/scrollbar.h \ terminal/scrollbar.h \
terminal/terminal.h \ terminal/terminal.h \
terminal/terminal_handlers.h \ terminal/terminal_handlers.h \
@ -38,6 +39,7 @@ libguac_terminal_la_SOURCES = \
char_mappings.c \ char_mappings.c \
common.c \ common.c \
display.c \ display.c \
palette.c \
scrollbar.c \ scrollbar.c \
terminal.c \ terminal.c \
terminal_handlers.c \ terminal_handlers.c \

View File

@ -105,23 +105,3 @@ int guac_terminal_write_all(int fd, const char* buffer, int size) {
} }
int guac_terminal_colorcmp(const guac_terminal_color* a,
const guac_terminal_color* b) {
/* Consider red component highest order ... */
if (a->red != b->red)
return a->red - b->red;
/* ... followed by green ... */
if (a->green != b->green)
return a->green - b->green;
/* ... followed by blue */
if (a->blue != b->blue)
return a->blue - b->blue;
/* If all components match, colors are equal */
return 0;
}

View File

@ -22,6 +22,7 @@
#include "common/surface.h" #include "common/surface.h"
#include "terminal/common.h" #include "terminal/common.h"
#include "terminal/display.h" #include "terminal/display.h"
#include "terminal/palette.h"
#include "terminal/types.h" #include "terminal/types.h"
#include <math.h> #include <math.h>
@ -36,30 +37,6 @@
#include <guacamole/socket.h> #include <guacamole/socket.h>
#include <pango/pangocairo.h> #include <pango/pangocairo.h>
const guac_terminal_color guac_terminal_palette[16] = {
/* Normal colors */
{0, 0x00, 0x00, 0x00}, /* Black */
{1, 0x99, 0x3E, 0x3E}, /* Red */
{2, 0x3E, 0x99, 0x3E}, /* Green */
{3, 0x99, 0x99, 0x3E}, /* Brown */
{4, 0x3E, 0x3E, 0x99}, /* Blue */
{5, 0x99, 0x3E, 0x99}, /* Magenta */
{6, 0x3E, 0x99, 0x99}, /* Cyan */
{7, 0x99, 0x99, 0x99}, /* White */
/* Intense colors */
{8, 0x3E, 0x3E, 0x3E}, /* Black */
{9, 0xFF, 0x67, 0x67}, /* Red */
{10, 0x67, 0xFF, 0x67}, /* Green */
{11, 0xFF, 0xFF, 0x67}, /* Brown */
{12, 0x67, 0x67, 0xFF}, /* Blue */
{13, 0xFF, 0x67, 0xFF}, /* Magenta */
{14, 0x67, 0xFF, 0xFF}, /* Cyan */
{15, 0xFF, 0xFF, 0xFF}, /* White */
};
/** /**
* Clears the currently-selected region, removing the highlight. * Clears the currently-selected region, removing the highlight.
*/ */

66
src/terminal/palette.c Normal file
View File

@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "config.h"
#include "terminal/palette.h"
const guac_terminal_color guac_terminal_palette[16] = {
/* Normal colors */
{0, 0x00, 0x00, 0x00}, /* Black */
{1, 0x99, 0x3E, 0x3E}, /* Red */
{2, 0x3E, 0x99, 0x3E}, /* Green */
{3, 0x99, 0x99, 0x3E}, /* Brown */
{4, 0x3E, 0x3E, 0x99}, /* Blue */
{5, 0x99, 0x3E, 0x99}, /* Magenta */
{6, 0x3E, 0x99, 0x99}, /* Cyan */
{7, 0x99, 0x99, 0x99}, /* White */
/* Intense colors */
{8, 0x3E, 0x3E, 0x3E}, /* Black */
{9, 0xFF, 0x67, 0x67}, /* Red */
{10, 0x67, 0xFF, 0x67}, /* Green */
{11, 0xFF, 0xFF, 0x67}, /* Brown */
{12, 0x67, 0x67, 0xFF}, /* Blue */
{13, 0xFF, 0x67, 0xFF}, /* Magenta */
{14, 0x67, 0xFF, 0xFF}, /* Cyan */
{15, 0xFF, 0xFF, 0xFF}, /* White */
};
int guac_terminal_colorcmp(const guac_terminal_color* a,
const guac_terminal_color* b) {
/* Consider red component highest order ... */
if (a->red != b->red)
return a->red - b->red;
/* ... followed by green ... */
if (a->green != b->green)
return a->green - b->green;
/* ... followed by blue */
if (a->blue != b->blue)
return a->blue - b->blue;
/* If all components match, colors are equal */
return 0;
}

View File

@ -24,6 +24,7 @@
#include "terminal/buffer.h" #include "terminal/buffer.h"
#include "terminal/common.h" #include "terminal/common.h"
#include "terminal/display.h" #include "terminal/display.h"
#include "terminal/palette.h"
#include "terminal/terminal.h" #include "terminal/terminal.h"
#include "terminal/terminal_handlers.h" #include "terminal/terminal_handlers.h"
#include "terminal/types.h" #include "terminal/types.h"

View File

@ -50,26 +50,5 @@ bool guac_terminal_has_glyph(int codepoint);
*/ */
int guac_terminal_write_all(int fd, const char* buffer, int size); int guac_terminal_write_all(int fd, const char* buffer, int size);
/**
* Compares two colors, returning a negative value if the first color is less
* than the second, a positive value if the first color is greater than the
* second, and zero if the colors are identical. Only the color components are
* compared (not the palette index). The red component is considered the
* highest order component, followed by green, followed by blue.
*
* @param a
* The first color to compare.
*
* @param b
* The second color to compare.
*
* @return
* A negative value if the first color is less than the second, a positive
* value if the first color is greater than the second, and zero if the
* colors are identical.
*/
int guac_terminal_colorcmp(const guac_terminal_color* a,
const guac_terminal_color* b);
#endif #endif

View File

@ -24,6 +24,7 @@
#include "config.h" #include "config.h"
#include "common/surface.h" #include "common/surface.h"
#include "palette.h"
#include "types.h" #include "types.h"
#include <guacamole/client.h> #include <guacamole/client.h>
@ -37,93 +38,6 @@
*/ */
#define GUAC_TERMINAL_MAX_CHAR_WIDTH 2 #define GUAC_TERMINAL_MAX_CHAR_WIDTH 2
/**
* The index of black within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_BLACK 0
/**
* The index of low-intensity red within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_DARK_RED 1
/**
* The index of low-intensity green within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_DARK_GREEN 2
/**
* The index of brown within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_BROWN 3
/**
* The index of low-intensity blue within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_DARK_BLUE 4
/**
* The index of low-intensity magenta (purple) within the terminal color
* palette.
*/
#define GUAC_TERMINAL_COLOR_PURPLE 5
/**
* The index of low-intensity cyan (teal) within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_TEAL 6
/**
* The index of low-intensity white (gray) within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_GRAY 7
/**
* The index of bright black (dark gray) within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_DARK_GRAY 8
/**
* The index of bright red within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_RED 9
/**
* The index of bright green within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_GREEN 10
/**
* The index of bright brown (yellow) within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_YELLOW 11
/**
* The index of bright blue within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_BLUE 12
/**
* The index of bright magenta within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_MAGENTA 13
/**
* The index of bright cyan within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_CYAN 14
/**
* The index of bright white within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_WHITE 15
/**
* The available color palette. All integer colors within structures
* here are indices into this palette.
*/
extern const guac_terminal_color guac_terminal_palette[16];
/** /**
* All available terminal operations which affect character cells. * All available terminal operations which affect character cells.
*/ */

View File

@ -0,0 +1,163 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef GUAC_TERMINAL_PALETTE_H
#define GUAC_TERMINAL_PALETTE_H
#include "config.h"
#include <stdint.h>
/**
* The index of black within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_BLACK 0
/**
* The index of low-intensity red within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_DARK_RED 1
/**
* The index of low-intensity green within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_DARK_GREEN 2
/**
* The index of brown within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_BROWN 3
/**
* The index of low-intensity blue within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_DARK_BLUE 4
/**
* The index of low-intensity magenta (purple) within the terminal color
* palette.
*/
#define GUAC_TERMINAL_COLOR_PURPLE 5
/**
* The index of low-intensity cyan (teal) within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_TEAL 6
/**
* The index of low-intensity white (gray) within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_GRAY 7
/**
* The index of bright black (dark gray) within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_DARK_GRAY 8
/**
* The index of bright red within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_RED 9
/**
* The index of bright green within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_GREEN 10
/**
* The index of bright brown (yellow) within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_YELLOW 11
/**
* The index of bright blue within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_BLUE 12
/**
* The index of bright magenta within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_MAGENTA 13
/**
* The index of bright cyan within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_CYAN 14
/**
* The index of bright white within the terminal color palette.
*/
#define GUAC_TERMINAL_COLOR_WHITE 15
/**
* An RGB color, where each component ranges from 0 to 255.
*/
typedef struct guac_terminal_color {
/**
* The index of this color within the terminal palette, or -1 if the color
* does not exist within the terminal palette.
*/
int palette_index;
/**
* The red component of this color.
*/
uint8_t red;
/**
* The green component of this color.
*/
uint8_t green;
/**
* The blue component of this color.
*/
uint8_t blue;
} guac_terminal_color;
/**
* Compares two colors, returning a negative value if the first color is less
* than the second, a positive value if the first color is greater than the
* second, and zero if the colors are identical. Only the color components are
* compared (not the palette index). The red component is considered the
* highest order component, followed by green, followed by blue.
*
* @param a
* The first color to compare.
*
* @param b
* The second color to compare.
*
* @return
* A negative value if the first color is less than the second, a positive
* value if the first color is greater than the second, and zero if the
* colors are identical.
*/
int guac_terminal_colorcmp(const guac_terminal_color* a,
const guac_terminal_color* b);
/**
* The terminal color palette.
*/
extern const guac_terminal_color guac_terminal_palette[16];
#endif

View File

@ -22,6 +22,7 @@
#define _GUAC_TERMINAL_TYPES_H #define _GUAC_TERMINAL_TYPES_H
#include "config.h" #include "config.h"
#include "palette.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@ -35,34 +36,6 @@
*/ */
#define GUAC_CHAR_CONTINUATION -1 #define GUAC_CHAR_CONTINUATION -1
/**
* An RGB color, where each component ranges from 0 to 255.
*/
typedef struct guac_terminal_color {
/**
* The index of this color within the terminal palette, or -1 if the color
* does not exist within the terminal palette.
*/
int palette_index;
/**
* The red component of this color.
*/
uint8_t red;
/**
* The green component of this color.
*/
uint8_t green;
/**
* The blue component of this color.
*/
uint8_t blue;
} guac_terminal_color;
/** /**
* Terminal attributes, as can be applied to a single character. * Terminal attributes, as can be applied to a single character.
*/ */

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "terminal/char_mappings.h" #include "terminal/char_mappings.h"
#include "terminal/palette.h"
#include "terminal/terminal.h" #include "terminal/terminal.h"
#include "terminal/terminal_handlers.h" #include "terminal/terminal_handlers.h"
#include "terminal/types.h" #include "terminal/types.h"