[wip] Initial stab on inline images support, with many problems
[elinks/images.git] / src / terminal / color.h
blob1d4c283486d1fd6417f7d5c65a58d33816810d65
1 #ifndef EL__TERMINAL_COLOR_H
2 #define EL__TERMINAL_COLOR_H
4 #include "util/color.h"
5 struct screen_char;
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:
12 * 0bbb0fff (f = foreground, b = background)
15 #define TERM_COLOR_MASK 0x07
17 #if defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS)
18 #define TERM_COLOR_FOREGROUND_256(color) ((color)[0])
19 #define TERM_COLOR_BACKGROUND_256(color) ((color)[1])
20 #endif
21 #define TERM_COLOR_FOREGROUND_16(color) ((color)[0] & TERM_COLOR_MASK)
22 #define TERM_COLOR_BACKGROUND_16(color) (((color)[0] >> 4) & TERM_COLOR_MASK)
24 /** Bit flags to control how the colors are handled. */
25 enum color_flags {
26 /** Use a decreased color range. */
27 COLOR_DECREASE_LIGHTNESS = 1,
29 /** Mangle the color to stand out if attributes like underline are set.
30 * Useful for terminals that don't support these attributes. */
31 COLOR_ENHANCE_UNDERLINE = 2,
33 /** Adjust the foreground color to be more readable by increasing the
34 * contrast. */
35 COLOR_INCREASE_CONTRAST = 4,
37 /** Adjust the contrast if the back- and foregroundcolor is equal.
38 * If inverting should be done also pass the latter flag. */
39 COLOR_ENSURE_CONTRAST = 8,
40 COLOR_ENSURE_INVERTED_CONTRAST = 16,
43 /** How many colors the terminal supports.
44 * These numbers are used in the terminal._template_.colors and
45 * document.dump.color_mode options. They should be kept stable so
46 * that configuration files are portable between ELinks versions.
47 * Any unsupported modes should be treated as COLOR_MODE_16.
48 * (Can't fall back to COLOR_MODE_88 from COLOR_MODE_256 because
49 * the palettes are incompatible.) */
50 enum color_mode {
51 COLOR_MODE_DUMP = -1,
52 COLOR_MODE_MONO = 0,
53 COLOR_MODE_16 = 1,
54 #ifdef CONFIG_88_COLORS
55 COLOR_MODE_88 = 2,
56 #endif
57 #ifdef CONFIG_256_COLORS
58 COLOR_MODE_256 = 3,
59 #endif
60 #ifdef CONFIG_TRUE_COLOR
61 COLOR_MODE_TRUE_COLOR = 4,
62 #endif
63 COLOR_MODES = 5, /* XXX: Keep last */
66 void set_term_color16(struct screen_char *schar, enum color_flags flags,
67 unsigned char fg, unsigned char bg);
69 /** Mixes the color pair and attributes to a terminal text color.
70 * If @a flags has masked in the ::COLOR_INCREASE_CONTRAST the
71 * foreground color will be adjusted.
73 * XXX: @a schar may not be NULL and is modified adding stuff like
74 * boldness. */
76 color_T get_term_color16(unsigned int index);
77 #ifdef CONFIG_88_COLORS
78 color_T get_term_color88(unsigned int index);
79 #endif
80 #ifdef CONFIG_256_COLORS
81 color_T get_term_color256(unsigned int index);
82 #endif
84 void get_screen_char_color(struct screen_char *schar, struct color_pair *pair,
85 enum color_flags flags, enum color_mode color_mode);
86 void set_term_color(struct screen_char *schar, struct color_pair *pair,
87 enum color_flags flags, enum color_mode mode);
89 #endif