2005-09-15 09:58:31 -04:00
|
|
|
#ifndef EL__TERMINAL_COLOR_H
|
|
|
|
#define EL__TERMINAL_COLOR_H
|
|
|
|
|
2010-07-31 14:51:24 -04:00
|
|
|
#include "util/color.h"
|
2020-10-05 14:14:55 -04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
struct screen_char;
|
|
|
|
|
|
|
|
/* Terminal color encoding: */
|
|
|
|
/* Below color pairs are encoded to terminal colors. Both the terminal fore-
|
|
|
|
* and background color are a number between 0 and 7. They are stored in an
|
|
|
|
* unsigned char as specified in the following bit sequence:
|
|
|
|
*
|
|
|
|
* 0bbb0fff (f = foreground, b = background)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TERM_COLOR_MASK 0x07
|
|
|
|
|
|
|
|
#if defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS)
|
2006-08-26 13:05:31 -04:00
|
|
|
#define TERM_COLOR_FOREGROUND_256(color) ((color)[0])
|
|
|
|
#define TERM_COLOR_BACKGROUND_256(color) ((color)[1])
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|
2006-08-20 08:51:06 -04:00
|
|
|
#define TERM_COLOR_FOREGROUND_16(color) ((color)[0] & TERM_COLOR_MASK)
|
|
|
|
#define TERM_COLOR_BACKGROUND_16(color) (((color)[0] >> 4) & TERM_COLOR_MASK)
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Bit flags to control how the colors are handled. */
|
2005-09-15 09:58:31 -04:00
|
|
|
enum color_flags {
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Use a decreased color range. */
|
2005-09-15 09:58:31 -04:00
|
|
|
COLOR_DECREASE_LIGHTNESS = 1,
|
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Mangle the color to stand out if attributes like underline are set.
|
|
|
|
* Useful for terminals that don't support these attributes. */
|
2005-09-15 09:58:31 -04:00
|
|
|
COLOR_ENHANCE_UNDERLINE = 2,
|
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Adjust the foreground color to be more readable by increasing the
|
2005-09-15 09:58:31 -04:00
|
|
|
* contrast. */
|
|
|
|
COLOR_INCREASE_CONTRAST = 4,
|
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Adjust the contrast if the back- and foregroundcolor is equal.
|
2005-09-15 09:58:31 -04:00
|
|
|
* If inverting should be done also pass the latter flag. */
|
|
|
|
COLOR_ENSURE_CONTRAST = 8,
|
|
|
|
COLOR_ENSURE_INVERTED_CONTRAST = 16,
|
|
|
|
};
|
|
|
|
|
2022-01-28 10:11:54 -05:00
|
|
|
typedef unsigned char color_flags_T;
|
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** How many colors the terminal supports.
|
|
|
|
* These numbers are used in the terminal._template_.colors and
|
2006-12-25 04:51:24 -05:00
|
|
|
* document.dump.color_mode options. They should be kept stable so
|
|
|
|
* that configuration files are portable between ELinks versions.
|
|
|
|
* Any unsupported modes should be treated as COLOR_MODE_16.
|
|
|
|
* (Can't fall back to COLOR_MODE_88 from COLOR_MODE_256 because
|
|
|
|
* the palettes are incompatible.) */
|
2005-09-15 09:58:31 -04:00
|
|
|
enum color_mode {
|
|
|
|
COLOR_MODE_DUMP = -1,
|
2006-12-25 04:51:24 -05:00
|
|
|
COLOR_MODE_MONO = 0,
|
|
|
|
COLOR_MODE_16 = 1,
|
2005-09-15 09:58:31 -04:00
|
|
|
#ifdef CONFIG_88_COLORS
|
2006-12-25 04:51:24 -05:00
|
|
|
COLOR_MODE_88 = 2,
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_256_COLORS
|
2006-12-25 04:51:24 -05:00
|
|
|
COLOR_MODE_256 = 3,
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|
2006-08-19 17:39:40 -04:00
|
|
|
#ifdef CONFIG_TRUE_COLOR
|
2006-12-25 04:51:24 -05:00
|
|
|
COLOR_MODE_TRUE_COLOR = 4,
|
2006-08-19 17:39:40 -04:00
|
|
|
#endif
|
2006-12-25 04:51:24 -05:00
|
|
|
COLOR_MODES = 5, /* XXX: Keep last */
|
2005-09-15 09:58:31 -04:00
|
|
|
};
|
|
|
|
|
2022-01-28 08:42:48 -05:00
|
|
|
typedef int color_mode_T;
|
|
|
|
|
2022-01-28 10:11:54 -05:00
|
|
|
void set_term_color16(struct screen_char *schar, color_flags_T flags,
|
2009-03-28 14:15:08 -04:00
|
|
|
unsigned char fg, unsigned char bg);
|
2006-05-07 09:49:08 -04:00
|
|
|
|
2007-07-27 09:50:37 -04:00
|
|
|
/** Mixes the color pair and attributes to a terminal text color.
|
|
|
|
* If @a flags has masked in the ::COLOR_INCREASE_CONTRAST the
|
|
|
|
* foreground color will be adjusted.
|
|
|
|
*
|
|
|
|
* XXX: @a schar may not be NULL and is modified adding stuff like
|
|
|
|
* boldness. */
|
2010-07-31 14:51:24 -04:00
|
|
|
|
|
|
|
color_T get_term_color16(unsigned int index);
|
|
|
|
#ifdef CONFIG_88_COLORS
|
|
|
|
color_T get_term_color88(unsigned int index);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_256_COLORS
|
|
|
|
color_T get_term_color256(unsigned int index);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void get_screen_char_color(struct screen_char *schar, struct color_pair *pair,
|
2022-01-28 10:11:54 -05:00
|
|
|
color_flags_T flags, color_mode_T color_mode);
|
2005-09-15 09:58:31 -04:00
|
|
|
void set_term_color(struct screen_char *schar, struct color_pair *pair,
|
2022-01-28 10:11:54 -05:00
|
|
|
color_flags_T flags, color_mode_T mode);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|