1 #ifndef EL__TERMINAL_COLOR_H 2 #define EL__TERMINAL_COLOR_H 3 4 struct color_pair; 5 struct screen_char; 6 7 /* Terminal color encoding: */ 8 /* Below color pairs are encoded to terminal colors. Both the terminal fore- 9 * and background color are a number between 0 and 7. They are stored in an 10 * unsigned char as specified in the following bit sequence: 11 * 12 * 0bbb0fff (f = foreground, b = background) 13 */ 14 15 #define TERM_COLOR_MASK 0x07 16 17 #if defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS) 18 #define TERM_COLOR_FOREGROUND(color) ((color)[0]) 19 #define TERM_COLOR_BACKGROUND(color) ((color)[1]) 20 #else 21 #define TERM_COLOR_FOREGROUND(color) ((color)[0] & TERM_COLOR_MASK) 22 #define TERM_COLOR_BACKGROUND(color) (((color)[0] >> 4) & TERM_COLOR_MASK) 23 #endif 24 25 /* Bit flags to control how the colors are handled. */ 26 enum color_flags { 27 /* Use a decreased color range. */ 28 COLOR_DECREASE_LIGHTNESS = 1, 29 30 /* Mangle the color to stand out if attributes like underline are set. 31 * Useful for terminals that doesn't support these attributes. */ 32 COLOR_ENHANCE_UNDERLINE = 2, 33 34 /* Adjust the forground color to be more readable by increasing the 35 * contrast. */ 36 COLOR_INCREASE_CONTRAST = 4, 37 38 /* Adjust the contrast if the back- and foregroundcolor is equal. 39 * If inverting should be done also pass the latter flag. */ 40 COLOR_ENSURE_CONTRAST = 8, 41 COLOR_ENSURE_INVERTED_CONTRAST = 16, 42 }; 43 44 enum color_mode { 45 COLOR_MODE_DUMP = -1, 46 COLOR_MODE_MONO, 47 COLOR_MODE_16, 48 #ifdef CONFIG_88_COLORS 49 COLOR_MODE_88, 50 #endif 51 #ifdef CONFIG_256_COLORS 52 COLOR_MODE_256, 53 #endif 54 55 COLOR_MODES, /* XXX: Keep last */ 56 }; 57 58 /* Mixes the color pair and attributes to a terminal text color. */ 59 /* If @flags has masked in the COLOR_INCREASE_CONTRAST the foreground color will 60 * be adjusted. */ 61 /* XXX: @schar may not be NULL and is modified adding stuff like boldness. */ 62 void set_term_color(struct screen_char *schar, struct color_pair *pair, 63 enum color_flags flags, enum color_mode mode); 64 65 #endif 66