C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Color Management

Conversion of Color Data Types and Management of Colors and Color Pairs. More...

Functions

void apply_gamma (RGB *rgb)
 Apply gamma correction to RGB color.
int clr_name_to_idx (char *s)
 Get color index from color name.
void display_cmplx_str (WINDOW *win, cchar_t *cmplx_buf, int line, int col)
 Display a complex character string on a window.
int get_clr_pair (int fg, int bg)
 Get color pair index for foreground and background colors.
RGB hex_clr_str_to_rgb (char *s)
 Convert six-digit HTML style hex color code to RGB struct.
bool init_clr_palette (SIO *sio)
 Initialize color palette based on SIO settings.
void init_hex_clr (int idx, char *s)
 Initialize extended ncurses color from HTML style hex string.
void initialize_local_colors (SIO *sio)
 Initialize local color variables and color pairs based on SIO settings.
void list_colors ()
 list colors to stderr
size_t mk_cmplx_str (cchar_t *cmplx_buf, char *s, attr_t attr, int cp)
 Convert a multibyte string to an array of cchar_t complex characters.
cchar_t mkcc (int cp, attr_t attr, const char *s)
 Create a cchar_t with the specified color pair index.
int rgb_to_curses_clr (RGB *rgb)
 Get color index for RGB color.
int rgb_to_xterm256_idx (RGB *rgb)
 Convert RGB color to XTerm 256 color index.
size_t str_to_cc (cchar_t *cmplx_buf, const char *s, attr_t attr, int cp, size_t maxlen)
 Convert a multibyte string to an array of cchar_t complex characters.
RGB xterm256_idx_to_rgb (int idx)
 Convert XTerm 256 color index to RGB.

Detailed Description

Conversion of Color Data Types and Management of Colors and Color Pairs.

Function Documentation

◆ apply_gamma()

void apply_gamma ( RGB * rgb)

Apply gamma correction to RGB color.

apply_gamma

Parameters
rgbPointer to RGB color

This function modifies the RGB color in place. It applies gamma correction to the RGB color based on the gamma values set in the SIO struct. If the color is a shade of gray, it applies the gray gamma correction. Otherwise, it applies the individual red, green, and blue gamma corrections.

Definition at line 518 of file dwin.c.

518 {
519 if (rgb->r == rgb->g && rgb->r == rgb->b) {
520 if (GRAY_GAMMA > 0.0f && GRAY_GAMMA != 1.0f) {
521 rgb->r = (int)(pow((rgb->r / 255.0f), 1.0f / GRAY_GAMMA) * 255.0f);
522 rgb->g = rgb->r;
523 rgb->b = rgb->r;
524 }
525 return;
526 }
527 if (rgb->r != 0 && RED_GAMMA > 0.0f && RED_GAMMA != 1.0f)
528 rgb->r = (int)(pow((rgb->r / 255.0f), 1.0f / RED_GAMMA) * 255.0f);
529 if (rgb->g != 0 && GREEN_GAMMA > 0.0f && GREEN_GAMMA != 1.0f)
530 rgb->g = (int)(pow((rgb->g / 255.0f), 1.0f / GREEN_GAMMA) * 255.0f);
531 if (rgb->b != 0 && BLUE_GAMMA > 0.0f && BLUE_GAMMA != 1.0f)
532 rgb->b = (int)(pow((rgb->b / 255.0f), 1.0f / BLUE_GAMMA) * 255.0f);
533}
double BLUE_GAMMA
Definition dwin.c:157
double GRAY_GAMMA
Definition dwin.c:154
double RED_GAMMA
Definition dwin.c:155
double GREEN_GAMMA
Definition dwin.c:156
int r
Definition cm.h:382
int b
Definition cm.h:382
int g
Definition cm.h:382

References RGB::b, BLUE_GAMMA, RGB::g, GRAY_GAMMA, GREEN_GAMMA, RGB::r, and RED_GAMMA.

Referenced by init_hex_clr(), and rgb_to_curses_clr().

Here is the caller graph for this function:

◆ clr_name_to_idx()

int clr_name_to_idx ( char * s)

Get color index from color name.

clr_name_to_idx

Parameters
sColor name
Returns
Color index or -1 if not found

Definition at line 1966 of file dwin.c.

1966 {
1967 int i = 0;
1968 int n = 16;
1969
1970 str_to_lower(s);
1971 while (i < n) {
1972 if (!strcmp(colors_text[i], s))
1973 break;
1974 i++;
1975 }
1976 if (i >= n)
1977 return (-1);
1978 return (i);
1979}
char const colors_text[][10]
Color names for .minitrc overrides.
Definition dwin.c:133
bool str_to_lower(char *)
Converts a string to lowercase.
Definition futil.c:508

References colors_text, and str_to_lower().

Here is the call graph for this function:

◆ display_cmplx_str()

void display_cmplx_str ( WINDOW * win,
cchar_t * cmplx_buf,
int line,
int col )

Display a complex character string on a window.

display_cmplx_str

Parameters
winNCurses window to display the string on
cmplx_bufArray of cchar_t complex characters to display
lineLine number to display the string on
colColumn number to start displaying the string from

This function clears the line where the string will be displayed, then uses wadd_wchstr to add the complex character string (cmplx_buf) to the window. Finally, it moves the cursor to the specified column position.

Definition at line 857 of file dwin.c.

857 {
858 wmove(win, line, 0);
859 wclrtoeol(win);
860 wmove(win, line, 0);
861 wadd_wchstr(win, cmplx_buf);
862 wmove(win, line, col);
863 return;
864}

◆ get_clr_pair()

int get_clr_pair ( int fg,
int bg )

Get color pair index for foreground and background colors.

get_clr_pair

Parameters
fgForeground color index
bgBackground color index
Returns
Color pair index

Definition at line 401 of file dwin.c.

401 {
402 int rc, i, pfg, pbg;
403 for (i = 1; i < clr_pair_cnt; i++) {
404 extended_pair_content(i, &pfg, &pbg);
405 if (pfg == fg && pbg == bg)
406 return i;
407 }
408 if (i >= COLOR_PAIRS) {
409 ssnprintf(em0, MAXLEN - 1, "%s, line: %d", __FILE__, __LINE__ - 1);
410 ssnprintf(em1, MAXLEN - 1, "NCurses COLOR_PAIRS (%d) exceeded (%d)",
411 COLOR_PAIRS, i);
412 strerror_r(errno, em2, MAXLEN);
413 display_error(em0, em1, em2, nullptr);
414 return (EXIT_FAILURE);
415 }
416 if (i < COLOR_PAIRS) {
417 rc = init_extended_pair(i, fg, bg);
418 if (rc == ERR)
419 return ERR;
420 }
421 if (i < COLOR_PAIRS)
422 clr_pair_cnt++;
423 return i;
424}
int clr_pair_cnt
Definition dwin.c:197
char em1[MAXLEN]
Definition dwin.c:176
char em0[MAXLEN]
Definition dwin.c:175
char em2[MAXLEN]
Definition dwin.c:177
#define MAXLEN
Definition curskeys.c:15
int display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
Definition dwin.c:1467
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:420

References clr_pair_cnt, display_error(), em0, em1, em2, and ssnprintf().

Referenced by initialize_local_colors(), parse_ansi_str(), and ui_style_to_cch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hex_clr_str_to_rgb()

RGB hex_clr_str_to_rgb ( char * s)

Convert six-digit HTML style hex color code to RGB struct.

hex_clr_str_to_rgb

Parameters
ssix-digit HTML style hex color code

Definition at line 656 of file dwin.c.

656 {
657 RGB rgb;
658 sscanf(s, "#%02x%02x%02x", &rgb.r, &rgb.g, &rgb.b);
659 return rgb;
660}
Definition cm.h:381

References RGB::b, RGB::g, and RGB::r.

Referenced by init_hex_clr().

Here is the caller graph for this function:

◆ init_clr_palette()

bool init_clr_palette ( SIO * sio)

Initialize color palette based on SIO settings.

init_clr_palette

Parameters
sioPointer to SIO struct with color settings
Returns
true if successful, false if error

This function initializes the xterm256 color cube and applies any color overrides specified in the SIO struct. The color strings in the SIO struct are expected to be six-digit HTML style hex color codes (e.g., "#RRGGBB"). If a color override is specified for any of the standard colors, it is applied using the init_hex_clr function. After processing all colors, the clr_cnt variable is set to CLR_NCOLORS to indicate that the standard colors have been initialized.

Definition at line 546 of file dwin.c.

546 {
547 if (sio->black[0])
549 if (sio->red[0])
550 init_hex_clr(CLR_RED, sio->red);
551 if (sio->green[0])
553 if (sio->yellow[0])
555 if (sio->blue[0])
557 if (sio->magenta[0])
559 if (sio->cyan[0])
561 if (sio->white[0])
563 if (sio->bblack[0])
565 if (sio->bred[0])
567 if (sio->bgreen[0])
569 if (sio->byellow[0])
571 if (sio->bblue[0])
573 if (sio->bmagenta[0])
575 if (sio->bcyan[0])
577 if (sio->bwhite[0])
579 if (sio->borange[0])
581 if (sio->fg[0])
582 init_hex_clr(CLR_FG, sio->fg);
583 if (sio->bg[0])
584 init_hex_clr(CLR_BG, sio->bg);
585 if (sio->box_fg[0])
587 if (sio->box_bg[0])
589 if (sio->ind_fg[0])
591 if (sio->ind_bg[0])
593 if (sio->title_fg[0])
595 if (sio->title_bg[0])
597 if (sio->ln_fg[0])
599 if (sio->ln_bg[0])
601 if (sio->nt_fg[0])
603 if (sio->nt_bg[0])
605 if (sio->nt_rev_fg[0])
607 if (sio->nt_rev_bg[0])
609 if (sio->nt_hl_fg[0])
611 if (sio->nt_hl_bg[0])
613 if (sio->nt_hl_rev_fg[0])
615 if (sio->nt_hl_rev_bg[0])
617 if (sio->fill_char_fg[0])
619 if (sio->fill_char_bg[0])
621 if (sio->brackets_fg[0])
623 if (sio->brackets_bg[0])
626 return true;
627}
int clr_cnt
Definition dwin.c:195
@ CLR_FILL_CHAR_BG
Definition cm.h:183
@ CLR_BOX_BG
Definition cm.h:177
@ CLR_FILL_CHAR_FG
Definition cm.h:182
@ CLR_FG
Definition cm.h:174
@ CLR_RED
Definition cm.h:158
@ CLR_NT_FG
Definition cm.h:188
@ CLR_BRACKETS_FG
Definition cm.h:180
@ CLR_YELLOW
Definition cm.h:160
@ CLR_IND_FG
Definition cm.h:178
@ CLR_BCYAN
Definition cm.h:171
@ CLR_TITLE_FG
Definition cm.h:196
@ CLR_WHITE
Definition cm.h:164
@ CLR_MAGENTA
Definition cm.h:162
@ CLR_BRACKETS_BG
Definition cm.h:181
@ CLR_NT_REV_BG
Definition cm.h:191
@ CLR_BLACK
Definition cm.h:157
@ CLR_BWHITE
Definition cm.h:172
@ CLR_LN_BG
Definition cm.h:185
@ CLR_NT_HL_REV_BG
Definition cm.h:195
@ CLR_BBLACK
Definition cm.h:165
@ CLR_LN_FG
Definition cm.h:184
@ CLR_NT_HL_FG
Definition cm.h:192
@ CLR_BBLUE
Definition cm.h:169
@ CLR_BGREEN
Definition cm.h:167
@ CLR_BYELLOW
Definition cm.h:168
@ CLR_BMAGENTA
Definition cm.h:170
@ CLR_BORANGE
Definition cm.h:173
@ CLR_NT_HL_BG
Definition cm.h:193
@ CLR_NT_HL_REV_FG
Definition cm.h:194
@ CLR_BG
Definition cm.h:175
@ CLR_BOX_FG
Definition cm.h:176
@ CLR_NT_BG
Definition cm.h:189
@ CLR_TITLE_BG
Definition cm.h:197
@ CLR_BRED
Definition cm.h:166
@ CLR_NCOLORS
Definition cm.h:198
@ CLR_BLUE
Definition cm.h:161
@ CLR_IND_BG
Definition cm.h:179
@ CLR_GREEN
Definition cm.h:159
@ CLR_NT_REV_FG
Definition cm.h:190
@ CLR_CYAN
Definition cm.h:163
void init_hex_clr(int, char *)
Initialize extended ncurses color from HTML style hex string.
Definition dwin.c:638
char nt_hl_rev_bg[COLOR_LEN]
Definition cm.h:852
char nt_rev_bg[COLOR_LEN]
Definition cm.h:846
char ln_fg[COLOR_LEN]
Definition cm.h:839
char black[COLOR_LEN]
Definition cm.h:810
char title_bg[COLOR_LEN]
Definition cm.h:854
char bred[COLOR_LEN]
Definition cm.h:820
char yellow[COLOR_LEN]
Definition cm.h:813
char nt_hl_bg[COLOR_LEN]
Definition cm.h:848
char nt_hl_fg[COLOR_LEN]
Definition cm.h:847
char ind_fg[COLOR_LEN]
Definition cm.h:833
char bcyan[COLOR_LEN]
Definition cm.h:825
char borange[COLOR_LEN]
Definition cm.h:827
char red[COLOR_LEN]
Definition cm.h:811
char nt_fg[COLOR_LEN]
Definition cm.h:843
char magenta[COLOR_LEN]
Definition cm.h:815
char ln_bg[COLOR_LEN]
Definition cm.h:840
char bgreen[COLOR_LEN]
Definition cm.h:821
char nt_rev_fg[COLOR_LEN]
Definition cm.h:845
char brackets_fg[COLOR_LEN]
Definition cm.h:835
char fill_char_fg[COLOR_LEN]
Definition cm.h:837
char byellow[COLOR_LEN]
Definition cm.h:822
char bwhite[COLOR_LEN]
Definition cm.h:826
char box_bg[COLOR_LEN]
Definition cm.h:832
char fg[COLOR_LEN]
Definition cm.h:829
char cyan[COLOR_LEN]
Definition cm.h:816
char brackets_bg[COLOR_LEN]
Definition cm.h:836
char box_fg[COLOR_LEN]
Definition cm.h:831
char fill_char_bg[COLOR_LEN]
Definition cm.h:838
char green[COLOR_LEN]
Definition cm.h:812
char white[COLOR_LEN]
Definition cm.h:817
char bg[COLOR_LEN]
Definition cm.h:830
char bblue[COLOR_LEN]
Definition cm.h:823
char title_fg[COLOR_LEN]
Definition cm.h:853
char bmagenta[COLOR_LEN]
Definition cm.h:824
char blue[COLOR_LEN]
Definition cm.h:814
char nt_hl_rev_fg[COLOR_LEN]
Definition cm.h:850
char bblack[COLOR_LEN]
Definition cm.h:819
char ind_bg[COLOR_LEN]
Definition cm.h:834
char nt_bg[COLOR_LEN]
Definition cm.h:844

References SIO::bblack, SIO::bblue, SIO::bcyan, SIO::bg, SIO::bgreen, SIO::black, SIO::blue, SIO::bmagenta, SIO::borange, SIO::box_bg, SIO::box_fg, SIO::brackets_bg, SIO::brackets_fg, SIO::bred, SIO::bwhite, SIO::byellow, CLR_BBLACK, CLR_BBLUE, CLR_BCYAN, CLR_BG, CLR_BGREEN, CLR_BLACK, CLR_BLUE, CLR_BMAGENTA, CLR_BORANGE, CLR_BOX_BG, CLR_BOX_FG, CLR_BRACKETS_BG, CLR_BRACKETS_FG, CLR_BRED, CLR_BWHITE, CLR_BYELLOW, clr_cnt, CLR_CYAN, CLR_FG, CLR_FILL_CHAR_BG, CLR_FILL_CHAR_FG, CLR_GREEN, CLR_IND_BG, CLR_IND_FG, CLR_LN_BG, CLR_LN_FG, CLR_MAGENTA, CLR_NCOLORS, CLR_NT_BG, CLR_NT_FG, CLR_NT_HL_BG, CLR_NT_HL_FG, CLR_NT_HL_REV_BG, CLR_NT_HL_REV_FG, CLR_NT_REV_BG, CLR_NT_REV_FG, CLR_RED, CLR_TITLE_BG, CLR_TITLE_FG, CLR_WHITE, CLR_YELLOW, SIO::cyan, SIO::fg, SIO::fill_char_bg, SIO::fill_char_fg, SIO::green, SIO::ind_bg, SIO::ind_fg, init_hex_clr(), SIO::ln_bg, SIO::ln_fg, SIO::magenta, SIO::nt_bg, SIO::nt_fg, SIO::nt_hl_bg, SIO::nt_hl_fg, SIO::nt_hl_rev_bg, SIO::nt_hl_rev_fg, SIO::nt_rev_bg, SIO::nt_rev_fg, SIO::red, SIO::title_bg, SIO::title_fg, SIO::white, and SIO::yellow.

Referenced by initialize_local_colors().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_hex_clr()

void init_hex_clr ( int idx,
char * s )

Initialize extended ncurses color from HTML style hex string.

init_hex_clr

Parameters
idxColor index
sHex color string

NCurses uses 0-1000 for RGB values, so the RGB values from the hex string are converted to this range before initializing the color. If the color index is less than 16, the RGB values are also stored in the StdColors array for reference.

Definition at line 638 of file dwin.c.

638 {
639 RGB rgb;
640 rgb = hex_clr_str_to_rgb(s);
641 apply_gamma(&rgb);
642 if (idx < 16) {
643 StdColors[idx].r = rgb.r;
644 StdColors[idx].g = rgb.g;
645 StdColors[idx].b = rgb.b;
646 }
647 rgb.r = (rgb.r * 1000) / 255;
648 rgb.g = (rgb.g * 1000) / 255;
649 rgb.b = (rgb.b * 1000) / 255;
650 init_extended_color(idx, rgb.r, rgb.g, rgb.b);
651}
RGB StdColors[16]
Definition dwin.c:127
RGB hex_clr_str_to_rgb(char *)
Convert six-digit HTML style hex color code to RGB struct.
Definition dwin.c:656
void apply_gamma(RGB *)
Apply gamma correction to RGB color.
Definition dwin.c:518

References apply_gamma(), RGB::b, RGB::g, hex_clr_str_to_rgb(), RGB::r, and StdColors.

Referenced by init_clr_palette().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize_local_colors()

void initialize_local_colors ( SIO * sio)

Initialize local color variables and color pairs based on SIO settings.

Parameters
sioPointer to SIO struct with color settings

This function initializes local color variables and color pairs based on the settings in the SIO struct. It applies gamma correction to colors and sets up cchar_t variables for use in NCurses functions. The color pair indices are stored in global variables for easy reference throughout the code when applying colors to various parts of the interface using NCurses functions that accept color pair indices.

gamma correction values

These are read from ~/.minitrc

used when initializing colors

Definition at line 320 of file dwin.c.

320 {
324 RED_GAMMA = sio->red_gamma;
326 BLUE_GAMMA = sio->blue_gamma;
327 GRAY_GAMMA = sio->gray_gamma;
328 init_clr_palette(sio);
329
330 // Color Pairs
331 // Often used standardized color pairs for the user interface
348
349 // cchar_t For setting backgrounds
350 // with attributes and color pairs
351 CC_FILL_CHAR = mkcc(cp_fill_char, WA_NORMAL, " ");
352 CC_BRKTL = mkcc(cp_brackets, WA_NORMAL, " ");
353 CC_BRKTR = mkcc(cp_brackets, WA_NORMAL, " ");
354 CC_NT = mkcc(cp_nt, WA_NORMAL, " ");
355 CC_NT_REV = mkcc(cp_nt_rev, WA_NORMAL, " ");
356 CC_NT_HL_REV = mkcc(cp_nt_hl_rev, WA_NORMAL, " ");
357 CC_NT_HL = mkcc(cp_nt_hl, WA_NORMAL, " ");
358 CC_BOX = mkcc(cp_box, WA_NORMAL, " ");
359 CC_IND = mkcc(cp_ind, WA_NORMAL, " ");
360 CC_CMDLN = mkcc(cp_cmdln, WA_NORMAL, " ");
361 CC_TITLE = mkcc(cp_title, WA_NORMAL, " ");
362 CC_LN = mkcc(cp_ln, WA_NORMAL, " ");
363 CC_NORM = mkcc(cp_norm, WA_NORMAL, " ");
364 CC_RAN = mkcc(cp_ind, WA_NORMAL, " ");
365 CC_CHK = mkcc(cp_ind, WA_NORMAL, " ");
366 CC_RED = mkcc(cp_red, WA_NORMAL, " ");
367 CC_GREEN = mkcc(cp_green, WA_NORMAL, " ");
368 CC_YELLOW = mkcc(cp_yellow, WA_NORMAL, " ");
369 CC_BLUE = mkcc(cp_blue, WA_NORMAL, " ");
370
371 // cchar_t For borders and indicators
372 // with attributes and color pairs
373 setcchar(&ls, &bw_ve, WA_NORMAL, cp_box, NULL); // Left side
374 setcchar(&rs, &bw_ve, WA_NORMAL, cp_box, NULL); // Right side
375 setcchar(&ts, &bw_ho, WA_NORMAL, cp_box, NULL); // Top side
376 setcchar(&bs, &bw_ho, WA_NORMAL, cp_box, NULL); // Bottom side
377 setcchar(&tl, &bw_tl, WA_NORMAL, cp_box, NULL); // Top-left corner
378 setcchar(&tr, &bw_tr, WA_NORMAL, cp_box, NULL); // Top-right corner
379 setcchar(&bl, &bw_bl, WA_NORMAL, cp_box, NULL); // Bottom-left corner
380 setcchar(&br, &bw_br, WA_NORMAL, cp_box, NULL); // Bottom-right corner
381 setcchar(&lt, &bw_lt, WA_NORMAL, cp_box, NULL); // Left tee
382 setcchar(&rt, &bw_rt, WA_NORMAL, cp_box, NULL); // Right tee
383 setcchar(&sp, &bw_sp, WA_NORMAL, cp_box, NULL); // Space
384 setcchar(&ra, &bw_ra, WA_NORMAL, cp_box, NULL); // Right arrow
385 setcchar(&la, &bw_la, WA_NORMAL, cp_box, NULL); // Left arrow
386 setcchar(&ua, &bw_ua, WA_NORMAL, cp_box, NULL); // Up arrow
387 setcchar(&da, &bw_da, WA_NORMAL, cp_box, NULL); // Down arrow
388 setcchar(&ran, &bw_ran, WA_NORMAL, cp_ind, NULL); // Right angle
389 setcchar(&chk, &bw_chk, WA_NORMAL, cp_ind, NULL); // Right angle
390}
cchar_t CC_YELLOW
Definition dwin.c:216
const wchar_t bw_chk
Definition dwin.c:152
int cp_box
Definition dwin.c:179
const wchar_t bw_rt
Definition dwin.c:145
int cp_brackets
Definition dwin.c:190
const wchar_t bw_ho
Definition dwin.c:138
int cp_nt
Definition dwin.c:183
int cp_nt_hl
Definition dwin.c:185
int cp_ind
Definition dwin.c:180
cchar_t tl
Definition cm.h:501
cchar_t chk
Definition cm.h:631
cchar_t la
Definition cm.h:631
const wchar_t bw_tl
Definition dwin.c:140
const wchar_t bw_ua
Definition dwin.c:149
cchar_t CC_FILL_CHAR
Definition dwin.c:211
cchar_t ua
Definition cm.h:631
int cp_title
Definition dwin.c:182
int cp_yellow
Definition dwin.c:193
cchar_t CC_BLUE
Definition dwin.c:217
cchar_t da
Definition cm.h:631
cchar_t br
Definition cm.h:501
const wchar_t bw_tr
Definition dwin.c:141
cchar_t CC_NT
Definition dwin.c:204
cchar_t rs
Definition cm.h:501
cchar_t lt
Definition cm.h:631
cchar_t CC_GREEN
Definition dwin.c:215
cchar_t ran
Definition cm.h:631
const wchar_t bw_ran
Definition dwin.c:151
int cp_blue
Definition dwin.c:194
cchar_t CC_IND
Definition dwin.c:200
cchar_t CC_BRKTL
Definition cm.h:494
const wchar_t bw_sp
Definition dwin.c:146
const wchar_t bw_ra
Definition dwin.c:147
cchar_t CC_BOX
Definition dwin.c:199
const wchar_t bw_da
Definition dwin.c:150
cchar_t sp
Definition cm.h:631
cchar_t CC_TITLE
Definition dwin.c:203
int cp_red
Definition dwin.c:191
const wchar_t bw_lt
Definition dwin.c:144
cchar_t bl
Definition cm.h:501
const wchar_t bw_la
Definition dwin.c:148
int cp_nt_hl_rev
Definition dwin.c:186
cchar_t CC_RED
Definition dwin.c:214
const wchar_t bw_bl
Definition dwin.c:142
@ CLR_CMDLN_BG
Definition cm.h:187
@ CLR_CMDLN_FG
Definition cm.h:186
int cp_green
Definition dwin.c:192
cchar_t CC_NT_HL
Definition dwin.c:207
cchar_t ts
Definition cm.h:501
cchar_t CC_CMDLN
Definition dwin.c:202
const wchar_t bw_ve
Definition dwin.c:139
cchar_t CC_NT_REV
Definition dwin.c:205
int cp_nt_rev
Definition dwin.c:184
cchar_t tr
Definition cm.h:501
cchar_t ra
Definition cm.h:631
cchar_t ls
Definition cm.h:631
cchar_t rt
Definition cm.h:631
int cp_fill_char
Definition dwin.c:189
const wchar_t bw_br
Definition dwin.c:143
cchar_t bs
Definition cm.h:501
cchar_t CC_BRKTR
Definition cm.h:495
cchar_t CC_LN
Definition dwin.c:201
cchar_t CC_NT_HL_REV
Definition dwin.c:206
cchar_t CC_NORM
Definition dwin.c:208
int cp_ln
Definition dwin.c:187
cchar_t CC_RAN
Definition dwin.c:213
cchar_t CC_CHK
Definition dwin.c:212
int cp_cmdln
Definition dwin.c:181
int cp_norm
Definition dwin.c:188
bool init_clr_palette(SIO *)
Initialize color palette based on SIO settings.
Definition dwin.c:546
cchar_t mkcc(int, attr_t, const char *)
Create a cchar_t with the specified color pair index.
Definition dwin.c:748
int get_clr_pair(int fg, int bg)
Get color pair index for foreground and background colors.
Definition dwin.c:401
double green_gamma
Definition cm.h:807
double blue_gamma
Definition cm.h:808
double red_gamma
Definition cm.h:806
double gray_gamma
Definition cm.h:809

References bl, BLUE_GAMMA, SIO::blue_gamma, br, bs, bw_bl, bw_br, bw_chk, bw_da, bw_ho, bw_la, bw_lt, bw_ra, bw_ran, bw_rt, bw_sp, bw_tl, bw_tr, bw_ua, bw_ve, CC_BLUE, CC_BOX, CC_BRKTL, CC_BRKTR, CC_CHK, CC_CMDLN, CC_FILL_CHAR, CC_GREEN, CC_IND, CC_LN, CC_NORM, CC_NT, CC_NT_HL, CC_NT_HL_REV, CC_NT_REV, CC_RAN, CC_RED, CC_TITLE, CC_YELLOW, chk, CLR_BG, CLR_BLUE, CLR_BOX_BG, CLR_BOX_FG, CLR_BRACKETS_BG, CLR_BRACKETS_FG, CLR_CMDLN_BG, CLR_CMDLN_FG, CLR_FG, CLR_FILL_CHAR_BG, CLR_FILL_CHAR_FG, CLR_GREEN, CLR_IND_BG, CLR_IND_FG, CLR_LN_BG, CLR_LN_FG, CLR_NT_BG, CLR_NT_FG, CLR_NT_HL_BG, CLR_NT_HL_FG, CLR_NT_HL_REV_BG, CLR_NT_HL_REV_FG, CLR_NT_REV_BG, CLR_NT_REV_FG, CLR_RED, CLR_TITLE_BG, CLR_TITLE_FG, CLR_YELLOW, cp_blue, cp_box, cp_brackets, cp_cmdln, cp_fill_char, cp_green, cp_ind, cp_ln, cp_norm, cp_nt, cp_nt_hl, cp_nt_hl_rev, cp_nt_rev, cp_red, cp_title, cp_yellow, da, get_clr_pair(), GRAY_GAMMA, SIO::gray_gamma, GREEN_GAMMA, SIO::green_gamma, init_clr_palette(), la, ls, lt, mkcc(), ra, ran, RED_GAMMA, SIO::red_gamma, rs, rt, sp, tl, tr, ts, and ua.

Referenced by main(), and read_theme().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ list_colors()

void list_colors ( )

list colors to stderr

list_colors

only lists the first 16, since that's how many we let the user redefine

Definition at line 1985 of file dwin.c.

1985 {
1986 int i, col;
1987
1988 for (i = 0, col = 0; i < 16; i++, col++) {
1989 if (i < 8) {
1990 fprintf(stderr, " ");
1991 }
1992 if (i == 8) {
1993 col = 0;
1994 fprintf(stderr, "\n");
1995 } else if (col > 0)
1996 fprintf(stderr, " ");
1997 fprintf(stderr, "%s", colors_text[i]);
1998 }
1999 fprintf(stderr, "\n");
2000}

References colors_text.

◆ mk_cmplx_str()

size_t mk_cmplx_str ( cchar_t * cmplx_buf,
char * s,
attr_t attr,
int cp )

Convert a multibyte string to an array of cchar_t complex characters.

mk_cmplx_str

Parameters
cmplx_bufOutput buffer for complex characters
sInput multibyte string
attrAttributes to apply to the complex characters
cpColor pair index for the complex characters
Returns
Number of bytes processed from the input string

Definition at line 828 of file dwin.c.

828 {
829 cchar_t cc = {0};
830 wchar_t wstr[2] = {L'\0', L'\0'};
831 mbstate_t mbstate;
832 memset(&mbstate, 0, sizeof(mbstate));
833 size_t len = strlen(s);
834
835 while (*s != '\0') {
836 mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
837 setcchar(&cc, wstr, attr, cp, nullptr);
838 *cmplx_buf++ = cc;
839 s += mbrlen(s, MB_CUR_MAX, &mbstate);
840 }
841 wstr[0] = L'\0';
842 wstr[1] = L'\0';
843 setcchar(&cc, wstr, attr, cp, nullptr);
844 *cmplx_buf++ = cc;
845 return len;
846}

◆ mkcc()

cchar_t mkcc ( int cp,
attr_t attr,
const char * s )

Create a cchar_t with the specified color pair index.

mkcc

Parameters
cpColor pair index
attrAttributes to apply to the cchar_t
sMultibyte string to convert to wide character (only the first character is used)
Returns
cchar_t with the specified color pair index and a space character as the wide character

Definition at line 748 of file dwin.c.

748 {
749 mbstate_t mbstate;
750 memset(&mbstate, 0, sizeof(mbstate));
751 size_t len;
752 size_t n;
753 cchar_t cc = {0};
754 wchar_t wstr[2] = {L'\0', L'\0'};
755 len = strlen(s);
756 if (len > 0) {
757 n = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
758 if (n <= 0) {
759 wstr[0] = L'?';
760 wstr[1] = L'\0';
761 } else {
762 wstr[1] = L'\0';
763 }
764 } else {
765 wstr[0] = L' ';
766 wstr[1] = L'\0';
767 }
768 setcchar(&cc, wstr, attr, cp, nullptr);
769 return cc;
770}

Referenced by init_form(), initialize_local_colors(), and ui_style_to_cch().

Here is the caller graph for this function:

◆ rgb_to_curses_clr()

int rgb_to_curses_clr ( RGB * rgb)

Get color index for RGB color.

rgb_to_curses_clr

Parameters
rgbRGB color
Returns
NCurses color index

Curses uses 0-1000 for RGB values. If the color does not exist, it is created along with a new color index

Definition at line 432 of file dwin.c.

432 {
433 int i;
434 int r, g, b;
435 apply_gamma(rgb);
436 rgb->r = (rgb->r * 1000) / 255;
437 rgb->g = (rgb->g * 1000) / 255;
438 rgb->b = (rgb->b * 1000) / 255;
439 for (i = 0; i < clr_cnt; i++) {
440 extended_color_content(i, &r, &g, &b);
441 if (rgb->r == r && rgb->g == g && rgb->b == b) {
442 return i;
443 }
444 }
445 if (i < COLORS) {
446 init_extended_color(i, rgb->r, rgb->g, rgb->b);
447 clr_cnt++;
448 return clr_cnt - 1;
449 }
450 return ERR;
451}

References apply_gamma(), RGB::b, clr_cnt, RGB::g, and RGB::r.

Referenced by parse_ansi_str(), and ui_style_to_cch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rgb_to_xterm256_idx()

int rgb_to_xterm256_idx ( RGB * rgb)

Convert RGB color to XTerm 256 color index.

rgb_to_xterm256_idx

Parameters
rgbRGB color
Returns
XTerm 256 color index

This function converts an RGB color to the nearest XTerm 256 color index. It first checks if the color is a shade of gray, and if so, it uses the gray ramp. Otherwise, it calculates the nearest color in the 6x6x6 color cube.

Definition at line 461 of file dwin.c.

461 {
462 if (rgb->r == rgb->g && rgb->g == rgb->b) {
463 if (rgb->r < 8)
464 return 16;
465 if (rgb->r > 248)
466 return 231;
467 return ((rgb->r - 8) / 10) + 231;
468 } else {
469 int r_index = (rgb->r < 45) ? 0 : (rgb->r - 60) / 40 + 1;
470 int g_index = (rgb->g < 45) ? 0 : (rgb->g - 60) / 40 + 1;
471 int b_index = (rgb->b < 45) ? 0 : (rgb->b - 60) / 40 + 1;
472 return 16 + (36 * r_index) + (6 * g_index) + b_index;
473 }
474}

References RGB::b, RGB::g, and RGB::r.

◆ str_to_cc()

size_t str_to_cc ( cchar_t * cmplx_buf,
const char * s,
attr_t attr,
int cp,
size_t maxlen )

Convert a multibyte string to an array of cchar_t complex characters.

str_to_cc

Parameters
cmplx_bufOutput buffer for complex characters
sInput multibyte string
attrAttributes to apply to the complex characters
cpColor pair index for the complex characters
maxlenMaximum length of the output buffer
Returns
Number of complex characters added to the output buffer

This function converts a multibyte string to an array of cchar_t complex characters that can be used with NCurses functions. It handles multibyte characters and applies the specified color pair to each character. The function ensures that it does not exceed the maximum length of the output buffer.

Definition at line 786 of file dwin.c.

786 {
787 int i = 0, j = 0;
788 int len = 0;
789 cchar_t cc = {0};
790 wchar_t wstr[2] = {L'\0', L'\0'};
791 mbstate_t mbstate;
792 memset(&mbstate, 0, sizeof(mbstate));
793 while (s[i] != '\0') {
794 if (s[i] == '\033') {
795 i++;
796 continue;
797 }
798 wstr[1] = L'\0';
799 len = mbrtowc(wstr, &s[i], MB_CUR_MAX, &mbstate);
800 if (len <= 0) {
801 wstr[0] = L'?';
802 wstr[1] = L'\0';
803 len = 1;
804 }
805 if (setcchar(&cc, wstr, attr, cp, nullptr) != ERR) {
806 if (len > 0)
807 if ((j + len) < (int)maxlen + 1)
808 cmplx_buf[j++] = cc;
809 }
810 i += len;
811 }
812 wstr[0] = '\0';
813 wstr[1] = '\0';
814 setcchar(&cc, wstr, WA_NORMAL, cp, nullptr);
815 cmplx_buf[j++] = cc;
816 return j;
817}

Referenced by form_display_field(), and form_display_fields().

Here is the caller graph for this function:

◆ xterm256_idx_to_rgb()

RGB xterm256_idx_to_rgb ( int idx)

Convert XTerm 256 color index to RGB.

xterm256_idx_to_rgb

Parameters
idxXTerm 256 color index
Returns
RGB color

This function converts an XTerm 256 color index to an RGB color. It first checks if the index is in the standard 16 colors, then checks if it's in the 6x6x6 color cube, and finally checks if it's in the gray ramp.

Convert XTerm 256 color index to RGB

Parameters
idx- XTerm 256 color index
Returns
RGB struct

Definition at line 483 of file dwin.c.

483 {
487 RGB rgb;
488 if (idx > 255)
489 idx = 255;
490 if (idx < 0)
491 idx = 0;
492 rgb.r = rgb.g = rgb.b = 0;
493 if (idx < 16) {
494 rgb.r = StdColors[idx].r;
495 rgb.g = StdColors[idx].g;
496 rgb.b = StdColors[idx].b;
497 } else if (idx >= 16 && idx <= 231) {
498 idx -= 16;
499 rgb.r = (idx / 36) % 6 * 51;
500 rgb.g = (idx / 6) % 6 * 51;
501 rgb.b = (idx % 6) * 51;
502 } else if (idx >= 232 && idx <= 255) {
503 int gray = (idx - 232) * 11;
504 rgb.r = rgb.g = rgb.b = gray;
505 }
506 return rgb;
507}

References RGB::b, RGB::g, RGB::r, and StdColors.

Referenced by parse_ansi_str().

Here is the caller graph for this function: