C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
ui_common.c File Reference
#include "cm.h"
#include "ui_backend.h"
#include <fcntl.h>
#include <iso646.h>
#include <math.h>
#include <poll.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <wchar.h>
Include dependency graph for ui_common.c:

Go to the source code of this file.

Macros

#define AS_STRING(NAME)

Functions

void ui_abend (int ec, char *s)
 Convert multibyte string to complex character array.
bool ui_action_disposition (char *title, char *action_str)
 Display a simple action disposition message window or print to stderr.
void ui_activate_all_chyron_keys (UiChyron *chyron)
 Deactivate chyron key.
void ui_activate_chyron_key (UiChyron *chyron, uint k)
 Activate chyron key.
int ui_answer_yn (char *msg0, char *msg1, char *msg2, char *msg3)
 Accept a single letter answer.
void ui_apply_gamma (RGB *rgb)
 Apply gamma correction to RGB color.
int ui_assign_chyron_win (UiChyron *chyron, UiSurface *sfc, ss_t w, char *y)
 Assign surface and window to chyron structure.
int ui_border_draw (UiSurface *sfc, ss_t w)
int ui_border_title (UiSurface *sfc, ss_t w, const char *title)
 Draw a box with a title around the specified window.
int ui_border_ysplit (UiSurface *sfc, ss_t w, uint y)
 Draw a box with a separator line around the specified window.
int ui_border_ysplit_text (UiSurface *sfc, char *text_in, uint separator_line)
 Draw a box with a separator line and text around the specified window.
int ui_cm_surface_destroy (UiSurface *sfc)
 Destroy the most recently created surface.
void ui_compile_chyron (UiChyron *chyron)
 construct the chyron string from the chyron structure
void ui_deactivate_all_chyron_keys (UiChyron *chyron)
 Deactivate all chyron keys.
void ui_deactivate_chyron_key (UiChyron *chyron, uint k)
 Deactivate chyron key.
UiChyron * ui_destroy_chyron (UiChyron *chyron)
 Destroy UiChyron structure.
void ui_display_chyron (UiSurface *sfc, ss_t w, UiChyron *chyron, uint line, uint col)
 Display chyron on the specified line and column of the surface.
int ui_display_error (char *msg0, char *msg1, char *msg2, char *msg3)
 Display an error message window or print to stderr.
int ui_get_chyron_key (UiChyron *chyron, uint x)
 Get keycode from chyron.
bool ui_init_clr_palette (SIO *sio)
void ui_initialize_sio (SIO *sio)
bool ui_is_set_chyron_key (UiChyron *chyron, uint k)
 Check if function key label is set.
char * ui_iso8601_timestamp (char *buf, size_t n, bool local)
 Generate an ISO 8601 timestamp string.
void ui_log_write (const UiLogLevel level, const char *file, const char *func, const int line, const char *fmt,...)
void ui_mbc_to_wc (wchar_t wc[2], const char mbc)
 Convert a multibyte character to a wide character.
wchar_t * ui_mbstr_to_wcstr (const char *mb_str)
 Convert a multibyte string to a wide character string.
UiChyron * ui_new_chyron (UiSurface *sfc, ss_t w)
 Create new chyron structure.
int ui_open_log ()
 Open the log file for writing.
void ui_parse_ansi (char *ansi_str, attr_t *attrs, uint *cpx)
 Parse ANSI escape sequences for color and attributes.
int ui_perror (char *emsg_str)
 Display a simple error message window or print to stderr.
int ui_poll_reg_read_fd (int timeout_ms)
 Poll for input on registered external files.
void ui_register_read_fd (int fd, int token_id)
 Register an external file descriptor for polling.
uint ui_rgb_to_xterm256_idx (RGB *rgb)
 Convert RGB color to XTerm 256 color index.
void ui_set_chyron_key (UiChyron *chyron, uint k, char *s, uint kc)
 Set chyron key with default color pair (cp_nt_rev).
void ui_set_chyron_key_cb (UiChyron *chyron, uint k, char *s, uint kc, UiCell cell_base)
 Set chyron key with color pair (cp).
const char * ui_sub_surface_str (ss_t w)
int ui_timeout_prompt (char *msg0, char *msg1, uint timeout_ms, uint timeout_secs)
 Display a timeout prompt window or print to stderr.
int ui_tracked_sfc_box (uint wlines, uint wcols, uint wbegy, uint wbegx, const char *wtitle)
 Create a new surface with a box window.
int ui_tracked_sfc_split_box (uint wlines, uint wcols, uint split_y, uint split_x, uint wbegy, uint wbegx, const char *wtitle)
 Create a new surface with a split box window.
void ui_unregister_read_fd (int fd)
 Unregister an external file descriptor from polling.
void ui_unset_chyron_key (UiChyron *chyron, uint k)
 Unset chyron key.
int ui_update_timeout_prompt (UiSurface *sfc, ss_t w, uint timeout_ms)
 Update the timeout prompt with the remaining time.
RGB ui_xterm256_idx_to_rgb (uint idx)
 Convert XTerm 256 color index to RGB.

Variables

double BLUE_GAMMA = 1.2
const wchar_t * border_double = L"═║╠╣╦╩╬╔╗╚╝"
const wchar_t * border_heavy = L"━┃┣┫┳┻╋┏┓┗┛"
const wchar_t * border_none = L" "
const wchar_t * border_rounded = L"─│├┤┬┴┼╭╮╰╯"
const wchar_t * border_single = L"─│├┤┬┴┼┌┐└┘"
uint16_t box_attr
BorderWide bw
const wchar_t * bw_chk = L"\u2611"
const wchar_t * bw_da = L"\u2193"
const wchar_t * bw_h09 = L"\u23BD"
const wchar_t * bw_la = L"\u2190"
const wchar_t * bw_lan = L"\u276E"
const wchar_t * bw_ra = L"\u2192"
const wchar_t * bw_ran = L"\u276F"
const wchar_t * bw_rbl = L"\u2570"
const wchar_t * bw_rbr = L"\u256f"
const wchar_t * bw_rtl = L"\u256d"
const wchar_t * bw_rtr = L"\u256e"
const wchar_t * bw_sp = L"\x20"
const wchar_t * bw_ua = L"\u2191"
UiCell cell_bl
UiCell cell_black_bg
UiCell cell_blue_bg
UiCell cell_box
UiCell cell_br
UiCell cell_brktl
UiCell cell_brktr
UiCell cell_bs
UiCell cell_bt
UiCell cell_chk
UiCell cell_cmdln
UiCell cell_cr
UiCell cell_cyan_bg
UiCell cell_default
UiCell cell_fill_char
UiCell cell_green_bg
UiCell cell_ho
UiCell cell_ind
UiCell cell_ln
UiCell cell_ls
UiCell cell_lt
UiCell cell_magenta_bg
UiCell cell_nt
UiCell cell_nt_hl
UiCell cell_nt_hl_rev
UiCell cell_nt_rev
UiCell cell_ran
UiCell cell_red_bg
UiCell cell_rs
UiCell cell_rt
UiCell cell_sp
UiCell cell_title
UiCell cell_tl
UiCell cell_tr
UiCell cell_ts
UiCell cell_tt
UiCell cell_ve
UiCell cell_white_bg
UiCell cell_yellow_bg
int click_x
int click_y
unsigned int cmd_key
char const colors_text [][10]
 Color names for .minitrc overrides.
ushort cp_black
ushort cp_blue
ushort cp_box
ushort cp_brackets
ushort cp_cmdln
ushort cp_cyan
ushort cp_default
ushort cp_fill_char
ushort cp_green
ushort cp_ind
ushort cp_ln
ushort cp_magenta
ushort cp_nt
ushort cp_nt_hl
ushort cp_nt_hl_rev
ushort cp_nt_rev
ushort cp_red
ushort cp_title
ushort cp_white
ushort cp_yellow
char em0 [MAXLEN]
char em1 [MAXLEN]
char em2 [MAXLEN]
char em3 [MAXLEN]
int exit_code
bool f_ncurses_open = false
bool f_notcurses_open = false
bool f_sigwench = false
char fn [MAXLEN]
double GRAY_GAMMA = 1.2
double GREEN_GAMMA = 1.2
uint m_begx = -1
uint m_begy = -1
uint m_cols
uint m_lines
uint mouse_support
int pipe_in
int pipe_out
double RED_GAMMA = 1.2
uint src_line
char * src_name
STDRGB std_color []
int stderr_fd
int stdin_fd
int stdout_fd
const char * subsfc_s []
int tty_fd
ui_context_t ui_ctx
UiLogContext ui_log_ctx
uint16_t win_attr

Macro Definition Documentation

◆ AS_STRING

#define AS_STRING ( NAME)
Value:
#NAME,

Definition at line 1433 of file ui_common.c.

Function Documentation

◆ ui_abend()

void ui_abend ( int ec,
char * s )

Convert multibyte string to complex character array.

ui_mbstr_to_cellstr

Parameters
cmplx_bufOutput buffer for complex characters
strInput multibyte string
cell_baseBase cell for attributes and color pair
pPointer to current position in the output buffer, updated as characters are added
atmostMaximum length of the output buffer
Returns
Number of bytes processed from the input string

This function converts a multibyte string to an array of complex characters (cchar_t) that can be used with NCurses functions. It handles multibyte characters and applies the attributes and color pair from the base cell to each character. The p parameter is updated to reflect the current position in the output buffer, and the function ensures that it does not exceed the maximum length specified by atmost. ui_abend

Handle abnormal termination of the program

Parameters
ecExit code to return to the operating system
sMessage describing the reason for termination

This function is called when the program encounters a critical error that requires it to terminate. It performs necessary cleanup, restores terminal settings, and outputs an error message to stderr before exiting with the specified exit code.

Definition at line 404 of file ui_common.c.

404 {
405 ui_shutdown();
407 sig_dfl_mode();
408 fprintf(stderr, _("\n\nABEND: %s (code: %d)\n"), s, ec);
409 exit(EXIT_FAILURE);
410}
void ui_shutdown()
Shutdown the UI runtime, cleaning up resources and freeing memory.
Definition ui_ncurses.c:449
#define _(String)
Definition amort.c:23
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:57
void sig_dfl_mode()
Set signal handlers to default behavior.
Definition sig.c:41

References restore_shell_tioctl(), sig_dfl_mode(), and ui_shutdown().

Referenced by form_parse_desc(), init_menu_files(), init_pick(), mapp_initialization(), new_form(), new_init(), new_menu(), new_pick(), new_view(), parse_menu_description(), sig_prog_mode(), signal_handler(), ui_answer_yn(), ui_display_error(), ui_new_chyron(), ui_timeout_prompt(), and view_init_input().

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

◆ ui_activate_all_chyron_keys()

void ui_activate_all_chyron_keys ( UiChyron * chyron)

Deactivate chyron key.

deactivate_chyron_key

Parameters
chyronstructure
kchyron_key index

Definition at line 811 of file ui_common.c.

811 {
812 for (int k = 0; k < CHYRON_KEYS; k++)
813 chyron->key[k]->active = true;
814}
#define CHYRON_KEYS
Definition ui_backend.h:92

◆ ui_activate_chyron_key()

void ui_activate_chyron_key ( UiChyron * chyron,
uint k )

Activate chyron key.

activate_chyron_key

Parameters
chyronstructure
kchyron_key index

Definition at line 802 of file ui_common.c.

802 {
803 chyron->key[k]->active = true;
804}

◆ ui_apply_gamma()

void ui_apply_gamma ( RGB * rgb)

Apply gamma correction to RGB color.

ui_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 1002 of file ui_common.c.

1002 {
1003 if (rgb->r == rgb->g && rgb->r == rgb->b) {
1004 if (GRAY_GAMMA > 0.0f && GRAY_GAMMA != 1.0f) {
1005 rgb->r = (int)(pow((rgb->r / 255.0f), 1.0f / GRAY_GAMMA) * 255.0f);
1006 rgb->g = rgb->r;
1007 rgb->b = rgb->r;
1008 }
1009 return;
1010 }
1011 if (rgb->r != 0 && RED_GAMMA > 0.0f && RED_GAMMA != 1.0f)
1012 rgb->r = (int)(pow((rgb->r / 255.0f), 1.0f / RED_GAMMA) * 255.0f);
1013 if (rgb->g != 0 && GREEN_GAMMA > 0.0f && GREEN_GAMMA != 1.0f)
1014 rgb->g = (int)(pow((rgb->g / 255.0f), 1.0f / GREEN_GAMMA) * 255.0f);
1015 if (rgb->b != 0 && BLUE_GAMMA > 0.0f && BLUE_GAMMA != 1.0f)
1016 rgb->b = (int)(pow((rgb->b / 255.0f), 1.0f / BLUE_GAMMA) * 255.0f);
1017}
double BLUE_GAMMA
Definition ui_common.c:82
double GRAY_GAMMA
Definition ui_common.c:79
double RED_GAMMA
Definition ui_common.c:80
double GREEN_GAMMA
Definition ui_common.c:81
uint8_t b
Definition ui_backend.h:349
uint8_t r
Definition ui_backend.h:349
uint8_t g
Definition ui_backend.h:349

References BLUE_GAMMA, GRAY_GAMMA, GREEN_GAMMA, and RED_GAMMA.

Referenced by ui_chg_color(), ui_color_from_rgb(), and ui_init_color_hex().

Here is the caller graph for this function:

◆ ui_assign_chyron_win()

int ui_assign_chyron_win ( UiChyron * chyron,
UiSurface * sfc,
ss_t w,
char * y )

Assign surface and window to chyron structure.

assign_chyron_win

Parameters
chyronpointer to UiChyron structure
sfcpointer to UiSurface structure
winwindow index (WIN or BOX)
yline number for chyron display
Returns
0 on success, -1 on error

This function assigns the specified surface and window to the chyron structure. It also sets the line number for displaying the chyron. If the input string y is "-", it sets the line number to the last line of the surface. Otherwise, it converts the string y to an integer and sets it as the line number, ensuring it does not exceed the maximum line number of the surface.

Note
Drop-down menus from the chyron will be added in the future

Definition at line 695 of file ui_common.c.

695 {
696 bool a_toi_error = false;
697 if (!sfc)
698 return -1;
699 chyron->sfc = sfc;
700 chyron->w = w;
701 if (*y == '-')
702 chyron->y = ui_getmaxy(sfc, w) - 1;
703 else {
704 chyron->y = a_toi(y, &a_toi_error);
705 if (a_toi_error)
706 return -1;
707 chyron->y = min(chyron->y, ui_getmaxy(sfc, w) - 1);
708 }
709 return 0;
710}
int ui_getmaxy(UiSurface *s, ss_t w)
Get the maximum number of lines (rows) of a UiSurface.
Definition ui_ncurses.c:733
#define min(x, y)
Definition lf.h:158
int a_toi(char *, bool *)
a safer alternative to atoi() for converting ASCII strings to integers.
Definition futil.c:806

References a_toi(), and ui_getmaxy().

Here is the call graph for this function:

◆ ui_border_draw()

int ui_border_draw ( UiSurface * sfc,
ss_t w )

Definition at line 523 of file ui_common.c.

523 {
524 uint maxy = ui_getmaxy(sfc, w);
525 uint maxx = ui_getmaxx(sfc, w);
526 uint y = 0;
527 uint x = 0;
528 ui_mvwadd_wchnstr(sfc, w, y, x++, &cell_tl, 1);
529 for (x = 1; x < maxx - 1; x++)
530 ui_mvwadd_wchnstr(sfc, w, y, x, &cell_ho, 1);
531 ui_mvwadd_wchnstr(sfc, w, y, maxx - 1, &cell_tr, 1);
532 for (y = 1; y < maxy - 1; y++) {
533 ui_mvwadd_wchnstr(sfc, w, y, 0, &cell_ve, 1);
534 ui_mvwadd_wchnstr(sfc, w, y, maxx - 1, &cell_ve, 1);
535 }
536 ui_mvwadd_wchnstr(sfc, w, y, 0, &cell_bl, 1);
537 for (x = 1; x < maxx - 1; x++)
538 ui_mvwadd_wchnstr(sfc, w, y, x, &cell_ho, 1);
539 ui_mvwadd_wchnstr(sfc, w, y, maxx - 1, &cell_br, 1);
540#ifdef DEBUG_IMMED_UI
541 ui_render();
542#endif
543 return 0;
544}
void ui_render()
Render the UI by updating panels and refreshing the display.
Definition ui_ncurses.c:931
int ui_getmaxx(UiSurface *s, ss_t w)
Get the maximum number of columns of a UiSurface.
Definition ui_ncurses.c:744
UiCell cell_ve
Definition ui_common.c:141
UiCell cell_tr
Definition ui_common.c:139
UiCell cell_br
Definition ui_common.c:143
UiCell cell_tl
Definition ui_common.c:138
UiCell cell_ho
Definition ui_common.c:140
UiCell cell_bl
Definition ui_common.c:142
int ui_mvwadd_wchnstr(UiSurface *s, ss_t w, uint y, uint x, const UiCell *cmplx_buf, uint n)
Draw a complex character string at a specific position in a surface window, with a maximum length.

References cell_bl, cell_br, cell_ho, cell_tl, cell_tr, cell_ve, ui_getmaxx(), ui_getmaxy(), and ui_mvwadd_wchnstr().

Referenced by ui_surface_box(), and ui_surface_box().

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

◆ ui_border_title()

int ui_border_title ( UiSurface * sfc,
ss_t w,
const char * title )

Draw a box with a title around the specified window.

border_title

Parameters
boxPointer to the window to draw the box around
titleTitle text to display at the top of the box

This function draws a box around the specified window, similar to border_draw(), but it also includes a title at the top of the box. The title is displayed in the center of the top edge of the box, and the horizontal line is drawn on either side of the title. Use this function when you want to visually label a window with a title.

Definition at line 621 of file ui_common.c.

621 {
622 if (!title || !*title)
623 return 0;
624 uint y = 0;
625 uint x = 0;
626 uint l;
627 uint maxx = ui_getmaxx(sfc, w);
628 ui_mvwadd_wchnstr(sfc, w, y, x++, &cell_tl, 1);
629 ui_mvwadd_wchnstr(sfc, w, y, x++, &cell_rt, 1);
630 ui_mvwadd_wchnstr(sfc, w, y, x++, &cell_sp, 1);
631 wchar_t *title_wc;
632 title_wc = ui_mbstr_to_wcstr(title);
633 l = wcswidth(title_wc, wcslen(title_wc));
634 l = min(l, maxx - 7);
635 ui_bkgdset(sfc, w, &cell_title);
636 ui_mvwaddnwstr(sfc, w, y, x, title_wc, l);
637 ui_bkgdset(sfc, w, &cell_box);
638 x += l;
639 free(title_wc);
640 ui_mvwadd_wchnstr(sfc, w, y, x++, &cell_sp, 1);
641 ui_mvwadd_wchnstr(sfc, w, y, x++, &cell_lt, 1);
642 while (x < maxx - 1) {
643 ui_mvwadd_wchnstr(sfc, w, y, x++, &cell_ho, 1);
644 }
645#ifdef DEBUG_IMMED_UI
646 ui_render();
647#endif
648 return 0;
649}
int ui_bkgdset(UiSurface *s, ss_t w, const UiCell *cell)
Set the background for new content to be written to a specific window within a UiSurface.
Definition ui_ncurses.c:988
UiCell cell_sp
Definition ui_common.c:149
wchar_t * ui_mbstr_to_wcstr(const char *mb_str)
Convert a multibyte string to a wide character string.
Definition ui_common.c:364
UiCell cell_lt
Definition ui_common.c:144
UiCell cell_title
Definition ui_common.c:130
UiCell cell_box
Definition ui_common.c:127
UiCell cell_rt
Definition ui_common.c:145
int ui_mvwaddnwstr(UiSurface *s, ss_t w, uint y, uint x, const wchar_t *wstr, int m)
Draw a wide-character string at a specific position in a surface window, with a maximum length.

References cell_box, cell_ho, cell_lt, cell_rt, cell_sp, cell_title, cell_tl, ui_bkgdset(), ui_getmaxx(), ui_mbstr_to_wcstr(), ui_mvwadd_wchnstr(), and ui_mvwaddnwstr().

Referenced by new_view_file(), ui_surface_box(), ui_surface_box(), view_boxwin_resize(), and view_file().

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

◆ ui_border_ysplit()

int ui_border_ysplit ( UiSurface * sfc,
ss_t w,
uint y )

Draw a box with a separator line around the specified window.

ui_border-ysplit

Parameters
boxPointer to the window to draw the box around
yLine number where the separator line should be drawn

This function draws a box around the specified window, similar to border_draw(), but it also includes a horizontal separator line that divides the box into two sections. The separator line is drawn at a fixed position (line 00, page 00) and extends across the width of the box. Use this function when you want to visually separate two sections within a window, such as for a header and content area.

Definition at line 556 of file ui_common.c.

556 {
557 uint maxx = ui_getmaxx(sfc, w);
558 ui_mvwadd_wchnstr(sfc, w, y, 0, &cell_lt, 1);
559 for (uint x = 1; x < maxx - 1; x++)
560 ui_mvwadd_wchnstr(sfc, w, y, x, &cell_ho, 1);
561 ui_mvwadd_wchnstr(sfc, w, y, maxx - 1, &cell_rt, 1);
562#ifdef DEBUG_IMMED_UI
563 ui_render();
564#endif
565 return 0;
566}

References cell_ho, cell_lt, cell_rt, ui_getmaxx(), and ui_mvwadd_wchnstr().

Referenced by ui_tracked_sfc_split_box().

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

◆ ui_border_ysplit_text()

int ui_border_ysplit_text ( UiSurface * sfc,
char * text_in,
uint separator_line )

Draw a box with a separator line and text around the specified window.

ui_border_ysplit_text

Parameters
boxPointer to the window to draw the box around
textText to display in the middle of the separator line
separator_lineLine number where the separator line should be drawn

This function draws a box around the specified window, similar to border_draw(), but it also includes a horizontal separator line that divides the box into two sections. The separator line is drawn at the specified line number and extends across the width of the box, with the provided text displayed in the middle of the line. Use this function when you want to visually separate two sections within a window and label the separator with descriptive text.

Definition at line 579 of file ui_common.c.

579 {
580 char text[MAXLEN];
581 uint maxx = ui_getmaxx(sfc, BOX);
582 uint l;
583 uint y = separator_line;
584 uint x = 0;
585 // Draw the horizontal line with text in the middle, so we start by drawing
586 // the left edge, then the text, then the right edge, and finally fill in the
587 // horizontal line on either side of the text.
588 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_lt, 1);
589 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_ho, 1);
590 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_rt, 1);
591 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_sp, 1);
592 strnz__cpy(text, text_in, maxx - 7);
593 wchar_t *text_wc;
594 text_wc = ui_mbstr_to_wcstr(text);
595 l = wcswidth(text_wc, wcslen(text_wc));
596 ui_bkgdset(sfc, BOX, &cell_nt_hl);
597 ui_mvwaddnwstr(sfc, BOX, y, x, text_wc, l);
598 x += l;
599 l = min(l, maxx - 7);
600 free(text_wc);
601 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_sp, 1);
602 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_lt, 1);
603 while (x < maxx - 1)
604 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_ho, 1);
605 ui_mvwadd_wchnstr(sfc, BOX, y, x++, &cell_rt, 1);
606#ifdef DEBUG_IMMED_UI
607 ui_render();
608#endif
609 return 0;
610}
UiCell cell_nt_hl
Definition ui_common.c:125
#define MAXLEN
Definition lf.h:38
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition lf.c:2299

References cell_ho, cell_lt, cell_nt_hl, cell_rt, cell_sp, strnz__cpy(), ui_bkgdset(), ui_getmaxx(), ui_mbstr_to_wcstr(), ui_mvwadd_wchnstr(), and ui_mvwaddnwstr().

Referenced by picker().

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

◆ ui_cm_surface_destroy()

int ui_cm_surface_destroy ( UiSurface * sfc)

Destroy the most recently created surface.

ui_cm_destroy_surface

Returns
0 on success, -1 if no surfaces exist

This function destroys the most recently created surface and decrements the surface pointer. It should be called when a surface is no longer needed to free up resources. If there are no surfaces to destroy, it returns -1.

Note
The difference between this function and ui_surface_destroy() is that this function destroys the surface pointed to by the surface pointer (sfc_ptr) and decrements the surface pointer after destroying the surface.

Definition at line 515 of file ui_common.c.

515 {
517 sfc_ptr--;
518 return 0;
519}
void ui_surface_destroy(UiSurface *s)
Destroy a UiSurface, cleaning up its windows and panels.
Definition ui_ncurses.c:499
int sfc_ptr
Definition ui_ncurses.c:42

References sfc_ptr, and ui_surface_destroy().

Referenced by init_form(), init_pick(), menu_engine(), ui_action_disposition(), ui_answer_yn(), ui_display_error(), ui_perror(), and ui_timeout_prompt().

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

◆ ui_compile_chyron()

void ui_compile_chyron ( UiChyron * chyron)

construct the chyron string from the chyron structure

compile_chyron

Parameters
chyron

The chyron string is constructed by concatenating the labels of the set keys, separated by _(" | "). The end_pos values for each key are set to determine the zones for mouse clicks. When a mouse click occurs, the get_chyron_key function uses the end_pos values to determine which key was clicked based on the X position of the click.

Definition at line 843 of file ui_common.c.

843 {
844 uint end_pos = 0;
845 uint k = 0;
846 uint pos = 0;
847 UiCell cell_base = cell_nt_rev;
848 UiCell *cx;
849 char tmp_str[MAXLEN];
850 while (k < CHYRON_KEYS) {
851 if (chyron->key[k]->text[0] == '\0' || !chyron->key[k]->active) {
852 k++;
853 continue;
854 }
855 cell_base = chyron->key[k]->cell_base;
856 if (end_pos == 0) {
857 cx = chyron->cmplx_buf;
858 ui_mbstr_to_cellstr(chyron->sfc, chyron->w,
859 cx,
860 " ",
861 &cell_base,
862 &pos,
863 MAXLEN - 1);
864 } else {
865 ui_mbstr_to_cellstr(chyron->sfc, chyron->w,
866 chyron->cmplx_buf,
867 "|",
868 &cell_base,
869 &pos,
870 MAXLEN - 1);
871 }
872 cx = chyron->cmplx_buf;
873 ui_mbstr_to_cellstr(chyron->sfc, chyron->w, cx, chyron->key[k]->text, &cell_base, &pos, MAXLEN - 1);
874 end_pos = pos;
875 chyron->l = end_pos;
876 chyron->key[k]->end_pos = end_pos;
877 ssnprintf(tmp_str, MAXLEN - 1, _("k=%d, text=%s, end_pos=%d"), k,
878 chyron->key[k]->text, chyron->key[k]->end_pos);
879 k++;
880 }
881 ui_mbstr_to_cellstr(chyron->sfc, chyron->w, chyron->cmplx_buf, " ", &cell_base, &pos, MAXLEN - 1);
882 chyron->l = end_pos;
883}
uint ui_mbstr_to_cellstr(UiSurface *sfc, ss_t w, UiCell *cmplx_buf, const char *str, const UiCell *cell_base, uint *p, const uint atmost)
Convert multibyte string to complex character array (Notcurses version).
UiCell cell_nt_rev
Definition ui_common.c:124
size_t ssnprintf(char *, size_t, const char *,...)
Custom safe string formatting utility (Variadic version).
Definition futil.c:398

References cell_nt_rev, and ssnprintf().

Referenced by field_editor(), form_engine(), form_post(), form_process(), open_pick_win(), picker(), ui_action_disposition(), ui_answer_yn(), ui_display_error(), ui_perror(), and ui_timeout_prompt().

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

◆ ui_deactivate_all_chyron_keys()

void ui_deactivate_all_chyron_keys ( UiChyron * chyron)

Deactivate all chyron keys.

deactivate_all_chyron_keys

Parameters
chyronstructure

Definition at line 829 of file ui_common.c.

829 {
830 for (int k = 0; k < CHYRON_KEYS; k++)
831 chyron->key[k]->active = false;
832}

◆ ui_deactivate_chyron_key()

void ui_deactivate_chyron_key ( UiChyron * chyron,
uint k )

Deactivate chyron key.

deactivate_chyron_key

Parameters
chyronstructure
kchyron_key index

Definition at line 821 of file ui_common.c.

821 {
822 chyron->key[k]->active = false;
823}

◆ ui_destroy_chyron()

UiChyron * ui_destroy_chyron ( UiChyron * chyron)

Destroy UiChyron structure.

destroy_chyron

Parameters
chyronpointer to UiChyron structure
Returns
nullptr

Definition at line 717 of file ui_common.c.

717 {
718 uint i;
719
720 if (!chyron)
721 return nullptr;
722 for (i = 0; i < CHYRON_KEYS; i++) {
723 if (chyron->key[i]) {
724 free(chyron->key[i]);
725 chyron->key[i] = nullptr;
726 }
727 }
728 free(chyron);
729 chyron = nullptr;
730 return chyron;
731}

Referenced by init_form(), pick_engine(), ui_action_disposition(), ui_answer_yn(), ui_display_error(), ui_perror(), and ui_timeout_prompt().

Here is the caller graph for this function:

◆ ui_display_chyron()

void ui_display_chyron ( UiSurface * sfc,
ss_t w,
UiChyron * chyron,
uint line,
uint col )

Display chyron on the specified line and column of the surface.

display_chyron

Parameters
sfcPointer to the UiSurface structure
wWindow index (WIN or BOX)
chyronPointer to the UiChyron structure
lineLine number where the chyron should be displayed
colColumn number where the chyron should start

This function displays the compiled chyron string on the specified line and column of the given surface. It first moves the cursor to the specified position, clears to the end of the line, and then writes the chyron string. Finally, it moves the cursor back to the specified column for user input.

Definition at line 898 of file ui_common.c.

898 {
899 chyron->y = line;
900 ui_wmove(sfc, w, line, 0);
901 ui_wclrtoeol(sfc, w);
902 ui_wmove(sfc, w, line, 0);
903 ui_mvwadd_wchstr(sfc, w, line, 0, chyron->cmplx_buf);
904 ui_wmove(sfc, w, line, col);
905 return;
906}
int ui_wmove(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
Definition ui_ncurses.c:685
int ui_wclrtoeol(UiSurface *s, ss_t w)
Clear to the end of the line in a surface window.
int ui_mvwadd_wchstr(UiSurface *s, ss_t w, uint y, uint x, const UiCell *cmplx_buf)
Draw a complex character string at a specific position in a surface window.

References ui_mvwadd_wchstr(), ui_wclrtoeol(), and ui_wmove().

Referenced by field_editor(), form_engine(), form_post(), form_process(), picker(), ui_action_disposition(), ui_answer_yn(), ui_display_error(), ui_perror(), and ui_timeout_prompt().

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

◆ ui_get_chyron_key()

int ui_get_chyron_key ( UiChyron * chyron,
uint x )

Get keycode from chyron.

get_chyron_key

Parameters
chyronstructure
xMouse X position
Returns
Keycode

This function uses the end_pos values set in compile_chyron to determine which key was clicked. The chyron functions provide xwgetch() with a mechanism to translate mouse click positions into key codes based on the labels set in the chyron structure. When a mouse click occurs, xwgetch() can call get_chyron_key() with the X position of the click to determine which function key was clicked, allowing for dynamic and customizable function key behavior in the chyron area of the interface.

Definition at line 922 of file ui_common.c.

922 {
923 uint i = 0;
924 uint k = -1;
925 while (i < CHYRON_KEYS - 1) {
926 if (chyron->key[i]->text[0] != '\0' && chyron->key[i]->active)
927 if (chyron->key[i]->end_pos >= x) {
928 k = i;
929 break;
930 }
931 i++;
932 }
933 return chyron->key[k]->keycode;
934}

Referenced by field_editor(), form_post(), form_process(), picker(), and ui_get_event().

Here is the caller graph for this function:

◆ ui_init_clr_palette()

bool ui_init_clr_palette ( SIO * sio)

Definition at line 289 of file ui_common.c.

289 {
291 ui_chg_color(CLR_RED, &sio->red);
294 ui_chg_color(CLR_BLUE, &sio->blue);
296 ui_chg_color(CLR_CYAN, &sio->cyan);
299 ui_chg_color(CLR_BRED, &sio->bred);
307 ui_chg_color(CLR_FG, &sio->fg);
308 ui_chg_color(CLR_BG, &sio->bg);
329 return true;
330}
@ CLR_FILL_CHAR_BG
Definition ui_backend.h:578
@ CLR_BOX_BG
Definition ui_backend.h:572
@ CLR_FILL_CHAR_FG
Definition ui_backend.h:577
@ CLR_FG
Definition ui_backend.h:569
@ CLR_RED
Definition ui_backend.h:553
@ CLR_NT_FG
Definition ui_backend.h:583
@ CLR_BRACKETS_FG
Definition ui_backend.h:575
@ CLR_YELLOW
Definition ui_backend.h:555
@ CLR_IND_FG
Definition ui_backend.h:573
@ CLR_BCYAN
Definition ui_backend.h:566
@ CLR_WHITE
Definition ui_backend.h:559
@ CLR_MAGENTA
Definition ui_backend.h:557
@ CLR_BRACKETS_BG
Definition ui_backend.h:576
@ CLR_NT_REV_BG
Definition ui_backend.h:586
@ CLR_BLACK
Definition ui_backend.h:552
@ CLR_BWHITE
Definition ui_backend.h:567
@ CLR_LN_BG
Definition ui_backend.h:580
@ CLR_NT_HL_REV_BG
Definition ui_backend.h:590
@ CLR_BBLACK
Definition ui_backend.h:560
@ CLR_LN_FG
Definition ui_backend.h:579
@ CLR_NT_HL_FG
Definition ui_backend.h:587
@ CLR_BBLUE
Definition ui_backend.h:564
@ CLR_BGREEN
Definition ui_backend.h:562
@ CLR_BYELLOW
Definition ui_backend.h:563
@ CLR_BMAGENTA
Definition ui_backend.h:565
@ CLR_BORANGE
Definition ui_backend.h:568
@ CLR_NT_HL_BG
Definition ui_backend.h:588
@ CLR_NT_HL_REV_FG
Definition ui_backend.h:589
@ CLR_BG
Definition ui_backend.h:570
@ CLR_BOX_FG
Definition ui_backend.h:571
@ CLR_NT_BG
Definition ui_backend.h:584
@ CLR_TITLE_BG
Definition ui_backend.h:592
@ CLR_BRED
Definition ui_backend.h:561
@ CLR_NCOLORS
Definition ui_backend.h:593
@ CLR_BLUE
Definition ui_backend.h:556
@ CLR_IND_BG
Definition ui_backend.h:574
@ CLR_GREEN
Definition ui_backend.h:554
@ CLR_NT_REV_FG
Definition ui_backend.h:585
@ CLR_CYAN
Definition ui_backend.h:558
uint ui_color_cnt
Definition ui_ncurses.c:43
int ui_chg_color(uint16_t color_idx, uint32_t *color)
Change the RGB color value for a given color index.
uint32_t ln_bg
Definition ui_backend.h:780
uint32_t magenta
Definition ui_backend.h:755
uint32_t nt_hl_rev_fg
Definition ui_backend.h:789
uint32_t bgreen
Definition ui_backend.h:761
uint32_t green
Definition ui_backend.h:752
uint32_t nt_fg
Definition ui_backend.h:783
uint32_t yellow
Definition ui_backend.h:753
uint32_t fill_char_fg
Definition ui_backend.h:777
uint32_t box_fg
Definition ui_backend.h:771
uint32_t ln_fg
Definition ui_backend.h:779
uint32_t ind_bg
Definition ui_backend.h:774
uint32_t bmagenta
Definition ui_backend.h:764
uint32_t ind_fg
Definition ui_backend.h:773
uint32_t byellow
Definition ui_backend.h:762
uint32_t bblue
Definition ui_backend.h:763
uint32_t borange
Definition ui_backend.h:767
uint32_t title_bg
Definition ui_backend.h:792
uint32_t fg
Definition ui_backend.h:769
uint32_t cyan
Definition ui_backend.h:756
uint32_t bblack
Definition ui_backend.h:759
uint32_t red
Definition ui_backend.h:751
uint32_t nt_hl_rev_bg
Definition ui_backend.h:790
uint32_t bred
Definition ui_backend.h:760
uint32_t fill_char_bg
Definition ui_backend.h:778
uint32_t black
Definition ui_backend.h:750
uint32_t nt_rev_bg
Definition ui_backend.h:786
uint32_t brackets_bg
Definition ui_backend.h:776
uint32_t bcyan
Definition ui_backend.h:765
uint32_t nt_bg
Definition ui_backend.h:784
uint32_t blue
Definition ui_backend.h:754
uint32_t brackets_fg
Definition ui_backend.h:775
uint32_t white
Definition ui_backend.h:757
uint32_t box_bg
Definition ui_backend.h:772
uint32_t nt_hl_fg
Definition ui_backend.h:787
uint32_t bwhite
Definition ui_backend.h:766
uint32_t nt_rev_fg
Definition ui_backend.h:785
uint32_t nt_hl_bg
Definition ui_backend.h:788
uint32_t bg
Definition ui_backend.h:770

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_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_WHITE, CLR_YELLOW, SIO::cyan, SIO::fg, SIO::fill_char_bg, SIO::fill_char_fg, SIO::green, SIO::ind_bg, SIO::ind_fg, 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, ui_chg_color(), ui_color_cnt, SIO::white, and SIO::yellow.

Referenced by ui_initialize_sio().

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

◆ ui_initialize_sio()

void ui_initialize_sio ( SIO * sio)

gamma correction values

These are read from ~/.minitrc

used when initializing colors

Definition at line 211 of file ui_common.c.

211 {
215 ui->sio = sio;
216 RED_GAMMA = sio->red_gamma;
218 BLUE_GAMMA = sio->blue_gamma;
219 GRAY_GAMMA = sio->gray_gamma;
221 //
222 // Initialize Standardized color pairs
223 //
236
245 //
246 // Initialize Standardized UiCells
247 //
250 mbstate_t mbstate;
251 memset(&mbstate, 0, sizeof(mbstate));
252 wchar_t brktl = sio->brackets[0];
253 cell_brktl = ui_cell_from_ucp(&brktl, &sio->brackets_fg, &sio->brackets_bg);
254 wchar_t brktr = sio->brackets[1];
255 cell_brktr = ui_cell_from_ucp(&brktr, &sio->brackets_fg, &sio->brackets_bg);
256 cell_nt = ui_cell_from_ucp(bw_sp, &sio->nt_fg, &sio->nt_bg);
263 cell_sp = ui_cell_from_ucp(bw_sp, &sio->nt_fg, &sio->nt_bg);
264 cell_ln = ui_cell_from_ucp(bw_sp, &sio->ln_fg, &sio->ln_bg);
268 cell_tl = ui_cell_from_ucp(&bw_tl, &sio->box_fg, &sio->box_bg);
269 cell_tr = ui_cell_from_ucp(&bw_tr, &sio->box_fg, &sio->box_bg);
270 cell_bl = ui_cell_from_ucp(&bw_bl, &sio->box_fg, &sio->box_bg);
271 cell_br = ui_cell_from_ucp(&bw_br, &sio->box_fg, &sio->box_bg);
272 cell_ho = ui_cell_from_ucp(&bw_ho, &sio->box_fg, &sio->box_bg);
273 cell_ve = ui_cell_from_ucp(&bw_ve, &sio->box_fg, &sio->box_bg);
274 cell_lt = ui_cell_from_ucp(&bw_lt, &sio->box_fg, &sio->box_bg);
275 cell_rt = ui_cell_from_ucp(&bw_rt, &sio->box_fg, &sio->box_bg);
276 cell_tt = ui_cell_from_ucp(&bw_tt, &sio->box_fg, &sio->box_bg);
277 cell_bt = ui_cell_from_ucp(&bw_bt, &sio->box_fg, &sio->box_bg);
278 cell_cr = ui_cell_from_ucp(&bw_cr, &sio->box_fg, &sio->box_bg);
280 cell_red_bg = ui_cell_from_ucp(bw_sp, &sio->white, &sio->red);
287}
#define bw_ho
Definition ui_backend.h:627
#define bw_tr
Definition ui_backend.h:635
#define bw_lt
Definition ui_backend.h:629
#define bw_br
Definition ui_backend.h:637
#define bw_bl
Definition ui_backend.h:636
@ CLR_CMDLN_BG
Definition ui_backend.h:582
@ CLR_TITLE_FG
Definition ui_backend.h:591
@ CLR_CMDLN_FG
Definition ui_backend.h:581
#define bw_tt
Definition ui_backend.h:631
#define bw_cr
Definition ui_backend.h:633
#define bw_bt
Definition ui_backend.h:632
#define bw_ve
Definition ui_backend.h:628
#define bw_rt
Definition ui_backend.h:630
#define bw_tl
Definition ui_backend.h:634
const wchar_t * bw_sp
Definition ui_common.c:96
UiCell cell_blue_bg
Definition ui_common.c:154
ushort cp_nt
Definition ui_common.c:167
UiCell cell_nt
Definition ui_common.c:123
ushort cp_magenta
Definition ui_common.c:181
const wchar_t * bw_ran
Definition ui_common.c:101
UiCell cell_nt_hl_rev
Definition ui_common.c:126
UiCell cell_cyan_bg
Definition ui_common.c:155
UiCell cell_bt
Definition ui_common.c:147
ushort cp_green
Definition ui_common.c:177
UiCell cell_magenta_bg
Definition ui_common.c:156
ushort cp_red
Definition ui_common.c:176
ushort cp_white
Definition ui_common.c:182
ushort cp_box
Definition ui_common.c:163
ushort cp_blue
Definition ui_common.c:179
UiCell cell_ln
Definition ui_common.c:131
const wchar_t * bw_chk
Definition ui_common.c:103
ushort cp_black
Definition ui_common.c:175
ushort cp_cyan
Definition ui_common.c:180
ushort cp_nt_hl
Definition ui_common.c:169
UiCell cell_yellow_bg
Definition ui_common.c:153
ushort cp_cmdln
Definition ui_common.c:165
ushort cp_fill_char
Definition ui_common.c:173
UiCell cell_tt
Definition ui_common.c:146
ushort cp_brackets
Definition ui_common.c:174
ushort cp_yellow
Definition ui_common.c:178
UiCell cell_red_bg
Definition ui_common.c:151
bool ui_init_clr_palette(SIO *sio)
Definition ui_common.c:289
UiCell cell_default
Definition ui_common.c:119
ushort cp_nt_hl_rev
Definition ui_common.c:170
ushort cp_default
Definition ui_common.c:172
ushort cp_nt_rev
Definition ui_common.c:168
ushort cp_ln
Definition ui_common.c:171
ushort cp_title
Definition ui_common.c:166
UiCell cell_brktl
Definition ui_common.c:121
UiCell cell_cr
Definition ui_common.c:148
UiCell cell_ind
Definition ui_common.c:128
UiCell cell_ran
Definition ui_common.c:132
UiCell cell_black_bg
Definition ui_common.c:150
UiCell cell_white_bg
Definition ui_common.c:157
UiCell cell_cmdln
Definition ui_common.c:129
UiCell cell_brktr
Definition ui_common.c:122
ushort cp_ind
Definition ui_common.c:164
UiCell cell_green_bg
Definition ui_common.c:152
UiCell cell_fill_char
Definition ui_common.c:120
UiCell cell_chk
Definition ui_common.c:133
uint ui_add_pair(uint fg, uint bg)
Add a new color pair to the UI, or retrieve the index of an existing pair.
UiRuntime * ui
Definition ui_ncurses.c:39
UiCell ui_cell_from_ucp(const wchar_t *ucp, const uint32_t *fg, const uint32_t *bg)
Convert a Unicode code point to a curses UiCell with specified foreground and background colors.
Definition ui_ncurses.c:102
uint32_t ran_bg
Definition ui_backend.h:794
double green_gamma
Definition ui_backend.h:747
double blue_gamma
Definition ui_backend.h:748
char brackets[3]
Definition ui_backend.h:807
uint32_t cmdln_bg
Definition ui_backend.h:782
uint32_t cmdln_fg
Definition ui_backend.h:781
uint32_t ran_fg
Definition ui_backend.h:793
double red_gamma
Definition ui_backend.h:746
uint32_t title_fg
Definition ui_backend.h:791
double gray_gamma
Definition ui_backend.h:749

References SIO::black, SIO::blue, BLUE_GAMMA, SIO::blue_gamma, SIO::box_bg, SIO::box_fg, SIO::brackets, SIO::brackets_bg, SIO::brackets_fg, bw_chk, bw_ran, bw_sp, cell_bl, cell_black_bg, cell_blue_bg, cell_box, cell_br, cell_brktl, cell_brktr, cell_bt, cell_chk, cell_cmdln, cell_cr, cell_cyan_bg, cell_default, cell_fill_char, cell_green_bg, cell_ho, cell_ind, cell_ln, cell_lt, cell_magenta_bg, cell_nt, cell_nt_hl, cell_nt_hl_rev, cell_nt_rev, cell_ran, cell_red_bg, cell_rt, cell_sp, cell_title, cell_tl, cell_tr, cell_tt, cell_ve, cell_white_bg, cell_yellow_bg, CLR_BG, CLR_BLACK, CLR_BLUE, CLR_BOX_BG, CLR_BOX_FG, CLR_BRACKETS_BG, CLR_BRACKETS_FG, CLR_CMDLN_BG, CLR_CMDLN_FG, 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_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::cmdln_bg, SIO::cmdln_fg, cp_black, cp_blue, cp_box, cp_brackets, cp_cmdln, cp_cyan, cp_default, cp_fill_char, cp_green, cp_ind, cp_ln, cp_magenta, cp_nt, cp_nt_hl, cp_nt_hl_rev, cp_nt_rev, cp_red, cp_title, cp_white, cp_yellow, SIO::cyan, SIO::fill_char_bg, SIO::fill_char_fg, GRAY_GAMMA, SIO::gray_gamma, SIO::green, GREEN_GAMMA, SIO::green_gamma, SIO::ind_bg, SIO::ind_fg, 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::ran_bg, SIO::ran_fg, SIO::red, RED_GAMMA, SIO::red_gamma, SIO::title_bg, SIO::title_fg, ui, ui_add_pair(), ui_cell_from_ucp(), ui_init_clr_palette(), SIO::white, and SIO::yellow.

Referenced by read_theme(), ui_init(), and ui_init().

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

◆ ui_is_set_chyron_key()

bool ui_is_set_chyron_key ( UiChyron * chyron,
uint k )

Check if function key label is set.

is_set_chyron_key

Parameters
chyronstructure
kFunction key index (0-19)
Returns
true if set, false if not set

Definition at line 738 of file ui_common.c.

738 {
739 if (chyron->key[k]->text[0] != '\0')
740 return true;
741 else
742 return false;
743}

Referenced by form_post(), and form_process().

Here is the caller graph for this function:

◆ ui_iso8601_timestamp()

char * ui_iso8601_timestamp ( char * buf,
size_t n,
bool local )

Generate an ISO 8601 timestamp string.

ui_iso8601_timestamp

Parameters
bufBuffer to store the timestamp string
nSize of the buffer
localIf true, use local time; if false, use UTC
Returns
Pointer to the buffer containing the timestamp string

Definition at line 1421 of file ui_common.c.

1421 {
1422 if (buf == NULL)
1423 return NULL;
1424 time_t t = time(NULL);
1425 struct tm *tp = local ? localtime(&t) : gmtime(&t);
1426 if (local) {
1427 strftime(buf, n, _("%Y-%m-%dT%H:%M:%S%z"), tp);
1428 } else {
1429 strftime(buf, n, _("%Y-%m-%dT%H:%M:%SZ"), tp);
1430 }
1431 return buf;
1432}

Referenced by ui_log_write().

Here is the caller graph for this function:

◆ ui_log_write()

void ui_log_write ( const UiLogLevel level,
const char * file,
const char * func,
const int line,
const char * fmt,
... )

Definition at line 1476 of file ui_common.c.

1476 {
1477 UiLogLevel safe_level = (level >= LOG_LEVEL_COUNT) ? INFO : level;
1478 struct stat st;
1479 if (ui_log_ctx.fd == -1 || (stat(ui_log_ctx.file_spec, &st) == 0 && st.st_size >= MAX_LOG_SIZE)) {
1480 if (ui_log_ctx.fd != -1) {
1481 close(ui_log_ctx.fd);
1482 ui_log_ctx.fd = -1;
1483 }
1484 char old_archive[MAXLEN];
1485 strnz__cpy(old_archive, ui_log_ctx.file_spec, MAXLEN - 1);
1486 strnz__cat(old_archive, ".closed", MAXLEN - 1);
1487 rename(ui_log_ctx.file_spec, old_archive);
1488 ui_log_ctx.fd = ui_open_log();
1489 }
1490 char log_buffer[MAX_LOG_REC_LEN];
1491 int offset = 0;
1492 int written = snprintf(log_buffer + offset, sizeof(log_buffer) - offset, "[%s]%s[%s]%s<%s:%s:%d> ",
1493 ui_iso8601_timestamp(ui_log_ctx.timestamp, sizeof(ui_log_ctx.timestamp), ui_log_ctx.localtime),
1494 ui_log_ctx.color[safe_level],
1495 ui_log_ctx.level[safe_level],
1496 ANSI_RESET,
1497 file, func, line);
1498 if (written > 0)
1499 offset += written;
1500 va_list args;
1501 va_start(args, fmt);
1502 written = vsnprintf(log_buffer + offset, sizeof(log_buffer) - offset, fmt, args);
1503 va_end(args);
1504 if (written > 0)
1505 offset += written;
1506 if (offset < (int)sizeof(log_buffer) - 2) {
1507 log_buffer[offset++] = '\n';
1508 log_buffer[offset] = '\0';
1509 } else {
1510 log_buffer[sizeof(log_buffer) - 2] = '\n';
1511 log_buffer[sizeof(log_buffer) - 1] = '\0';
1512 offset = sizeof(log_buffer) - 1;
1513 }
1514 // Atomic if log_buffer <= 4096 bytes
1515 if (write(ui_log_ctx.fd, log_buffer, offset) == -1) {
1516 perror("Failed to write atomic log record");
1517 }
1518}
UiLogLevel
Definition ui_backend.h:230
@ LOG_LEVEL_COUNT
Definition ui_backend.h:232
UiLogContext ui_log_ctx
Definition ui_common.c:53
char * ui_iso8601_timestamp(char *buf, size_t n, bool local)
Generate an ISO 8601 timestamp string.
Definition ui_common.c:1421
int ui_open_log()
Open the log file for writing.
Definition ui_common.c:1446
#define MAX_LOG_REC_LEN
Definition lf.h:50
#define MAX_LOG_SIZE
Definition lf.h:51
#define ANSI_RESET
Definition lf.h:86
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition lf.c:2330

References UiLogContext::color, UiLogContext::fd, UiLogContext::file_spec, UiLogContext::level, UiLogContext::localtime, LOG_LEVEL_COUNT, strnz__cat(), strnz__cpy(), UiLogContext::timestamp, ui_iso8601_timestamp(), ui_log_ctx, and ui_open_log().

Referenced by pad_refresh(), ui_get_screen_size(), ui_init(), ui_prefresh(), ui_surface_addpad(), ui_surface_addpad(), ui_surface_addwin(), ui_surface_box(), ui_surface_box(), ui_surface_new(), ui_tracked_sfc_box(), ui_tracked_sfc_split_box(), view_cmd_processor(), and view_full_screen_resize().

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

◆ ui_mbc_to_wc()

void ui_mbc_to_wc ( wchar_t wc[2],
const char mbc )

Convert a multibyte character to a wide character.

mbc_to_wc

Parameters
wcOutput array for wide characters (size 2)
mbcInput multibyte character

This function converts a single multibyte character to a wide character. It uses the mbrtowc function to perform the conversion and handles any errors by setting the output to a question mark ('?') if the conversion fails. The output array is null-terminated.

Definition at line 344 of file ui_common.c.

344 {
345 wc[0] = wc[1] = L'\0';
346 mbstate_t state = {};
347 size_t len = mbrtowc(wc, &mbc, MB_CUR_MAX, &state);
348 if (len <= 0) {
349 wc[0] = L'?';
350 wc[1] = L'\0';
351 len = 1;
352 }
353}

◆ ui_mbstr_to_wcstr()

wchar_t * ui_mbstr_to_wcstr ( const char * mb_str)

Convert a multibyte string to a wide character string.

ui_mbstr_to_wcstr

Parameters
mb_strInput multibyte string
Returns
Pointer to newly allocated wide character string, or nullptr on error

This function converts a null-terminated multibyte string to a wide character string. It first calculates the required length for the wide character string, allocates memory for it, and then performs the conversion. The caller is responsible for freeing the allocated memory. If the conversion fails, it returns nullptr.

Definition at line 364 of file ui_common.c.

364 {
365 const char *src_ptr = mb_str;
366 mbstate_t state = {};
367 size_t wc_count = mbsrtowcs(NULL, &src_ptr, 0, &state);
368 if (wc_count == (size_t)-1)
369 return nullptr;
370 src_ptr = mb_str;
371 wmemset((wchar_t *)&state, 0, sizeof(state) / sizeof(wchar_t));
372 wchar_t *wc_str = malloc((wc_count + 1) * sizeof(wchar_t));
373 if (!wc_str)
374 return nullptr;
375 mbsrtowcs(wc_str, &src_ptr, wc_count + 1, &state);
376 return wc_str;
377}

Referenced by ui_border_title(), and ui_border_ysplit_text().

Here is the caller graph for this function:

◆ ui_new_chyron()

UiChyron * ui_new_chyron ( UiSurface * sfc,
ss_t w )

Create new chyron structure.

new_chyron

Returns
pointer to new chyron structure

This function allocates memory for a new chyron structure and its associated keys. It initializes the structure to zero and returns a pointer to the newly created chyron. If memory allocation fails, it calls ui_abend() to terminate the program with an error message.

Definition at line 662 of file ui_common.c.

662 {
663 UiChyron *chyron = (UiChyron *)calloc(1, sizeof(UiChyron));
664 if (!chyron) {
665 ui_abend(-1, _("calloc chyron failed"));
666 return nullptr;
667 }
668 chyron->sfc = sfc;
669 chyron->w = w;
670 for (int i = 0; i < CHYRON_KEYS; i++) {
671 chyron->key[i] = (UiChyronKey *)calloc(1, sizeof(UiChyronKey));
672 if (!chyron->key[i]) {
673 ui_abend(-1, _("calloc chyron->key[i] failed"));
674 return nullptr;
675 }
676 }
677 return chyron;
678}
void ui_abend(int ec, char *s)
Convert multibyte string to complex character array.
Definition ui_common.c:404

References ui_abend().

Referenced by form_engine(), open_pick_win(), ui_action_disposition(), ui_answer_yn(), ui_display_error(), ui_perror(), and ui_timeout_prompt().

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

◆ ui_open_log()

int ui_open_log ( )

Open the log file for writing.

ui_open_log

Returns
FILE pointer to the opened log file

Definition at line 1446 of file ui_common.c.

1446 {
1447 if (ui_log_ctx.fd == -1) {
1448 char *user = getenv("USER");
1449 time_t t = time(NULL);
1450 struct tm tp;
1451 localtime_r(&t, &tp);
1452 char time_s[16];
1453 strftime(time_s, 100, "%Y%m%d%H%M%S", &tp);
1454 ssnprintf(ui_log_ctx.file_spec, MAXLEN - 1, "/tmp/%s_ui_%s.log", user, time_s);
1455 ui_log_ctx.fd = open(ui_log_ctx.file_spec, O_WRONLY | O_CREAT | O_APPEND, 0644);
1456 if (ui_log_ctx.fd == -1) {
1457 ssnprintf(em0, MAXLEN - 1, _("Failed to open log file: %s"), ui_log_ctx.file_spec);
1458 ssnprintf(em1, MAXLEN - 1, _("Error: %s"), strerror(errno));
1459 ssnprintf(em2, MAXLEN - 1, "%s: line: %d", __FILE__, __LINE__ - 4);
1460 ssnprintf(em3, MAXLEN - 1, _("remedy: delete %s and try again"), ui_log_ctx.file_spec);
1461 fprintf(stderr, "%s\n%s\n%s\n%s\n", em0, em1, em2, em3);
1462 exit(EXIT_FAILURE);
1463 }
1464 }
1465 char ttyname[MAXLEN];
1466 char cmenu_user[MAXLEN];
1467 char *p = getenv(_("USER"));
1468 strnz__cpy(cmenu_user, p, MAXLEN - 1);
1469 if (ttyname_r(STDERR_FILENO, ttyname, sizeof(ttyname)) == 0)
1470 strnz__cpy(em0, ttyname, MAXLEN - 1);
1471 ssnprintf(em0, MAXLEN - 1, _("Ui_Log started by user '%s' on terminal '%s'"), cmenu_user, ttyname);
1472 ui_log(INFO, "%s:", em0);
1473 return ui_log_ctx.fd;
1474}
char em1[MAXLEN]
Definition lf.c:43
char em2[MAXLEN]
Definition lf.c:44
char em3[MAXLEN]
Definition lf.c:45
char em0[MAXLEN]
Definition lf.c:42

References em0, em1, em2, em3, UiLogContext::fd, UiLogContext::file_spec, ssnprintf(), strnz__cpy(), and ui_log_ctx.

Referenced by mapp_initialization(), and ui_log_write().

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

◆ ui_parse_ansi()

void ui_parse_ansi ( char * ansi_str,
attr_t * attrs,
uint * cpx )

Parse ANSI escape sequences for color and attributes.

parse_ansi

Parameters
ansi_strANSI escape sequence string
attrPointer to attribute variable to be updated
cpxPointer to color pair index to be updated

This function parses an ANSI escape sequence string (e.g., _("\033[31;1m")) and updates the provided attribute and color pair index accordingly. It handles standard colors, extended colors, and text attributes like bold, underline, etc.

Definition at line 1532 of file ui_common.c.

1532 {
1533 char *tok;
1534 char t0, t1;
1535 char tstr[3];
1536 uint len, x_idx;
1537 uint fg, bg;
1538 uint fg_clr, bg_clr;
1539 char *ansi_p = ansi_str + 2;
1540 ui_pair_content(*cpx, &fg_clr, &bg_clr);
1541 bool f_rgb = false;
1542 fg = fg_clr;
1543 bg = bg_clr;
1544 RGB rgb;
1545 tok = strtok((char *)ansi_p, ";m");
1546 bool a_toi_error = false;
1547 while (1) {
1548 if (tok == nullptr || *tok == '\0')
1549 break;
1550 len = strlen(tok);
1551 if (len == 2) {
1552 t0 = tok[0];
1553 t1 = tok[1];
1554 if (t0 == '3' || t0 == '4') {
1555 if (t1 == '8') {
1556 tok = strtok(nullptr, ";m");
1557 if (tok != nullptr) {
1558 if (*tok == '5') {
1559 tok = strtok(nullptr, ";m");
1560 if (tok != nullptr) {
1561 x_idx = a_toi(tok, &a_toi_error);
1562 rgb = ui_xterm256_idx_to_rgb(x_idx);
1563 f_rgb = true;
1564 }
1565 } else if (*tok == '2') {
1566 tok = strtok(nullptr, ";m");
1567 if (tok != nullptr) {
1568 rgb.r = a_toi(tok, &a_toi_error);
1569 tok = strtok(nullptr, ";m");
1570 if (tok != nullptr) {
1571 rgb.g = a_toi(tok, &a_toi_error);
1572 tok = strtok(nullptr, ";m");
1573 if (tok != nullptr) {
1574 rgb.b = a_toi(tok, &a_toi_error);
1575 f_rgb = true;
1576 }
1577 }
1578 }
1579 }
1580 }
1581 if (f_rgb) {
1582 if (t0 == '3')
1583 fg_clr = ui_color_from_rgb(&rgb);
1584 else if (t0 == '4')
1585 bg_clr = ui_color_from_rgb(&rgb);
1586 }
1587 } else if (t1 == '9') {
1588 if (t0 == '3')
1589 fg_clr = CLR_NT_FG;
1590 else if (t0 == '4')
1591 bg_clr = CLR_NT_BG;
1592 } else if (t1 >= '0' && t1 <= '7') {
1593 if (t0 == '3') {
1594 tstr[0] = t1;
1595 tstr[1] = '\0';
1596 x_idx = a_toi(tstr, &a_toi_error);
1597 rgb = ui_xterm256_idx_to_rgb(x_idx);
1598 fg_clr = ui_color_from_rgb(&rgb);
1599 } else if (t0 == '4') {
1600 tstr[0] = t1;
1601 tstr[1] = '\0';
1602 x_idx = a_toi(tstr, &a_toi_error);
1603 rgb = ui_xterm256_idx_to_rgb(x_idx);
1604 bg_clr = ui_color_from_rgb(&rgb);
1605 }
1606 }
1607 } else if (t0 == '0') {
1608 *tok = t1;
1609 len = 1;
1610 }
1611 }
1612 if (len == 1) {
1613 if (*tok == '0') {
1614 *attrs = WA_NORMAL;
1615 fg_clr = CLR_NT_FG;
1616 bg_clr = CLR_NT_BG;
1617 } else {
1618 switch (a_toi(tok, &a_toi_error)) {
1619 case 1:
1620 *attrs |= WA_BOLD;
1621 break;
1622 case 2:
1623 *attrs |= WA_DIM;
1624 break;
1625 case 3:
1626 *attrs |= WA_ITALIC;
1627 break;
1628 case 4:
1629 *attrs |= WA_UNDERLINE;
1630 break;
1631 case 5:
1632 *attrs |= WA_BLINK;
1633 break;
1634 case 7:
1635 *attrs |= WA_REVERSE;
1636 break;
1637 case 8:
1638 *attrs |= WA_INVIS;
1639 break;
1640 default:
1641 break;
1642 }
1643 }
1644 } else if (len == 0) {
1645 *attrs = WA_NORMAL;
1646 fg_clr = CLR_NT_FG;
1647 bg_clr = CLR_NT_BG;
1648 }
1649 tok = strtok(nullptr, ";m");
1650 }
1651 if (!a_toi_error && (fg_clr != fg || bg_clr != bg))
1652 *cpx = ui_add_pair(fg_clr, bg_clr);
1653 return;
1654}
#define WA_NORMAL
#define WA_BLINK
#define WA_ITALIC
#define WA_DIM
#define WA_INVIS
#define WA_BOLD
#define WA_REVERSE
#define WA_UNDERLINE
RGB ui_xterm256_idx_to_rgb(uint idx)
Convert XTerm 256 color index to RGB.
Definition ui_common.c:969
int ui_pair_content(uint pair, uint *fg, uint *bg)
Get the foreground and background colors of a specified color pair.
int ui_color_from_rgb(RGB *rgb)
Convert RGB to curses color index, adding new color if necessary.

References a_toi(), CLR_NT_BG, CLR_NT_FG, ui_add_pair(), ui_color_from_rgb(), ui_pair_content(), and ui_xterm256_idx_to_rgb().

Here is the call graph for this function:

◆ ui_rgb_to_xterm256_idx()

uint ui_rgb_to_xterm256_idx ( RGB * rgb)

Convert RGB color to XTerm 256 color index.

ui_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 947 of file ui_common.c.

947 {
948 if (rgb->r == rgb->g && rgb->g == rgb->b) {
949 if (rgb->r < 8)
950 return 16;
951 if (rgb->r > 248)
952 return 231;
953 return ((rgb->r - 8) / 10) + 231;
954 } else {
955 uint r_index = (rgb->r < 45) ? 0 : (rgb->r - 60) / 40 + 1;
956 uint g_index = (rgb->g < 45) ? 0 : (rgb->g - 60) / 40 + 1;
957 uint b_index = (rgb->b < 45) ? 0 : (rgb->b - 60) / 40 + 1;
958 return 16 + (36 * r_index) + (6 * g_index) + b_index;
959 }
960}

◆ ui_set_chyron_key()

void ui_set_chyron_key ( UiChyron * chyron,
uint k,
char * s,
uint kc )

Set chyron key with default color pair (cp_nt_rev).

set_chyron_key

Parameters
chyronstructure
kchyron key index (0-19)
schyron key label
kcchyron key code

This function sets the label and keycode for a function key in the chyron structure. It uses the default color pair cp_nt_rev for the key label. If the input string s is not empty, it copies the string into the chyron key's text field. If the input string is empty, it sets the first character of the text field to '\0' to indicate that the key is not set. The keycode is stored in the chyron key's keycode field, and the color pair index is set to cp_nt_rev.

Definition at line 778 of file ui_common.c.

778 {
779 if (*s != '\0')
780 ssnprintf(chyron->key[k]->text, CHYRON_KEY_MAXLEN - 1, "%s", s);
781 else
782 chyron->key[k]->text[0] = '\0';
783 chyron->key[k]->keycode = kc;
784 chyron->key[k]->active = true;
785 chyron->key[k]->cell_base = cell_nt_rev;
786}
#define CHYRON_KEY_MAXLEN
Definition ui_backend.h:91

References cell_nt_rev, and ssnprintf().

Referenced by form_engine(), open_pick_win(), ui_action_disposition(), ui_answer_yn(), ui_display_error(), ui_perror(), and ui_timeout_prompt().

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

◆ ui_set_chyron_key_cb()

void ui_set_chyron_key_cb ( UiChyron * chyron,
uint k,
char * s,
uint kc,
UiCell cell_base )

Set chyron key with color pair (cp).

set_chyron_key

Parameters
chyronstructure
kchyron key index (0-19)
schyron key label
kcchyron key code
cell_basecolor pair for chyron key label

This function is like set_chyron_key, except it includes a color pair numbers

Definition at line 754 of file ui_common.c.

754 {
755 if (*s != '\0')
756 ssnprintf(chyron->key[k]->text, CHYRON_KEY_MAXLEN - 1, "%s", s);
757 else
758 chyron->key[k]->text[0] = '\0';
759 chyron->key[k]->keycode = kc;
760 chyron->key[k]->active = true;
761 chyron->key[k]->cell_base = cell_base;
762}

References ssnprintf().

Referenced by field_editor(), form_engine(), and picker().

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

◆ ui_sub_surface_str()

const char * ui_sub_surface_str ( ss_t w)

Definition at line 1436 of file ui_common.c.

1436 {
1437 if (w < BOX || w >= SUB_SFC_MAX)
1438 return _("unknown");
1439 return subsfc_s[w];
1440}
@ SUB_SFC_MAX
Definition ui_backend.h:86
const char * subsfc_s[]
Definition ui_common.c:1434

References SUB_SFC_MAX, and subsfc_s.

◆ ui_tracked_sfc_box()

int ui_tracked_sfc_box ( uint wlines,
uint wcols,
uint wbegy,
uint wbegx,
const char * wtitle )

Create a new surface with a box window.

ui_tracked_sfc_box_com

Parameters
wlinesNumber of lines for the window
wcolsNumber of columns for the window
wbegyStarting Y position for the window
wbegxStarting X position for the window
wtitleTitle for the window
Returns
0 on success, -1 on error

This function creates a new surface and adds a box window to it. It checks if the maximum number of surfaces has been exceeded and adjusts the window size based on the screen size. The new surface is stored in the global ui_surface array, and the surface pointer (sfc_ptr) is incremented. The window is then rendered on the screen.

Definition at line 429 of file ui_common.c.

429 {
430 if (sfc_ptr >= SFC_MAX) {
431 ui_log(ERROR, _("Maximum number of surfaces (%d) exceeded"), SFC_MAX);
432 exit(EXIT_FAILURE);
433 }
434 uint maxy, maxx;
435 ui_get_screen_size(&maxy, &maxx);
436 wlines = min(wlines, maxy);
437 wcols = min(wcols, maxx);
438 sfc_ptr++;
439 // -------------------> UI_win_box <-------------------
440 ui_surface[sfc_ptr] = ui_surface_box(nullptr, 0, wlines + 2, wcols + 2, wbegy, wbegx, wtitle);
442 ui_surface_addwin(sfc, WIN, BOX, wlines, wcols, 1, 1);
443 ui_render();
444 return 0;
445}
UiSurface * ui_surface_box(UiSurface *parent, ss_t p, uint lines, uint cols, uint y, uint x, const char *title)
Create a new UI surface with a border box and optional title.
Definition ui_ncurses.c:293
int ui_surface_addwin(UiSurface *s, ss_t w, ss_t p, uint lines, uint cols, uint y, uint x)
Add a new window to the specified UiSurface.
Definition ui_ncurses.c:423
void ui_get_screen_size(uint *lines, uint *cols)
Get the current screen size (number of lines and columns).
Definition ui_ncurses.c:754
#define SFC_MAX
Definition ui_backend.h:65
UiSurface * ui_surface[UI_SFC_MAX]
Definition ui_ncurses.c:40

References sfc_ptr, ui_get_screen_size(), ui_log_write(), ui_render(), ui_surface, ui_surface_addwin(), and ui_surface_box().

Referenced by display_form(), main(), menu_engine(), popup_ckeys(), ui_action_disposition(), ui_answer_yn(), ui_display_error(), ui_perror(), and ui_timeout_prompt().

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

◆ ui_tracked_sfc_split_box()

int ui_tracked_sfc_split_box ( uint wlines,
uint wcols,
uint split_y,
uint split_x,
uint wbegy,
uint wbegx,
const char * wtitle )

Create a new surface with a split box window.

surface_split_box_win_new

Parameters
wlinesNumber of lines for the main window
wcolsNumber of columns for the main window
split_yY position for the split line
split_xX position for the split line (not implemented yet)
wbegyStarting Y position for the window
wbegxStarting X position for the window
wtitleTitle for the window
Returns
0 on success, -1 on error

This function creates a new surface and adds a split box window to it. It checks if the maximum number of surfaces has been exceeded and adjusts the window size based on the screen size. The new surface is stored in the global ui_surface array, and the surface pointer (sfc_ptr) is incremented. The main window and the split window are then rendered on the screen, with a separator line drawn at the specified Y position.

Definition at line 467 of file ui_common.c.

467 {
468 if (sfc_ptr >= SFC_MAX) {
469 ui_log(ERROR, _("Maximum number of surfaces (%d) exceeded"), SFC_MAX);
470 exit(EXIT_FAILURE);
471 }
472 if (wlines == 0 || wcols == 0) {
473 ui_log(ERROR, _("Invalid window size: lines=%d, cols=%d"), wlines, wcols);
474 return -1;
475 }
476 uint maxy, maxx;
477 ui_get_screen_size(&maxy, &maxx);
478 if (wbegy > maxy || wbegx > maxx) {
479 ui_log(ERROR, _("Invalid window position: wbegy=%d, wbegx=%d, wlines=%d, wcols=%d"), wbegy, wbegx, wlines, wcols);
480 return -1;
481 }
482 wlines = min(wlines, maxy);
483 wcols = min(wcols, maxx);
484 split_x = min(split_x, maxx); // not implemented yet
485 uint split_wlines = min(wlines + split_y + 1, maxy);
486 wcols = min(wcols, maxx);
487 sfc_ptr++;
488 // -------------------> surface_new <-------------------
489 ui_surface[sfc_ptr] = ui_surface_box(nullptr, 0, split_wlines + 2, wcols + 2, wbegy, wbegx, wtitle);
491
492 ui_surface_addwin(sfc, WIN, BOX, wlines, wcols, 1, 1);
493 ui_bkgd(sfc, WIN, &cell_nt);
494 ui_werase(sfc, WIN);
495 ui_border_ysplit(sfc, BOX, wlines + 1);
496 ui_surface_addwin(sfc, WIN2, BOX, 2, wcols, wlines + 2, 1);
497 ui_bkgd(sfc, WIN2, &cell_nt);
498 ui_werase(sfc, WIN2);
499 ui_curs_set(0);
500#ifdef DEBUG_IMMED_UI
501 ui_render();
502#endif
503 return 0;
504}
int ui_bkgd(UiSurface *s, ss_t w, const UiCell *cell)
Set the background of a specific window within a UiSurface.
Definition ui_ncurses.c:974
int ui_curs_set(int visibility)
Set the visibility of the cursor.
Definition ui_ncurses.c:881
int ui_werase(UiSurface *s, ss_t w)
Erase the contents of a UiSurface or all surfaces.
Definition ui_ncurses.c:582
int ui_border_ysplit(UiSurface *sfc, ss_t w, uint y)
Draw a box with a separator line around the specified window.
Definition ui_common.c:556

References cell_nt, sfc_ptr, ui_bkgd(), ui_border_ysplit(), ui_curs_set(), ui_get_screen_size(), ui_log_write(), ui_surface, ui_surface_addwin(), ui_surface_box(), and ui_werase().

Referenced by open_pick_win().

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

◆ ui_unset_chyron_key()

void ui_unset_chyron_key ( UiChyron * chyron,
uint k )

Unset chyron key.

unset_chyron_key

Parameters
chyronstructure
kchyron_key index

Definition at line 793 of file ui_common.c.

793 {
794 chyron->key[k]->text[0] = '\0';
795}

◆ ui_xterm256_idx_to_rgb()

RGB ui_xterm256_idx_to_rgb ( uint idx)

Convert XTerm 256 color index to RGB.

ui_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 969 of file ui_common.c.

969 {
973 RGB rgb;
974 if (idx > 255)
975 idx = 255;
976 rgb.r = rgb.g = rgb.b = 0;
977 if (idx < 16) {
978 rgb.r = std_color[idx].r;
979 rgb.g = std_color[idx].g;
980 rgb.b = std_color[idx].b;
981 } else if (idx >= 16 && idx <= 231) {
982 idx -= 16;
983 rgb.r = (idx / 36) % 6 * 51;
984 rgb.g = (idx / 6) % 6 * 51;
985 rgb.b = (idx % 6) * 51;
986 } else if (idx >= 232 && idx <= 255) {
987 uint gray = (idx - 232) * 11;
988 rgb.r = rgb.g = rgb.b = gray;
989 }
990 return rgb;
991}
STDRGB std_color[]
Definition ui_common.c:188

References std_color.

Referenced by parse_ansi_str(), and ui_parse_ansi().

Here is the caller graph for this function:

Variable Documentation

◆ BLUE_GAMMA

double BLUE_GAMMA = 1.2

Definition at line 82 of file ui_common.c.

Referenced by ui_apply_gamma(), and ui_initialize_sio().

◆ border_double

const wchar_t * border_double = L"═║╠╣╦╩╬╔╗╚╝"

Definition at line 86 of file ui_common.c.

Referenced by ui_init(), and ui_init().

◆ border_heavy

const wchar_t * border_heavy = L"━┃┣┫┳┻╋┏┓┗┛"

Definition at line 88 of file ui_common.c.

Referenced by ui_init(), and ui_init().

◆ border_none

const wchar_t * border_none = L" "

Definition at line 89 of file ui_common.c.

Referenced by ui_init(), and ui_init().

◆ border_rounded

const wchar_t * border_rounded = L"─│├┤┬┴┼╭╮╰╯"

Definition at line 87 of file ui_common.c.

Referenced by ui_init(), and ui_init().

◆ border_single

const wchar_t * border_single = L"─│├┤┬┴┼┌┐└┘"

BOX WIDE UNICODE CODEPOINTS

Definition at line 85 of file ui_common.c.

Referenced by ui_init(), and ui_init().

◆ box_attr

uint16_t box_attr

Definition at line 35 of file ui_common.c.

◆ bw

Definition at line 27 of file ui_common.c.

Referenced by ui_init(), and ui_init().

◆ bw_chk

const wchar_t * bw_chk = L"\u2611"

left_angle

Definition at line 103 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ bw_da

const wchar_t * bw_da = L"\u2193"

large down arrow

Definition at line 100 of file ui_common.c.

◆ bw_h09

const wchar_t * bw_h09 = L"\u23BD"

horizontal line 9

Definition at line 104 of file ui_common.c.

◆ bw_la

const wchar_t * bw_la = L"\u2190"

large left arrow

Definition at line 98 of file ui_common.c.

◆ bw_lan

const wchar_t * bw_lan = L"\u276E"

left_angle

Definition at line 102 of file ui_common.c.

◆ bw_ra

const wchar_t * bw_ra = L"\u2192"

large right arrow

Definition at line 97 of file ui_common.c.

◆ bw_ran

const wchar_t * bw_ran = L"\u276F"

right_angle

Definition at line 101 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ bw_rbl

const wchar_t * bw_rbl = L"\u2570"

rounded bottom left

Definition at line 94 of file ui_common.c.

◆ bw_rbr

const wchar_t * bw_rbr = L"\u256f"

rounded bottom right

Definition at line 95 of file ui_common.c.

◆ bw_rtl

const wchar_t * bw_rtl = L"\u256d"

MISCELANEOUS UNICODE CODEPOINTS rounded top left

Definition at line 92 of file ui_common.c.

◆ bw_rtr

const wchar_t * bw_rtr = L"\u256e"

rounded top right

Definition at line 93 of file ui_common.c.

◆ bw_sp

const wchar_t * bw_sp = L"\x20"

space

Definition at line 96 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ bw_ua

const wchar_t * bw_ua = L"\u2191"

large up arrow

Definition at line 99 of file ui_common.c.

◆ cell_bl

UiCell cell_bl

Definition at line 142 of file ui_common.c.

Referenced by ui_border_draw(), and ui_initialize_sio().

◆ cell_black_bg

UiCell cell_black_bg

Definition at line 150 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_blue_bg

UiCell cell_blue_bg

Definition at line 154 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_box

UiCell cell_box

Definition at line 127 of file ui_common.c.

Referenced by ui_border_title(), ui_initialize_sio(), and ui_surface_box().

◆ cell_br

UiCell cell_br

Definition at line 143 of file ui_common.c.

Referenced by ui_border_draw(), and ui_initialize_sio().

◆ cell_brktl

UiCell cell_brktl

Definition at line 121 of file ui_common.c.

Referenced by display_form(), and ui_initialize_sio().

◆ cell_brktr

UiCell cell_brktr

Definition at line 122 of file ui_common.c.

Referenced by display_form(), and ui_initialize_sio().

◆ cell_bs

UiCell cell_bs

Definition at line 137 of file ui_common.c.

◆ cell_bt

UiCell cell_bt

Definition at line 147 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_chk

◆ cell_cmdln

UiCell cell_cmdln

Definition at line 129 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_cr

UiCell cell_cr

Definition at line 148 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_cyan_bg

UiCell cell_cyan_bg

Definition at line 155 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_default

UiCell cell_default

Definition at line 119 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_fill_char

UiCell cell_fill_char

Definition at line 120 of file ui_common.c.

Referenced by form_display_fields(), and ui_initialize_sio().

◆ cell_green_bg

UiCell cell_green_bg

Definition at line 152 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_ho

◆ cell_ind

UiCell cell_ind

Definition at line 128 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_ln

UiCell cell_ln

Definition at line 131 of file ui_common.c.

Referenced by init_view_boxwin(), init_view_full_screen(), and ui_initialize_sio().

◆ cell_ls

UiCell cell_ls

Definition at line 134 of file ui_common.c.

◆ cell_lt

UiCell cell_lt

◆ cell_magenta_bg

UiCell cell_magenta_bg

Definition at line 156 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_nt

◆ cell_nt_hl

UiCell cell_nt_hl

◆ cell_nt_hl_rev

UiCell cell_nt_hl_rev

Definition at line 126 of file ui_common.c.

Referenced by field_editor(), form_engine(), menu_cmd_processor(), picker(), and ui_initialize_sio().

◆ cell_nt_rev

◆ cell_ran

UiCell cell_ran

Definition at line 132 of file ui_common.c.

Referenced by get_cmd_arg(), get_cmd_char(), picker(), and ui_initialize_sio().

◆ cell_red_bg

UiCell cell_red_bg

Definition at line 151 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_rs

UiCell cell_rs

Definition at line 135 of file ui_common.c.

◆ cell_rt

UiCell cell_rt

◆ cell_sp

◆ cell_title

UiCell cell_title

Definition at line 130 of file ui_common.c.

Referenced by ui_border_title(), and ui_initialize_sio().

◆ cell_tl

UiCell cell_tl

Definition at line 138 of file ui_common.c.

Referenced by ui_border_draw(), ui_border_title(), and ui_initialize_sio().

◆ cell_tr

UiCell cell_tr

Definition at line 139 of file ui_common.c.

Referenced by ui_border_draw(), and ui_initialize_sio().

◆ cell_ts

UiCell cell_ts

Definition at line 136 of file ui_common.c.

◆ cell_tt

UiCell cell_tt

Definition at line 146 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_ve

UiCell cell_ve

Definition at line 141 of file ui_common.c.

Referenced by ui_border_draw(), and ui_initialize_sio().

◆ cell_white_bg

UiCell cell_white_bg

Definition at line 157 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cell_yellow_bg

UiCell cell_yellow_bg

Definition at line 153 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ click_x

int click_x

the x coordinate of a mouse click

Definition at line 30 of file ui_common.c.

Referenced by cf_accept(), field_editor(), form_post(), and form_process().

◆ click_y

int click_y

the y coordinate of a mouse click

Definition at line 29 of file ui_common.c.

Referenced by cf_accept(), field_editor(), form_post(), and form_process().

◆ cmd_key

unsigned int cmd_key

◆ colors_text

char const colors_text
Initial value:
= {
_("black"), _("red"), _("green"), _("yellow"), _("blue"), _("magenta"), _("cyan"),
_("white"), _("orange"), _("bg"), _("abg"), _("bblack"), _("bred"), _("bgreen"),
_("byellow"), _("bblue"), _("bcyan"), _("bmagenta"), _("bwhite"), _("borange"), ""}

Color names for .minitrc overrides.

colors_text

These names are used in .minitrc to specify color overrides The order of these names corresponds to the ColorsEnum values

Definition at line 110 of file ui_common.c.

110 {
111 _("black"), _("red"), _("green"), _("yellow"), _("blue"), _("magenta"), _("cyan"),
112 _("white"), _("orange"), _("bg"), _("abg"), _("bblack"), _("bred"), _("bgreen"),
113 _("byellow"), _("bblue"), _("bcyan"), _("bmagenta"), _("bwhite"), _("borange"), ""};

◆ cp_black

ushort cp_black

black

Definition at line 175 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_blue

ushort cp_blue

blue

Definition at line 179 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_box

ushort cp_box

border

Definition at line 163 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_brackets

ushort cp_brackets

field enclosure brackets

Definition at line 174 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_cmdln

ushort cp_cmdln

command line

Definition at line 165 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_cyan

ushort cp_cyan

cyan

Definition at line 180 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_default

ushort cp_default

default color pair

Definition at line 172 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_fill_char

ushort cp_fill_char

field fill characters

Definition at line 173 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_green

ushort cp_green

green

Definition at line 177 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_ind

ushort cp_ind

indicator character

Definition at line 164 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_ln

ushort cp_ln

line numbers

Definition at line 171 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_magenta

ushort cp_magenta

magenta

Definition at line 181 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_nt

ushort cp_nt

normal text

Definition at line 167 of file ui_common.c.

Referenced by fmt_line(), and ui_initialize_sio().

◆ cp_nt_hl

ushort cp_nt_hl

normal text highlight

Definition at line 169 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_nt_hl_rev

ushort cp_nt_hl_rev

normal text highlight reverse

Definition at line 170 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_nt_rev

ushort cp_nt_rev

normal text reverse

Definition at line 168 of file ui_common.c.

Referenced by search(), and ui_initialize_sio().

◆ cp_red

ushort cp_red

red

Definition at line 176 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_title

ushort cp_title

border title

Definition at line 166 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_white

ushort cp_white

white

Definition at line 182 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ cp_yellow

ushort cp_yellow

yellow

Definition at line 178 of file ui_common.c.

Referenced by ui_initialize_sio().

◆ em0

char em0[MAXLEN]

error message string for error messages

Definition at line 46 of file ui_common.c.

◆ em1

char em1[MAXLEN]

error message string for error messages

Definition at line 47 of file ui_common.c.

◆ em2

char em2[MAXLEN]

error message string for error messages

Definition at line 48 of file ui_common.c.

◆ em3

char em3[MAXLEN]

error message string for error messages

Definition at line 49 of file ui_common.c.

◆ exit_code

int exit_code

the exit code for the program, for error messages and other output

Definition at line 31 of file ui_common.c.

◆ f_ncurses_open

◆ f_notcurses_open

◆ f_sigwench

bool f_sigwench = false

Definition at line 33 of file ui_common.c.

◆ fn

char fn[MAXLEN]

function name for error messages

Definition at line 45 of file ui_common.c.

Referenced by verify_dir(), and verify_file().

◆ GRAY_GAMMA

double GRAY_GAMMA = 1.2

Gamma correction. Set in .minitrc

Definition at line 79 of file ui_common.c.

Referenced by ui_apply_gamma(), and ui_initialize_sio().

◆ GREEN_GAMMA

double GREEN_GAMMA = 1.2

Definition at line 81 of file ui_common.c.

Referenced by ui_apply_gamma(), and ui_initialize_sio().

◆ m_begx

uint m_begx = -1

Definition at line 39 of file ui_common.c.

◆ m_begy

uint m_begy = -1

Definition at line 38 of file ui_common.c.

◆ m_cols

uint m_cols

Definition at line 37 of file ui_common.c.

◆ m_lines

uint m_lines

Definition at line 36 of file ui_common.c.

◆ mouse_support

uint mouse_support

Definition at line 40 of file ui_common.c.

◆ pipe_in

int pipe_in

Definition at line 78 of file ui_common.c.

◆ pipe_out

int pipe_out

Definition at line 78 of file ui_common.c.

◆ RED_GAMMA

double RED_GAMMA = 1.2

Definition at line 80 of file ui_common.c.

Referenced by ui_apply_gamma(), and ui_initialize_sio().

◆ src_line

uint src_line

the line number of the source file being processed, for error messages

Definition at line 43 of file ui_common.c.

Referenced by verify_dir(), and verify_file().

◆ src_name

char* src_name

the name of the source file being processed, for error messages

Definition at line 44 of file ui_common.c.

Referenced by verify_dir(), and verify_file().

◆ std_color

STDRGB std_color
Initial value:
= {
{0, 0, 0},
{128, 0, 0},
{0, 128, 0},
{128, 128, 0},
{0, 0, 128},
{128, 0, 128},
{0, 128, 128},
{192, 192, 192},
{128, 128, 128},
{255, 0, 0},
{0, 255, 0},
{255, 255, 0},
{0, 0, 255},
{255, 0, 255},
{0, 255, 255},
{255, 255, 255}}

Definition at line 188 of file ui_common.c.

188 {
189 {0, 0, 0},
190 {128, 0, 0},
191 {0, 128, 0},
192 {128, 128, 0},
193 {0, 0, 128},
194 {128, 0, 128},
195 {0, 128, 128},
196 {192, 192, 192},
197 {128, 128, 128},
198 {255, 0, 0},
199 {0, 255, 0},
200 {255, 255, 0},
201 {0, 0, 255},
202 {255, 0, 255},
203 {0, 255, 255},
204 {255, 255, 255}};

Referenced by ui_chg_color(), ui_color_from_rgb(), ui_init_color_hex(), and ui_xterm256_idx_to_rgb().

◆ stderr_fd

int stderr_fd

the file descriptor for the terminal, for error messages and other output

Definition at line 78 of file ui_common.c.

◆ stdin_fd

int stdin_fd

the file descriptor for the terminal, for error messages

Definition at line 41 of file ui_common.c.

◆ stdout_fd

int stdout_fd

the file descriptor for the terminal, for error messages

Definition at line 42 of file ui_common.c.

◆ subsfc_s

const char * subsfc_s
Initial value:
= {
#define SUB_SURFACE_LIST(X)
Definition ui_backend.h:74
#define AS_STRING(NAME)
Definition ui_common.c:1433

Definition at line 1434 of file ui_common.c.

1434 {

Referenced by ui_sub_surface_str().

◆ tty_fd

int tty_fd

Definition at line 78 of file ui_common.c.

◆ ui_ctx

◆ ui_log_ctx

UiLogContext ui_log_ctx
Initial value:
= {
.fd = -1,
.file_spec = "\0",
.min_level = INFO,
.localtime = false,
.timestamp = "\0",
.color = {
[FATAL] = "\033[1;31m",
[ERROR] = "\033[0;31m",
[WARN] = "\033[0;33m",
[INFO] = "\033[0;32m",
[VERBOSE] = "\033[0;36m",
[DEBUG] = "\033[0;34m",
[SILENT] = _("SILENT"),
},
.level = {[FATAL] = "FATAL", [ERROR] = "ERROR", [WARN] = "WARN", [INFO] = "INFO", [VERBOSE] = "VERBOSE", [DEBUG] = "DEBUG", [SILENT] = "SILENT"}}

Definition at line 53 of file ui_common.c.

53 {
54 .fd = -1,
55 .file_spec = "\0",
56 .min_level = INFO,
57 .localtime = false,
58 .timestamp = "\0",
59 .color = {
60 [FATAL] = "\033[1;31m", // Bold Red
61 [ERROR] = "\033[0;31m", // Regular Red
62 [WARN] = "\033[0;33m", // Yellow
63 [INFO] = "\033[0;32m", // Green
64 [VERBOSE] = "\033[0;36m", // Cyan
65 [DEBUG] = "\033[0;34m", // Blue
66 [SILENT] = _("SILENT"),
67 },
68 .level = {[FATAL] = "FATAL", [ERROR] = "ERROR", [WARN] = "WARN", [INFO] = "INFO", [VERBOSE] = "VERBOSE", [DEBUG] = "DEBUG", [SILENT] = "SILENT"}};

Referenced by mapp_initialization(), ui_init(), ui_init(), ui_log_write(), ui_open_log(), and write_config().

◆ win_attr

uint16_t win_attr

Ncurses attributes for the current window, such as color pair, bold, etc.

Definition at line 34 of file ui_common.c.