From eaa71f5717c85424ada7d3f63cbff3ad58661361 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 23 Apr 2017 11:38:49 -0700 Subject: [PATCH] GUACAMOLE-278: Move terminal palette/color definitions into dedicated files. --- src/terminal/Makefile.am | 2 + src/terminal/common.c | 20 ---- src/terminal/display.c | 25 +---- src/terminal/palette.c | 66 +++++++++++++ src/terminal/terminal.c | 1 + src/terminal/terminal/common.h | 21 ---- src/terminal/terminal/display.h | 88 +---------------- src/terminal/terminal/palette.h | 163 +++++++++++++++++++++++++++++++ src/terminal/terminal/types.h | 29 +----- src/terminal/terminal_handlers.c | 1 + 10 files changed, 236 insertions(+), 180 deletions(-) create mode 100644 src/terminal/palette.c create mode 100644 src/terminal/terminal/palette.h diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am index 53bc74d1..b3474605 100644 --- a/src/terminal/Makefile.am +++ b/src/terminal/Makefile.am @@ -27,6 +27,7 @@ noinst_HEADERS = \ terminal/char_mappings.h \ terminal/common.h \ terminal/display.h \ + terminal/palette.h \ terminal/scrollbar.h \ terminal/terminal.h \ terminal/terminal_handlers.h \ @@ -38,6 +39,7 @@ libguac_terminal_la_SOURCES = \ char_mappings.c \ common.c \ display.c \ + palette.c \ scrollbar.c \ terminal.c \ terminal_handlers.c \ diff --git a/src/terminal/common.c b/src/terminal/common.c index 27ca3b4d..99137534 100644 --- a/src/terminal/common.c +++ b/src/terminal/common.c @@ -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; - -} - diff --git a/src/terminal/display.c b/src/terminal/display.c index a4995ba3..8d2b1311 100644 --- a/src/terminal/display.c +++ b/src/terminal/display.c @@ -22,6 +22,7 @@ #include "common/surface.h" #include "terminal/common.h" #include "terminal/display.h" +#include "terminal/palette.h" #include "terminal/types.h" #include @@ -36,30 +37,6 @@ #include #include -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. */ diff --git a/src/terminal/palette.c b/src/terminal/palette.c new file mode 100644 index 00000000..374495da --- /dev/null +++ b/src/terminal/palette.c @@ -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; + +} + diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 0c1628e9..711a0fa8 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -24,6 +24,7 @@ #include "terminal/buffer.h" #include "terminal/common.h" #include "terminal/display.h" +#include "terminal/palette.h" #include "terminal/terminal.h" #include "terminal/terminal_handlers.h" #include "terminal/types.h" diff --git a/src/terminal/terminal/common.h b/src/terminal/terminal/common.h index 615779e6..ad059a87 100644 --- a/src/terminal/terminal/common.h +++ b/src/terminal/terminal/common.h @@ -50,26 +50,5 @@ bool guac_terminal_has_glyph(int codepoint); */ 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 diff --git a/src/terminal/terminal/display.h b/src/terminal/terminal/display.h index 1e886ff4..6397fe53 100644 --- a/src/terminal/terminal/display.h +++ b/src/terminal/terminal/display.h @@ -24,6 +24,7 @@ #include "config.h" #include "common/surface.h" +#include "palette.h" #include "types.h" #include @@ -37,93 +38,6 @@ */ #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. */ diff --git a/src/terminal/terminal/palette.h b/src/terminal/terminal/palette.h new file mode 100644 index 00000000..b0e52d13 --- /dev/null +++ b/src/terminal/terminal/palette.h @@ -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 + +/** + * 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 + diff --git a/src/terminal/terminal/types.h b/src/terminal/terminal/types.h index 47f27415..7d3cd537 100644 --- a/src/terminal/terminal/types.h +++ b/src/terminal/terminal/types.h @@ -22,6 +22,7 @@ #define _GUAC_TERMINAL_TYPES_H #include "config.h" +#include "palette.h" #include #include @@ -35,34 +36,6 @@ */ #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. */ diff --git a/src/terminal/terminal_handlers.c b/src/terminal/terminal_handlers.c index 330774aa..a4e514c9 100644 --- a/src/terminal/terminal_handlers.c +++ b/src/terminal/terminal_handlers.c @@ -20,6 +20,7 @@ #include "config.h" #include "terminal/char_mappings.h" +#include "terminal/palette.h" #include "terminal/terminal.h" #include "terminal/terminal_handlers.h" #include "terminal/types.h"