C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
ui_notcurses.c File Reference

NotCurses UI backend — lifecycle, surface management, and capabilities. More...

#include <iso646.h>
#include "cm.h"
#include "ui_backend.h"
#include "ui_notcurses_compat.h"
#include "ui_notcurses_internal.h"
#include <errno.h>
#include <inttypes.h>
#include <locale.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for ui_notcurses.c:

Go to the source code of this file.

Macros

#define _XOPEN_SOURCE_EXTENDED   1

Functions

void ui_abs_yx (UiSurface *s, ss_t w, int *y, int *x)
 Get the absolute cursor position within a window of a UI surface.
uint ui_add_pair (uint fg, uint bg)
 Add a new color pair to the UI color pair palette.
int ui_bkgd (UiSurface *s, ss_t w, const UiCell *cell)
 Set the background cell for the specified window within a UI surface.
int ui_bkgdset (UiSurface *s, ss_t w, const UiCell *cell)
 Set the background cell for the specified window within a UI surface without changing the base character.
int ui_bkgrnd (UiSurface *s, ss_t w, const UiCell *cell)
 Set the background cell for the specified window within a UI surface without changing the base character.
int ui_bkgrndset (UiSurface *s, ss_t w, const UiCell *cell)
 Set the background cell for the specified window within a UI surface without changing the base character.
UiCell ui_cell_from_ucp (const wchar_t *ucp, const uint32_t *fg, const uint32_t *bg)
 Create a UiCell from a Unicode codepoint and specified foreground and background colors.
int ui_chg_color (uint16_t color_idx, uint32_t *color)
 Change the color at a specified index in the UI color palette.
int ui_clear ()
 Clear the contents of the standard plane.
int ui_color_content (uint16_t color, uint8_t *r, uint8_t *g, uint8_t *b)
 Get the RGB components of a color from the UI color palette.
uint ui_color_from_rgb (RGB *rgb)
 Convert an RGB color to a color index in the UI color palette.
int ui_curs_set (int visible)
 Enable or disable the cursor visibility.
int ui_cursor_enable (UiSurface *s, ss_t w, bool visible)
 Enable or disable the cursor at the current position on the surface and plane specified.
int ui_cursor_enable_yx (UiSurface *s, ss_t w, uint y, uint x, bool visible)
 Enable or disable the cursor at a specific position on the surface and plane specified.
int ui_cursor_move (UiSurface *s, ss_t w, uint y, uint x)
 Move the cursor to the specified position within a window of a UI surface.
void ui_cursor_yx (int *y, int *x)
 Get the current cursor position within a window of a UI surface.
void ui_def_prog_mode ()
void ui_endwin ()
 Destroy a UI surface and free its resources.
int ui_erase ()
 Clear the contents of the specified window within a UI surface.
UiBackend ui_get_backend ()
 Get the current UI backend in use.
void ui_get_caps (UiCaps *caps)
 Get the capabilities of the current UI backend.
uint64_t ui_get_channels_from_pair (uint16_t pair)
 Get the combined foreground and background color channels for a given color pair index.
int ui_get_nccell (UiSurface *sfc, ss_t w, const UiCell *cell, wchar_t *wstr, UiStyle *style, short *pair)
 Get the properties of a cell at the current cursor position in a window of a UI surface.
int ui_get_pair (uint16_t pair, uint *fg, uint *bg)
 Get the foreground and background color indices for a given color pair index.
void ui_get_screen_size (uint *lines, uint *cols)
 Get the current screen size in lines and columns.
int ui_getmaxx (UiSurface *s, ss_t w)
 Get the maximum number of columns of a window within a UI surface.
int ui_getmaxy (UiSurface *s, ss_t w)
 Get the maximum number of lines (rows) of a window within a UI surface.
void ui_getmaxyx (UiSurface *s, ss_t w, uint *y, uint *x)
 Get the maximum dimensions of a window within a UI surface.
void ui_getyx (UiSurface *s, ss_t w, uint *y, uint *x)
 Get the current cursor position within a window of a UI surface.
RGB ui_hex_to_rgb (char *s)
 Convert a hexadecimal color string to an RGB structure.
int ui_idcok (UiSurface *s, ss_t w, bool enable)
 Enable or disable the keypad for the specified window within a UI surface.
int ui_idlok (UiSurface *s, ss_t w, bool enable)
 Enable or disable the use of the keypad for the specified window within a UI surface.
UiRuntime * ui_init (const UiConfig *cfg, SIO *sio)
 Initialize the UI runtime with the specified configuration and SIO.
int ui_init_color (uint16_t color, uint8_t r, uint8_t g, uint8_t b)
 Initialize a color in the UI color palette with specified RGB components.
uint ui_init_color_hex (char *s)
 Initialize a color from a hexadecimal string representation.
int ui_init_pair (uint16_t pair, uint fg, uint bg)
 Initialize a color pair in the UI color pair palette with specified foreground and background colors.
int ui_keypad (UiSurface *s, ss_t w, bool enable)
 Enable or disable the keypad for the specified window within a UI surface.
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).
struct notcurses * ui_notcurses_get_nc ()
 Get the pointer to the Notcurses context associated with the UI.
NcPlane * ui_notcurses_surface_get_plane (const UiSurface *s, ss_t w)
 Get the pointer to the NcPlane associated with a specific window in a UI surface.
int ui_pair_content (uint16_t pair, uint *fg, uint *bg)
 Get the foreground and background color indices for a given color pair index.
int ui_plane_cpy (NcPlane *dst, NcPlane *src, int dst_y, int dst_x, int src_y, int src_x, int ylen, int xlen)
void ui_plane_get_abs_yx (UiSurface *s, ss_t w, int *absy, int *absx)
int ui_prefresh (UiSurface *s, ss_t w, int pminrow, int pmincol, int sminrow, int smincol, int smaxrow, int smaxcol)
void ui_render ()
 Render the UI.
int ui_resume ()
 Resume the UI and enter the alternate screen.
int ui_scrollok (UiSurface *s, ss_t w, bool enable)
 Enable or disable scrolling for the specified window within a UI surface.
int ui_set_nccell (UiSurface *sfc, ss_t w, UiCell *cell, const wchar_t *wstr, const UiStyle style, short pair)
 Set the properties of a cell at the current cursor position in a window of a UI surface.
int ui_setscrreg (UiSurface *s, ss_t w, uint top, uint bottom)
 Set the scrolling region for the specified window within a UI surface.
void ui_shutdown ()
 Shutdown the UI runtime and free all associated resources.
int ui_surface_addpad (UiSurface *s, ss_t pad, ss_t win, uint lines, uint cols, uint y, uint x, bool hidden)
 Add padding to an existing UI surface.
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 an existing UI surface.
UiSurface * ui_surface_box (UiSurface *parent, ss_t p, uint lines, uint cols, uint y, uint x, const char *wtitle)
 Create a new UI surface with a border box and optional title.
void ui_surface_destroy (UiSurface *s)
 Destroy a UI surface and free its resources.
int ui_surface_hide (UiSurface *s, ss_t w)
 Hide the specified window within a UI surface.
int ui_surface_move (UiSurface *s, ss_t w, uint y, uint x)
 Move a UI surface to a new position on the screen.
UiSurface * ui_surface_new (ss_t w, UiSurface *parent, ss_t p, uint lines, uint cols, uint y, uint x)
 Create a new UI surface with the specified parameters.
int ui_surface_resize (UiSurface *s, ss_t w, uint lines, uint cols)
 Resize a UI surface to new dimensions.
int ui_surface_show (UiSurface *s, ss_t w)
 Show the specified window within a UI surface.
int ui_suspend ()
 Suspend the UI and leave the alternate screen.
int ui_top_surface (UiSurface *s, ss_t w)
 Move the specified window within a UI surface to the top of the z-order.
void ui_update_panels ()
 Update the panels and render the UI.
int ui_wclear (UiSurface *s, ss_t w)
 Clear the contents of the specified window within a UI surface.
int ui_werase (UiSurface *s, ss_t w)
 Clear the contents of the specified window within a UI surface.
int ui_wmove (UiSurface *s, ss_t w, uint y, uint x)
 Move the cursor to the specified position within a window of a UI surface.
int ui_wscrl (UiSurface *s, ss_t w, int r)
 Scroll the contents of the specified window up or down by the specified number of lines.

Variables

UiCell bkgd_cell
uint COLS
uint LINES
int sfc_ptr = -1
NcPlane * stdplane
UiSurface * stdsfc
UiRuntime * ui = NULL
UiColor * ui_color
uint ui_color_cnt = 0
UiConfig * ui_config
UiPair * ui_pair
uint ui_pair_cnt = 0
UiSurface * ui_surface [UI_SFC_MAX]

Detailed Description

NotCurses UI backend — lifecycle, surface management, and capabilities.

Implements all UiRuntime and UiSurface operations declared in ui_backend.h using the NotCurses library.

Definition in file ui_notcurses.c.

Macro Definition Documentation

◆ _XOPEN_SOURCE_EXTENDED

#define _XOPEN_SOURCE_EXTENDED   1

Definition at line 10 of file ui_notcurses.c.

Function Documentation

◆ ui_abs_yx()

void ui_abs_yx ( UiSurface * s,
ss_t w,
int * y,
int * x )

Get the absolute cursor position within a window of a UI surface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
yPointer to an integer to store the absolute y-coordinate of the cursor.
xPointer to an integer to store the absolute x-coordinate of the cursor.

This function retrieves the absolute cursor position within a window of a UI surface. If the surface or window is not initialized, it does nothing.

Definition at line 724 of file ui_notcurses.c.

724 {
725 if (!s)
726 return;
727 ncplane_abs_yx(s->mplane[w], y, x);
728}
struct ncplane * mplane[SUB_SFC_MAX]
Definition ui_backend.h:392

◆ ui_add_pair()

uint ui_add_pair ( uint fg,
uint bg )

Add a new color pair to the UI color pair palette.

Parameters
fgThe foreground color index for the new color pair.
bgThe background color index for the new color pair.
Returns
The index of the newly added color pair, or EXIT_FAILURE if the maximum number of pairs is exceeded.

This function adds a new color pair to the UI color pair palette. It checks if the specified foreground and background colors already exist in the palette. If they do, it returns the existing index. If not, it adds the new color pair and returns its index. If the maximum number of pairs is exceeded, it displays an error message and returns EXIT_FAILURE.

Definition at line 1358 of file ui_notcurses.c.

1358 {
1359 uint16_t i;
1360 for (i = 1; i < ui_pair_cnt; i++) {
1361 if (ui_pair[i].fg == fg && ui_pair[i].bg == bg)
1362 return i;
1363 }
1364 if (i + 1 >= UI_PAIRS) {
1365 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 1);
1366 ssnprintf(em1, MAXLEN - 1, _("NotCurses COLOR_PAIRS (%d) exceeded (%d)"),
1367 UI_PAIRS, i);
1368 strerror_r(errno, em2, MAXLEN);
1369 ui_display_error(em0, em1, em2, nullptr);
1370 return (EXIT_FAILURE);
1371 }
1372 if (i < UI_PAIRS) {
1373 ui_pair[i].fg = fg;
1374 ui_pair[i].bg = bg;
1375 ui_pair_cnt++;
1376 }
1377 return ui_pair_cnt - 1;
1378}
#define UI_PAIRS
Definition ui_backend.h:62
UiPair * ui_pair
uint ui_pair_cnt
Definition ui_ncurses.c:44
#define MAXLEN
Definition lf.h:38
char em1[MAXLEN]
Definition lf.c:43
char em2[MAXLEN]
Definition lf.c:44
char em0[MAXLEN]
Definition lf.c:42
#define _(String)
Definition amort.c:23
size_t ssnprintf(char *, size_t, const char *,...)
Custom safe string formatting utility (Variadic version).
Definition futil.c:398
int ui_display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
Definition ui_common.c:1261

References em0, em1, em2, ssnprintf(), ui_display_error(), ui_pair, and ui_pair_cnt.

Here is the call graph for this function:

◆ ui_bkgd()

int ui_bkgd ( UiSurface * s,
ss_t w,
const UiCell * cell )

Set the background cell for the specified window within a UI surface.

Set the background of a specific window within a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
cellPointer to the UiCell representing the background cell.
Returns
0 on success, -1 on failure.

This function sets the background cell for the specified window within a UI surface. It updates the styles and channels of the ncplane associated with the window and stores the background cell in the metadata. If the surface is not initialized, it returns -1.

Definition at line 1125 of file ui_notcurses.c.

1125 {
1126 if (!s)
1127 return -1;
1128 ncplane_set_styles(s->mplane[w], cell->stylemask);
1129 ncplane_set_channels(s->mplane[w], cell->channels);
1130 ncplane_set_base(s->mplane[w], " ",
1131 cell->stylemask, cell->channels);
1132 s->meta[w].bkgd_cell = *cell;
1133 return 0;
1134}
struct nccell bkgd_cell
Definition ui_backend.h:373
struct UiSurfaceMeta meta[SUB_SFC_MAX]
Definition ui_backend.h:395
uint16_t stylemask
Definition ui_backend.h:430
uint64_t channels
Definition ui_backend.h:447

Referenced by init_view_boxwin(), init_view_full_screen(), ui_perror(), and ui_tracked_sfc_split_box().

Here is the caller graph for this function:

◆ ui_bkgdset()

int ui_bkgdset ( UiSurface * s,
ss_t w,
const UiCell * cell )

Set the background cell for the specified window within a UI surface without changing the base character.

Set the background for new content to be written to a specific window within a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
cellPointer to the UiCell representing the background cell.
Returns
0 on success, -1 on failure.

This function sets the background cell for the specified window within a UI surface without changing the base character. It updates the styles and channels of the ncplane associated with the window and stores the background cell in the metadata. If the surface is not initialized, it returns -1.

Definition at line 1146 of file ui_notcurses.c.

1146 {
1147 if (!s)
1148 return -1;
1149 ncplane_set_styles(s->mplane[w], cell->stylemask);
1150 ncplane_set_channels(s->mplane[w], cell->channels);
1151 s->meta[w].bkgd_cell = *cell;
1152 // ncplane_set_base(s->mplane[w], " ",
1153 // cell->stylemask, cell->channels);
1154 return 0;
1155}

Referenced by display_pick_page(), display_prompt(), get_cmd_arg(), init_view_boxwin(), init_view_full_screen(), menu_cmd_processor(), menu_engine(), popup_ckeys(), reverse_object(), ui_border_title(), ui_border_ysplit_text(), and unreverse_object().

Here is the caller graph for this function:

◆ ui_bkgrnd()

int ui_bkgrnd ( UiSurface * s,
ss_t w,
const UiCell * cell )

Set the background cell for the specified window within a UI surface without changing the base character.

Set the background of a specific window within a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
cellPointer to the UiCell representing the background cell.
Returns
0 on success, -1 on failure.

This function sets the background cell for the specified window within a UI surface without changing the base character. It updates the styles and channels of the ncplane associated with the window and stores the background cell in the metadata. If the surface is not initialized, it returns -1.

Definition at line 1167 of file ui_notcurses.c.

1167 {
1168 if (!s)
1169 return -1;
1170 ncplane_set_styles(s->mplane[w], cell->stylemask);
1171 ncplane_set_channels(s->mplane[w], cell->channels);
1172 ncplane_set_base(s->mplane[w], " ",
1173 cell->stylemask, cell->channels);
1174 return 0;
1175}

◆ ui_bkgrndset()

int ui_bkgrndset ( UiSurface * s,
ss_t w,
const UiCell * cell )

Set the background cell for the specified window within a UI surface without changing the base character.

Set the background for new content to be written to a specific window within a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
cellPointer to the UiCell representing the background cell.
Returns
0 on success, -1 on failure.

This function sets the background cell for the specified window within a UI surface without changing the base character. It updates the styles and channels of the ncplane associated with the window and stores the background cell in the metadata. If the surface is not initialized, it returns -1.

Definition at line 1187 of file ui_notcurses.c.

1187 {
1188 if (!s)
1189 return -1;
1190 ncplane_set_styles(s->mplane[w], cell->stylemask);
1191 ncplane_set_channels(s->mplane[w], cell->channels);
1192 ncplane_set_base(s->mplane[w], " ",
1193 cell->stylemask, cell->channels);
1194 return 0;
1195}

◆ ui_cell_from_ucp()

UiCell ui_cell_from_ucp ( const wchar_t * ucp,
const uint32_t * fg,
const uint32_t * bg )

Create a UiCell from a Unicode codepoint and specified foreground and background colors.

Parameters
ucpPointer to a wide character string representing the Unicode codepoint.
fgPointer to a 32-bit unsigned integer representing the foreground color.
bgPointer to a 32-bit unsigned integer representing the background color.
Returns
A UiCell structure representing the created cell.

This function creates a UiCell from a Unicode codepoint and specified foreground and background colors. It initializes the cell, sets its width based on the Unicode codepoint, converts the codepoint to UTF-8, and sets the styles and channels for the cell. The resulting UiCell can be used for rendering text in a UI surface.

Definition at line 1295 of file ui_notcurses.c.

1295 {
1296 nccell cell;
1297 nccell_init(&cell);
1298 GCluster *gc = (GCluster *)&cell.gcluster;
1299 wchar_t wstr[2] = {ucp[0], L'\0'};
1300 // wcwidth expects Unicode codepoints, not UTF-8 encoded bytes
1301 cell.width = wcwidth(wstr[0]);
1302 // unicode_to_utf8_gcluster converts Unicode codepoints to UTF-8
1303 unicode_to_utf8_gcluster(wstr[0], gc);
1304 nccell_set_styles(&cell, WA_NORMAL);
1305 UiChannels *chan = (UiChannels *)&cell.channels;
1306 chan->bargb = *bg;
1307 chan->fargb = *fg;
1308 chan->b_a = chan->f_a = 0x40;
1309 return cell;
1310}
#define WA_NORMAL
uint8_t f_a
Definition ui_backend.h:412
uint32_t fargb
Definition ui_backend.h:414
uint32_t bargb
Definition ui_backend.h:408
uint8_t b_a
Definition ui_backend.h:406

◆ ui_chg_color()

int ui_chg_color ( uint16_t color_idx,
uint32_t * color )

Change the color at a specified index in the UI color palette.

Parameters
color_idxThe index of the color to change in the UI color palette.
colorPointer to a 32-bit unsigned integer representing the new color value.
Returns
0 on success, -1 on error (if the color index is out of bounds).

This function changes the color at a specified index in the UI color palette. It applies gamma correction to the new color value and updates both the standard and UI color arrays with the new RGB components. If the color index is out of bounds, it returns -1.

Definition at line 1554 of file ui_notcurses.c.

1554 {
1555 RGB rgb;
1556 rgb.color = *color;
1557 if (color_idx + 1 >= UI_COLORS)
1558 return -1;
1559 ui_apply_gamma(&rgb);
1560 if (color_idx < 16) {
1561 std_color[color_idx].r = rgb.r;
1562 std_color[color_idx].g = rgb.g;
1563 std_color[color_idx].b = rgb.b;
1564 }
1565 ui_color[color_idx].r = rgb.r;
1566 ui_color[color_idx].g = rgb.g;
1567 ui_color[color_idx].b = rgb.b;
1568 return 0;
1569}
#define UI_COLORS
Definition ui_backend.h:61
UiColor * ui_color
STDRGB std_color[]
Definition ui_common.c:188
void ui_apply_gamma(RGB *rgb)
Apply gamma correction to RGB color.
Definition ui_common.c:1002
uint32_t color
Definition ui_backend.h:351
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 std_color, ui_apply_gamma(), and ui_color.

Here is the call graph for this function:

◆ ui_clear()

int ui_clear ( )

Clear the contents of the standard plane.

Clear the entire screen.

Returns
0 on success, -1 on failure.

This function clears the contents of the standard plane by erasing its contents. If the standard plane is not initialized, it returns -1.

Definition at line 563 of file ui_notcurses.c.

563 {
564 if (!stdplane)
565 return -1;
566 ncplane_erase_region(stdplane, 0, 0, 0, 0);
567 return 0;
568}
NcPlane * stdplane

References stdplane.

◆ ui_color_content()

int ui_color_content ( uint16_t color,
uint8_t * r,
uint8_t * g,
uint8_t * b )

Get the RGB components of a color from the UI color palette.

Parameters
colorThe index of the color in the UI color palette.
rPointer to store the red component of the color.
gPointer to store the green component of the color.
bPointer to store the blue component of the color.
Returns
0 on success, -1 on error (if the color index is out of bounds).

This function retrieves the RGB components of a color from the UI color palette. It checks if the specified color index is valid and then fills in the provided pointers with the corresponding RGB values. If the color index is out of bounds, it returns -1.

Definition at line 1479 of file ui_notcurses.c.

1479 {
1480 if (color + 1 >= UI_COLORS)
1481 return -1;
1482 *r = ui_color[color].r;
1483 *g = ui_color[color].g;
1484 *b = ui_color[color].b;
1485 return 0;
1486}

◆ ui_color_from_rgb()

uint ui_color_from_rgb ( RGB * rgb)

Convert an RGB color to a color index in the UI color palette.

Parameters
rgbPointer to an RGB structure representing the color to convert.
Returns
The color index corresponding to the RGB color, or -1 if the color cannot be added.

This function converts an RGB color to a color index in the UI color palette. It applies gamma correction to the RGB values and checks if the color already exists in the palette. If it does, it returns the existing index. If not, it adds the new color to the palette and returns its index. If the palette is full, it returns -1.

Definition at line 1324 of file ui_notcurses.c.

1324 {
1325 uint i;
1326 RGB tmp;
1327 ui_apply_gamma(rgb);
1328 for (i = 0; i < ui_color_cnt && i < UI_COLORS; i++) {
1329 ui_color_content(i, &tmp.r, &tmp.g, &tmp.b);
1330 if (rgb->r == tmp.r && rgb->g == tmp.g && rgb->b == tmp.b)
1331 return i;
1332 }
1333 if (i < UI_COLORS) {
1334 if (i < 16) {
1335 std_color[i].r = rgb->r;
1336 std_color[i].g = rgb->g;
1337 std_color[i].b = rgb->b;
1338 }
1339 ui_init_color(i, rgb->r, rgb->g, rgb->b);
1340 if (ui_color_cnt + 1 < UI_COLORS)
1341 ui_color_cnt++;
1342 return ui_color_cnt - 1;
1343 }
1344 return -1;
1345}
int ui_init_color(uint16_t color, uint8_t r, uint8_t g, uint8_t b)
Initialize a color in the UI color palette with specified RGB components.
int ui_color_content(uint16_t color, uint8_t *r, uint8_t *g, uint8_t *b)
Get the RGB components of a color from the UI color palette.
uint ui_color_cnt
Definition ui_ncurses.c:43

References std_color, ui_apply_gamma(), ui_color_cnt, ui_color_content(), and ui_init_color().

Here is the call graph for this function:

◆ ui_curs_set()

int ui_curs_set ( int visible)

Enable or disable the cursor visibility.

Set the visibility of the cursor.

Parameters
visibleTrue to enable the cursor, false to disable it.
Returns
0 on success, -1 on failure.

This function enables or disables the cursor visibility. If the UI is not initialized, it returns -1. When enabling the cursor, it retrieves the current cursor position and enables the cursor at that position.

Definition at line 1041 of file ui_notcurses.c.

1041 {
1042 if (!ui)
1043 return -1;
1044 if (visible == 0) {
1045 ui->cursor_visible = false;
1046 notcurses_cursor_disable(ui->nc);
1047 } else {
1048 ui->cursor_visible = true;
1049 int y, x;
1050 notcurses_cursor_yx(ui->nc, &y, &x);
1051 int rc = notcurses_cursor_enable(ui->nc, y, x);
1052 return rc;
1053 }
1054 return 0;
1055}
UiRuntime * ui
Definition ui_ncurses.c:39

References ui.

Referenced by cf_accept(), field_editor(), fork_exec(), ui_answer_yn(), and ui_tracked_sfc_split_box().

Here is the caller graph for this function:

◆ ui_cursor_enable()

int ui_cursor_enable ( UiSurface * s,
ss_t w,
bool visible )

Enable or disable the cursor at the current position on the surface and plane specified.

Enable or disable the cursor for a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
visibleTrue to enable the cursor, false to disable it.
Returns
0 on success, -1 on failure.

This function enables or disables the cursor at the current position on the surface and plane specified. If the UI is not initialized, it returns -1.

Definition at line 1093 of file ui_notcurses.c.

1093 {
1094 if (!s)
1095 return -1;
1096 if (!visible) {
1097 ui->cursor_visible = false;
1098 notcurses_cursor_disable(ui->nc);
1099 } else {
1100 uint y, x;
1101 ncplane_cursor_yx(s->mplane[w], &y, &x);
1102 int yy, xx;
1103 ncplane_abs_yx(s->mplane[w], &yy, &xx);
1104 y += yy;
1105 x += xx;
1106 ui->cursor_visible = true;
1107 return notcurses_cursor_enable(ui->nc, y, x) == 0 ? 0 : -1;
1108 }
1109 return 0;
1110}

References ui.

◆ ui_cursor_enable_yx()

int ui_cursor_enable_yx ( UiSurface * s,
ss_t w,
uint y,
uint x,
bool visible )

Enable or disable the cursor at a specific position on the surface and plane specified.

Enable or disable the cursor at a specific position within a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
yThe y-coordinate for the cursor position.
xThe x-coordinate for the cursor position.
visibleTrue to enable the cursor, false to disable it.
Returns
0 on success, -1 on failure.

This function enables or disables the cursor at a specific position on the surface and plane specified. If the UI is not initialized, it returns -1.

Definition at line 1067 of file ui_notcurses.c.

1067 {
1068 if (!s)
1069 return -1;
1070 if (!visible) {
1071 ui->cursor_visible = false;
1072 notcurses_cursor_disable(ui->nc);
1073 } else {
1074 int yy, xx;
1075 ncplane_abs_yx(s->mplane[w], &yy, &xx);
1076 y += yy;
1077 x += xx;
1078 ui->cursor_visible = true;
1079 int rc = notcurses_cursor_enable(ui->nc, y, x);
1080 return rc;
1081 }
1082 return 0;
1083}

References ui.

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

Here is the caller graph for this function:

◆ ui_cursor_move()

int ui_cursor_move ( UiSurface * s,
ss_t w,
uint y,
uint x )

Move the cursor to the specified position within a window of a UI surface.

Move the cursor to a specified position within a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
yThe y-coordinate for the new cursor position.
xThe x-coordinate for the new cursor position.
Returns
0 on success, -1 on failure.

This function moves the cursor to the specified position within a window of a UI surface. If the surface or window is not initialized, it returns -1.

Definition at line 696 of file ui_notcurses.c.

696 {
697 if (!s)
698 return -1;
699 if (ncplane_cursor_move_yx(s->mplane[w], y, x) != 0)
700 return -1;
701 return 0;
702}

Referenced by cf_accept(), display_line(), display_line_eod(), display_prompt(), display_split_line(), form_post(), form_process(), get_cmd_arg(), get_cmd_char(), ncurses_input(), picker(), remove_right_angle(), scroll_next(), scroll_prev(), search(), unreverse_object(), and view_display_page().

Here is the caller graph for this function:

◆ ui_cursor_yx()

void ui_cursor_yx ( int * y,
int * x )

Get the current cursor position within a window of a UI surface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
yPointer to an unsigned integer to store the y-coordinate of the cursor.
xPointer to an unsigned integer to store the x-coordinate of the cursor.

This function retrieves the current cursor position within a window of a UI surface. If the surface or window is not initialized, it does nothing.

Definition at line 712 of file ui_notcurses.c.

712 {
713 notcurses_cursor_yx(ui->nc, y, x);
714}

References ui.

◆ ui_def_prog_mode()

void ui_def_prog_mode ( )

Definition at line 1027 of file ui_notcurses.c.

1027 {
1028 return;
1029}

◆ ui_endwin()

void ui_endwin ( )

Destroy a UI surface and free its resources.

End the UI application, cleaning up resources and shutting down the UI runtime.

Parameters
sPointer to the UiSurface to be destroyed.

This function destroys a UI surface by freeing its associated ncplanes and metadata. It also frees the memory allocated for the UiSurface structure. If the provided pointer is NULL, the function does nothing.

Definition at line 425 of file ui_notcurses.c.

425 {
426 ui_shutdown();
427}
void ui_shutdown()
Shutdown the UI runtime and free all associated resources.

References ui_shutdown().

Referenced by exec_objects(), fork_exec(), and form_exec_receiver().

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

◆ ui_erase()

int ui_erase ( )

Clear the contents of the specified window within a UI surface.

Erase the entire screen.

Parameters
sPointer to the UiSurface containing the window to clear.
wThe index of the window to clear.
Returns
0 on success, -1 on failure.

This function clears the contents of the specified window within a UI surface by erasing its contents. If the surface or window is not initialized, it returns -1.

Definition at line 578 of file ui_notcurses.c.

578 {
579 if (!stdplane)
580 return -1;
581 ncplane_erase_region(stdplane, 0, 0, 0, 0);
582 return 0;
583}

References stdplane.

Referenced by view_full_screen_resize().

Here is the caller graph for this function:

◆ ui_get_caps()

void ui_get_caps ( UiCaps * caps)

Get the capabilities of the current UI backend.

Get the UI backend capabilities.

Parameters
capsPointer to a UiCaps structure to be filled with the capabilities.

This function populates the provided UiCaps structure with information about the capabilities of the current UI backend. It sets various fields in the structure, such as truecolor support, palette size, mouse support, Unicode support, and resize capability. If the provided pointer is NULL or if the UI runtime is not initialized, the function does nothing.

Definition at line 63 of file ui_notcurses.c.

63 {
64 if (!caps)
65 return;
66 memset(caps, 0, sizeof(*caps));
67 if (!ui)
68 return;
69 caps->truecolor = true;
70 caps->palette256 = true;
71 caps->mouse = ui->mouse_enabled;
72 caps->unicode = true;
73 caps->resize = true;
74 caps->color_pairs = UI_PAIRS;
75 caps->pad_relative_yx = true;
76}
bool palette256
Definition ui_backend.h:499
bool mouse
Definition ui_backend.h:500
bool pad_relative_yx
Definition ui_backend.h:504
int color_pairs
Definition ui_backend.h:503
bool truecolor
Definition ui_backend.h:498
bool unicode
Definition ui_backend.h:501
bool resize
Definition ui_backend.h:502

References UiCaps::color_pairs, UiCaps::mouse, UiCaps::pad_relative_yx, UiCaps::palette256, UiCaps::resize, UiCaps::truecolor, ui, and UiCaps::unicode.

Referenced by init_view_boxwin(), and init_view_full_screen().

Here is the caller graph for this function:

◆ ui_get_channels_from_pair()

uint64_t ui_get_channels_from_pair ( uint16_t pair)

Get the combined foreground and background color channels for a given color pair index.

Parameters
pairThe color pair index.
Returns
A 64-bit unsigned integer representing the combined foreground and background color channels.

This function retrieves the combined foreground and background color channels for a given color pair index. It uses the ui_get_pair function to obtain the foreground and background color indices, then retrieves their RGB values and constructs a UiChannels structure. The resulting combined channels are returned as a 64-bit unsigned integer.

Definition at line 1400 of file ui_notcurses.c.

1400 {
1401 uint fg, bg;
1402 // ui_channels is a struct that holds the foreground and background color
1403 // channels
1404 // use channels.fb to get the combined foreground and background color channels
1405 UiChannels ui_channels = {};
1406 ui_get_pair(pair, &fg, &bg);
1407 ui_color_content(fg, &ui_channels.f_r, &ui_channels.f_g, &ui_channels.f_b);
1408 ui_channels.f_a = 0x40;
1409 ui_channels.f_r = ui_color[fg].r;
1410 ui_channels.f_g = ui_color[fg].g;
1411 ui_channels.f_b = ui_color[fg].b;
1412 bg = ui_pair[pair].bg;
1413 ui_color_content(bg, &ui_channels.b_r, &ui_channels.b_g, &ui_channels.b_b);
1414 ui_channels.b_a = 0x40;
1415 ui_channels.b_r = ui_color[bg].r;
1416 ui_channels.b_g = ui_color[bg].g;
1417 ui_channels.b_b = ui_color[bg].b;
1418 return ui_channels.fb;
1419}
int ui_get_pair(uint16_t pair, uint *fg, uint *bg)
Get the foreground and background color indices for a given color pair index.
uint8_t f_g
Definition ui_backend.h:412
uint8_t f_b
Definition ui_backend.h:412
uint8_t b_r
Definition ui_backend.h:406
uint64_t fb
Definition ui_backend.h:417
uint8_t f_r
Definition ui_backend.h:412
uint8_t b_g
Definition ui_backend.h:406
uint8_t b_b
Definition ui_backend.h:406

References ui_color_content(), and ui_get_pair().

Here is the call graph for this function:

◆ ui_get_nccell()

int ui_get_nccell ( UiSurface * sfc,
ss_t w,
const UiCell * cell,
wchar_t * wstr,
UiStyle * style,
short * pair )

Get the properties of a cell at the current cursor position in a window of a UI surface.

Parameters
sfcPointer to the UiSurface containing the window.
wThe index of the window within the surface.
cellPointer to a UiCell structure to store the cell properties.
wstrPointer to a wide character string to store the cell's character(s).
stylePointer to a UiStyle variable to store the cell's style attributes.
pairPointer to a short variable to store the color pair index of the cell.
Returns
0 on success, -1 on failure.

This function retrieves the properties of a cell at the current cursor position in a window of a UI surface. It fills in the provided UiCell structure with the cell's properties, including its character(s), style attributes, and color pair index. If any of the input pointers are NULL, it returns -1.

Definition at line 1213 of file ui_notcurses.c.

1219 {
1220 (void)sfc;
1221 (void)w;
1222 if (!cell || !wstr || !style || !pair)
1223 return -1;
1224 GCluster gc;
1225 gc.u32 = cell->gcluster;
1226 *wstr = gc.w32;
1227 *style = cell->stylemask;
1228 // Convert the channels to a color pair index
1229 UiChannels channels;
1230 channels.fb = cell->channels;
1231 RGB rgb;
1232 rgb.r = channels.f_r;
1233 rgb.g = channels.f_g;
1234 rgb.b = channels.f_b;
1235 // If the color index does not exist, create a new one
1236 int fg = ui_color_from_rgb(&rgb);
1237 rgb.r = channels.b_r;
1238 rgb.g = channels.b_g;
1239 rgb.b = channels.b_b;
1240 // If the color index does not exist, create a new one
1241 int bg = ui_color_from_rgb(&rgb);
1242 // If the color pair does not exist, create a new one
1243 *pair = ui_add_pair(fg, bg);
1244 return 0;
1245}
uint ui_add_pair(uint fg, uint bg)
Add a new color pair to the UI color pair palette.
uint ui_color_from_rgb(RGB *rgb)
Convert an RGB color to a color index in the UI color palette.
wchar_t w32
Definition ui_backend.h:148
uint32_t u32
Definition ui_backend.h:147
uint32_t gcluster
Definition ui_backend.h:422

References GCluster::u32, ui_add_pair(), ui_color_from_rgb(), and GCluster::w32.

Here is the call graph for this function:

◆ ui_get_pair()

int ui_get_pair ( uint16_t pair,
uint * fg,
uint * bg )

Get the foreground and background color indices for a given color pair index.

Parameters
pairThe color pair index.
fgPointer to store the foreground color index.
bgPointer to store the background color index.
Returns
0 on success, -1 on error (if the pair index is out of bounds).

Definition at line 1385 of file ui_notcurses.c.

1385 {
1386 *fg = ui_pair[pair].fg;
1387 *bg = ui_pair[pair].bg;
1388 return 0;
1389}

Referenced by ui_get_channels_from_pair(), and ui_set_nccell().

Here is the caller graph for this function:

◆ ui_get_screen_size()

void ui_get_screen_size ( uint * lines,
uint * cols )

Get the current screen size in lines and columns.

Get the current screen size (number of lines and columns).

Parameters
linesPointer to an unsigned integer to store the number of lines (rows).
colsPointer to an unsigned integer to store the number of columns.

This function retrieves the current screen size in lines and columns.

Definition at line 929 of file ui_notcurses.c.

929 {
930 if (!ui)
931 return;
932 unsigned int r = 0, c = 0;
933 notcurses_stddim_yx(ui->nc, &r, &c);
934 ui->lines = (int)r;
935 ui->cols = (int)c;
936 if (lines)
937 *lines = ui->lines;
938 if (cols)
939 *cols = ui->cols;
940 ui_log(INFO, "ui_get_screen_size(lines=%u, cols=%u)", *lines, *cols);
941}

References ui, and ui_log_write().

Referenced by open_pick_win(), popup_ckeys(), ui_action_disposition(), ui_answer_yn(), ui_display_error(), ui_perror(), ui_surface_box(), ui_surface_new(), ui_timeout_prompt(), ui_tracked_sfc_box(), ui_tracked_sfc_split_box(), view_calc_boxwin_dimensions(), view_calc_full_screen_dimensions(), and view_cmd_processor().

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

◆ ui_getmaxx()

int ui_getmaxx ( UiSurface * s,
ss_t w )

Get the maximum number of columns of a window within a UI surface.

Get the maximum number of columns of a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
Returns
The maximum number of columns of the window, or -1 on failure.

This function retrieves the maximum number of columns of a window within a UI surface. If the surface or window is not initialized, it returns -1.

Definition at line 785 of file ui_notcurses.c.

785 {
786 if (!s)
787 return -1;
788 uint y, x;
789 ncplane_dim_yx(s->mplane[w], &y, &x);
790 return x;
791}

Referenced by ui_border_draw(), ui_border_title(), ui_border_ysplit(), and ui_border_ysplit_text().

Here is the caller graph for this function:

◆ ui_getmaxy()

int ui_getmaxy ( UiSurface * s,
ss_t w )

Get the maximum number of lines (rows) of a window within a UI surface.

Get the maximum number of lines (rows) of a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
Returns
The maximum number of lines (rows) of the window, or -1 on failure.

This function retrieves the maximum number of lines (rows) of a window within a UI surface. If the surface or window is not initialized, it returns -1.

Definition at line 770 of file ui_notcurses.c.

770 {
771 if (!s)
772 return -1;
773 uint y, x;
774 ncplane_dim_yx(s->mplane[w], &y, &x);
775 return y;
776}

Referenced by field_editor(), ui_assign_chyron_win(), and ui_border_draw().

Here is the caller graph for this function:

◆ ui_getmaxyx()

void ui_getmaxyx ( UiSurface * s,
ss_t w,
uint * y,
uint * x )

Get the maximum dimensions of a window within a UI surface.

Get the maximum dimensions of a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
yPointer to an unsigned integer to store the maximum number of lines (rows).
xPointer to an unsigned integer to store the maximum number of columns.

This function retrieves the maximum dimensions of a window within a UI surface. If the surface or window is not initialized, it does nothing.

Definition at line 756 of file ui_notcurses.c.

756 {
757 if (!s)
758 return;
759 ncplane_dim_yx(s->mplane[w], y, x);
760}

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

Here is the caller graph for this function:

◆ ui_getyx()

void ui_getyx ( UiSurface * s,
ss_t w,
uint * y,
uint * x )

Get the current cursor position within a window of a UI surface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
yPointer to an unsigned integer to store the y-coordinate of the cursor.
xPointer to an unsigned integer to store the x-coordinate of the cursor.

This function retrieves the current cursor position within a window of a UI surface. If the surface or window is not initialized, it does nothing.

Definition at line 742 of file ui_notcurses.c.

742 {
743 if (!s)
744 return;
745 ncplane_cursor_yx(s->mplane[w], y, x);
746}

Referenced by display_prompt(), and get_cmd_char().

Here is the caller graph for this function:

◆ ui_hex_to_rgb()

RGB ui_hex_to_rgb ( char * s)

Convert a hexadecimal color string to an RGB structure.

Parameters
sA string representing the color in hexadecimal format (e.g., "#RRGGBB").
Returns
An RGB structure containing the red, green, and blue components of the color.

This function converts a hexadecimal color string to an RGB structure. It uses sscanf to parse the hex string and extract the red, green, and blue components. The resulting RGB structure is returned.

Definition at line 1462 of file ui_notcurses.c.

1462 {
1463 RGB rgb;
1464 sscanf(s, "#%02hhX%02hhX%02hhX", &rgb.r, &rgb.g, &rgb.b);
1465 return rgb;
1466}

◆ ui_idcok()

int ui_idcok ( UiSurface * s,
ss_t w,
bool enable )

Enable or disable the keypad for the specified window within a UI surface.

Enable or disable the use of the insert/delete character capabilities for a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
enableTrue to enable the keypad, false to disable the keypad.
Returns
0 on success, -1 on failure.

This function does nothing.

Definition at line 870 of file ui_notcurses.c.

870 {
871 (void)s;
872 (void)w;
873 (void)enable;
874 return 0;
875}

Referenced by init_view_boxwin(), and init_view_full_screen().

Here is the caller graph for this function:

◆ ui_idlok()

int ui_idlok ( UiSurface * s,
ss_t w,
bool enable )

Enable or disable the use of the keypad for the specified window within a UI surface.

Enable or disable the use of the insert/delete line capabilities for a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
enableTrue to enable the use of the keypad, false to disable it.
Returns
0 on success, -1 on failure.

This function does nothing.

Definition at line 884 of file ui_notcurses.c.

884 {
885 (void)s;
886 (void)w;
887 (void)enable;
888 return 0;
889}

Referenced by init_view_boxwin(), and init_view_full_screen().

Here is the caller graph for this function:

◆ ui_init()

UiRuntime * ui_init ( const UiConfig * cfg,
SIO * sio )

Initialize the UI runtime with the specified configuration and SIO.

Initialize the UI runtime with the given configuration and SIO.

Parameters
cfgPointer to a UiConfig structure containing configuration options.
sioPointer to a SIO structure for input/output operations.
Returns
Pointer to the initialized UiRuntime structure, or NULL on failure.

This function initializes the UI runtime using the NotCurses library. It sets up the terminal, creates the standard plane, and initializes various UI components based on the provided configuration. If any step fails, it cleans up and returns NULL.

Definition at line 90 of file ui_notcurses.c.

90 {
91 setlocale(LC_ALL, "en_US.UTF-8");
92 ui = calloc(1, sizeof(*ui));
93 if (!ui)
94 return NULL;
95 char tty_name[MAXLEN];
96 if (ttyname_r(STDIN_FILENO, tty_name, sizeof(tty_name)) != 0) {
97 free(ui);
98 ui = NULL;
99 return NULL;
100 }
101 ui->tty_fp = fopen(tty_name, "r+");
102 if (ui->tty_fp == NULL) {
103 ui = NULL;
104 free(ui);
105 return NULL;
106 }
107 ui_log_ctx.min_level = cfg->log_level;
108 NotCursesOptions nc_opts = {
109 .flags = NCOPTION_SUPPRESS_BANNERS |
110 NCOPTION_NO_QUIT_SIGHANDLERS,
111 };
112 ui->nc = notcurses_init(&nc_opts, ui->tty_fp);
113 if (ui->nc == NULL) {
114 free(ui);
115 ui = NULL;
116 return NULL;
117 }
118 f_notcurses_open = true;
119 stdplane = notcurses_stdplane(ui->nc);
120 notcurses_render(ui->nc);
121
122 if (ui->nc == NULL) {
123 fclose(ui->tty_fp);
124 ui->tty_fp = NULL;
125 free(ui);
126 ui = NULL;
127 return NULL;
128 }
129 notcurses_mice_enable(ui->nc, NCMICE_BUTTON_EVENT);
130 notcurses_cursor_disable(ui->nc);
131 notcurses_stddim_yx(ui->nc, &ui->lines, &ui->cols);
132 stdsfc = calloc(1, sizeof(*stdsfc));
133 if (!stdsfc)
134 return NULL;
135 for (int i = 0; i < SUB_SFC_MAX; i++) {
136 stdsfc->mplane[i] = NULL;
137 stdsfc->meta[i].lines = 0;
138 stdsfc->meta[i].cols = 0;
139 stdsfc->meta[i].y = 0;
140 stdsfc->meta[i].x = 0;
141 stdsfc->meta[i].hidden = false;
142 }
143 stdsfc->runtime = ui;
144 stdsfc->parent = NULL;
145 stdsfc->meta[BOX].lines = ui->lines;
146 stdsfc->meta[BOX].cols = ui->cols;
147 stdsfc->meta[BOX].y = 0;
148 stdsfc->meta[BOX].x = 0;
149 stdsfc->mplane[BOX] = stdplane;
150 if (!stdsfc->mplane[BOX]) {
151 notcurses_stop(ui->nc);
152 f_notcurses_open = false;
153 return NULL;
154 }
155 sfc_ptr = -1;
156 LINES = ui->lines;
157 COLS = ui->cols;
158 ui_pair = calloc(UI_PAIRS, sizeof(UiPair));
159 if (!ui_pair) {
160 free(ui_pair);
161 notcurses_stop(ui->nc);
162 f_notcurses_open = false;
163 free(ui);
164 return NULL;
165 }
166 ui_pair_cnt = 0;
167 ui_color = calloc(UI_COLORS, sizeof(UiColor));
168 if (!ui_color) {
169 free(ui_pair);
170 notcurses_stop(ui->nc);
171 f_notcurses_open = false;
172 free(ui);
173 return NULL;
174 }
175 ui_color_cnt = 0;
176 if (cfg->border_style)
177 ui->border_style = cfg->border_style;
178 if (!ui->border_style)
179 ui->border_style = UI_BORDER_ROUNDED;
180 if (cfg) {
181 switch (ui->border_style) {
182 case UI_BORDER_SINGLE:
183 memcpy(bw.str, border_single, sizeof(bw.str));
184 break;
185 case UI_BORDER_DOUBLE:
186 memcpy(bw.str, border_double, sizeof(bw.str));
187 break;
188 case UI_BORDER_ROUNDED:
189 memcpy(bw.str, border_rounded, sizeof(bw.str));
190 break;
191 case UI_BORDER_HEAVY:
192 memcpy(bw.str, border_heavy, sizeof(bw.str));
193 break;
194 case UI_BORDER_NONE:
195 memcpy(bw.str, border_none, sizeof(bw.str));
196 break;
197 default:
198 memcpy(bw.str, border_rounded, sizeof(bw.str));
199 break;
200 }
201 }
202 ui->tty_fd = notcurses_inputready_fd(ui->nc);
204 stdsfc = calloc(1, sizeof(*stdsfc));
205 return ui;
206}
struct UiColor UiColor
Definition ui_backend.h:465
uint COLS
Definition ui_backend.h:467
struct notcurses_options NotCursesOptions
Definition ui_backend.h:462
@ SUB_SFC_MAX
Definition ui_backend.h:86
struct UiPair UiPair
Definition ui_backend.h:464
uint LINES
UiSurface * stdsfc
Definition ui_ncurses.c:46
int sfc_ptr
Definition ui_ncurses.c:42
const wchar_t * border_none
Definition ui_common.c:89
UiLogContext ui_log_ctx
Definition ui_common.c:53
BorderWide bw
Definition ui_common.c:27
const wchar_t * border_double
Definition ui_common.c:86
const wchar_t * border_single
Definition ui_common.c:85
void ui_initialize_sio(SIO *sio)
Definition ui_common.c:211
const wchar_t * border_heavy
Definition ui_common.c:88
bool f_notcurses_open
Definition ui_common.c:51
const wchar_t * border_rounded
Definition ui_common.c:87
UiBorderStyle border_style
Definition ui_backend.h:486
UiLogLevel log_level
Definition ui_backend.h:488

References border_double, border_heavy, border_none, border_rounded, border_single, UiConfig::border_style, bw, f_ncurses_open, f_notcurses_open, UiConfig::log_level, UiLogContext::min_level, sfc_ptr, stdplane, stdsfc, border_wide::str, SUB_SFC_MAX, ui, ui_color, ui_color_cnt, ui_initialize_sio(), ui_log_ctx, ui_log_write(), ui_pair, ui_pair_cnt, and ui_shutdown().

Referenced by main().

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

◆ ui_init_color()

int ui_init_color ( uint16_t color,
uint8_t r,
uint8_t g,
uint8_t b )

Initialize a color in the UI color palette with specified RGB components.

Parameters
colorThe index of the color to initialize in the UI color palette.
rThe red component of the color (0-255).
gThe green component of the color (0-255).
bThe blue component of the color (0-255).
Returns
0 on success, -1 on error (if the color index is out of bounds).

This function initializes a color in the UI color palette with specified RGB components. It checks if the specified color index is valid and then sets the corresponding RGB values in the ui_color array. If the color index is out of bounds, it returns -1.

Definition at line 1499 of file ui_notcurses.c.

1499 {
1500 if (color + 1 >= UI_COLORS)
1501 return -1;
1502 ui_color[color].r = r;
1503 ui_color[color].g = g;
1504 ui_color[color].b = b;
1505 return 0;
1506}

References ui_color.

◆ ui_init_color_hex()

uint ui_init_color_hex ( char * s)

Initialize a color from a hexadecimal string representation.

Parameters
sA string representing the color in hexadecimal format (e.g., "#RRGGBB").
Returns
The index of the initialized color in the UI color palette, or 0 if the color cannot be added.

This function initializes a color from a hexadecimal string representation. It converts the hex string to an RGB structure, applies gamma correction, and checks if the color already exists in the UI color palette. If it does, it returns the existing index. If not, it adds the new color to the palette and returns its index. If the palette is full, it returns 0.

Definition at line 1430 of file ui_notcurses.c.

1430 {
1431 RGB rgb;
1432 rgb = ui_hex_to_rgb(s);
1433 ui_apply_gamma(&rgb);
1434 uint i;
1435 for (i = 0; i < ui_color_cnt && i < UI_COLORS; i++) {
1436 if (rgb.r == ui_color[i].r && rgb.g == ui_color[i].g && rgb.b == ui_color[i].b)
1437 return i;
1438 }
1439 if (i < UI_COLORS) {
1440 if (i < 16) {
1441 std_color[i].r = rgb.r;
1442 std_color[i].g = rgb.g;
1443 std_color[i].b = rgb.b;
1444 }
1445 ui_color[i].r = rgb.r;
1446 ui_color[i].g = rgb.g;
1447 ui_color[i].b = rgb.b;
1448 if (ui_color_cnt + 1 < UI_COLORS)
1449 ui_color_cnt++;
1450 return ui_color_cnt - 1;
1451 }
1452 return 0;
1453}
RGB ui_hex_to_rgb(char *s)
Convert a hexadecimal color string to an RGB structure.

References std_color, ui_apply_gamma(), ui_color, ui_color_cnt, and ui_hex_to_rgb().

Here is the call graph for this function:

◆ ui_init_pair()

int ui_init_pair ( uint16_t pair,
uint fg,
uint bg )

Initialize a color pair in the UI color pair palette with specified foreground and background colors.

Parameters
pairThe index of the color pair to initialize in the UI color pair palette.
fgThe foreground color index for the color pair.
bgThe background color index for the color pair.
Returns
0 on success, -1 on error (if the pair index is out of bounds).

This function initializes a color pair in the UI color pair palette with specified foreground and background colors. It checks if the specified pair index is valid and then sets the corresponding foreground and background color indices in the ui_pair array. If the pair index is out of bounds, it returns -1.

Definition at line 1537 of file ui_notcurses.c.

1537 {
1538 if (pair + 1 >= UI_PAIRS)
1539 return -1;
1540 ui_pair[pair].fg = fg;
1541 ui_pair[pair].bg = bg;
1542 return 0;
1543}

References ui_pair.

◆ ui_keypad()

int ui_keypad ( UiSurface * s,
ss_t w,
bool enable )

Enable or disable the keypad for the specified window within a UI surface.

Enable or disable the keypad for a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
enableTrue to enable the keypad, false to disable it.
Returns
0 on success, -1 on failure.

This function does nothing.

Definition at line 914 of file ui_notcurses.c.

914 {
915 (void)s;
916 (void)w;
917 (void)enable;
918 return 0;
919}

Referenced by fork_exec(), init_view_boxwin(), init_view_full_screen(), menu_cmd_processor(), open_pick_win(), picker(), and popup_ckeys().

Here is the caller graph for this function:

◆ ui_mbstr_to_cellstr()

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).

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 is a specialized version of ui_mbstr_to_cellstr for use with NCurses. It 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.

Definition at line 1618 of file ui_notcurses.c.

1618 {
1619 short cp;
1620 uint p1 = 0;
1621 uint *pos = &p1;
1622 if (p)
1623 pos = p;
1624 uint i = 0, len = 0;
1625 const char *s;
1626 attr_t style;
1627 UiCell cc;
1628 wchar_t wstr[5];
1629 ui_get_nccell(sfc, w, cell_base, &wstr[0], &style, &cp);
1630 mbstate_t mbstate;
1631 memset(&mbstate, 0, sizeof(mbstate));
1632 if (pos && *pos >= atmost - 1)
1633 return 0;
1634 while (str[i] != '\0') {
1635 s = &str[i];
1636 len = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
1637 if (len <= 0) {
1638 wstr[0] = L'?';
1639 wstr[1] = L'\0';
1640 len = 1;
1641 }
1642 wstr[1] = L'\0';
1643 if (*pos > atmost)
1644 break;
1645 if (ui_set_nccell(sfc, w, &cc, wstr, style, cp) != ERR) {
1646 if (len > 0 && (*pos + len) < atmost)
1647 cmplx_buf[(*pos)++] = cc;
1648 }
1649 i += len;
1650 }
1651 wstr[0] = L'\0';
1652 wstr[1] = L'\0';
1653 ui_set_nccell(sfc, w, &cc, wstr, style, cp);
1654 cmplx_buf[*pos] = cc;
1655 return *pos;
1656}
uint16_t attr_t
Definition ui_backend.h:458
#define ERR
Definition ui_backend.h:468
int ui_get_nccell(UiSurface *sfc, ss_t w, const UiCell *cell, wchar_t *wstr, UiStyle *style, short *pair)
Get the properties of a cell at the current cursor position in a window of a UI surface.
int ui_set_nccell(UiSurface *sfc, ss_t w, UiCell *cell, const wchar_t *wstr, const UiStyle style, short pair)
Set the properties of a cell at the current cursor position in a window of a UI surface.

◆ ui_notcurses_get_nc()

struct notcurses * ui_notcurses_get_nc ( )

Get the pointer to the Notcurses context associated with the UI.

Return the raw struct notcurses* for the NotCurses session.

Returns
A pointer to the Notcurses context, or NULL if the UI is not initialized.

This function retrieves the pointer to the Notcurses context associated with the UI. If the UI is not initialized, it returns NULL.

Definition at line 1579 of file ui_notcurses.c.

1579 {
1580 if (!ui)
1581 return NULL;
1582 return ui->nc;
1583}

References ui.

◆ ui_notcurses_surface_get_plane()

NcPlane * ui_notcurses_surface_get_plane ( const UiSurface * s,
ss_t w )

Get the pointer to the NcPlane associated with a specific window in a UI surface.

Return the raw struct ncplane* underlying a surface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
Returns
A pointer to the NcPlane associated with the specified window, or NULL if the surface is not initialized.

This function retrieves the pointer to the NcPlane associated with a specific window in a UI surface. If the surface is not initialized, it returns NULL.

Definition at line 1592 of file ui_notcurses.c.

1592 {
1593 (void)w;
1594 if (!s)
1595 return NULL;
1596 return s->mplane[w];
1597}

◆ ui_pair_content()

int ui_pair_content ( uint16_t pair,
uint * fg,
uint * bg )

Get the foreground and background color indices for a given color pair index.

Parameters
pairThe color pair index.
fgPointer to store the foreground color index.
bgPointer to store the background color index.
Returns
0 on success, -1 on error (if the pair index is out of bounds).

This function retrieves the foreground and background color indices for a given color pair index. It checks if the specified pair index is valid and then fills in the provided pointers with the corresponding foreground and background color indices. If the pair index is out of bounds, it returns -1.

Definition at line 1518 of file ui_notcurses.c.

1518 {
1519 if (pair + 1 >= UI_PAIRS)
1520 return -1;
1521 *fg = ui_pair[pair].fg;
1522 *bg = ui_pair[pair].bg;
1523 return 0;
1524}

◆ ui_plane_cpy()

int ui_plane_cpy ( NcPlane * dst,
NcPlane * src,
int dst_y,
int dst_x,
int src_y,
int src_x,
int ylen,
int xlen )

Definition at line 953 of file ui_notcurses.c.

953 {
954 if (!dst || !src)
955 return -1;
956 for (int y = 0; y < ylen; y++) {
957 for (int x = 0; x < xlen; x++) {
958 nccell c = NCCELL_TRIVIAL_INITIALIZER;
959 ncplane_at_yx_cell(src, src_y + y, src_x + x, &c);
960 ncplane_putc_yx(dst, dst_y + y, dst_x + x, &c);
961 nccell_release(src, &c);
962 }
963 }
964 return 0;
965}

Referenced by ui_prefresh().

Here is the caller graph for this function:

◆ ui_plane_get_abs_yx()

void ui_plane_get_abs_yx ( UiSurface * s,
ss_t w,
int * absy,
int * absx )

Definition at line 729 of file ui_notcurses.c.

729 {
730 ncplane_translate(s->mplane[w], NULL, absy, absx);
731 return;
732}

Referenced by ui_surface_addpad().

Here is the caller graph for this function:

◆ ui_prefresh()

int ui_prefresh ( UiSurface * s,
ss_t w,
int pminrow,
int pmincol,
int sminrow,
int smincol,
int smaxrow,
int smaxcol )

Definition at line 977 of file ui_notcurses.c.

977 {
978 if (!ui)
979 return -1;
980 if (s->meta[PAD].hidden == false)
981 ncplane_move_yx(s->mplane[w], -pminrow, -pmincol);
982 else {
983 int dst_y = sminrow;
984 int dst_x = smincol;
985 int src_y = pminrow;
986 int src_x = pmincol;
987 int ylen = smaxrow - sminrow;
988 int xlen = smaxcol - smincol;
989 ui_plane_cpy(s->mplane[VIEWPORT], s->mplane[PAD], dst_y, dst_x, src_y, src_x, ylen, xlen);
990 ui_log(INFO, "ui_plane_cpy(dst: %s, src: %s, dst_y=%d, dst_x=%d, src_y=%d, src_x=%d, ylen=%d, xlen=%d success)", ss_n[VIEWPORT], ss_n[PAD], pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol);
991 }
992 notcurses_render(ui->nc);
993 ui_log(INFO, "notcurses_render(ui->nc)");
994 return 0;
995}
int ui_plane_cpy(NcPlane *dst, NcPlane *src, int dst_y, int dst_x, int src_y, int src_x, int ylen, int xlen)

References ui, ui_log_write(), and ui_plane_cpy().

Referenced by pad_refresh().

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

◆ ui_render()

void ui_render ( )

Render the UI.

Render the UI by updating panels and refreshing the display.

This function renders the UI.

Definition at line 971 of file ui_notcurses.c.

971 {
972 if (!ui)
973 return;
974 notcurses_render(ui->nc);
975 ui_log(INFO, "notcurses_render(ui->nc)");
976}

References ui.

Referenced by cf_accept(), display_form(), display_pick_page(), field_editor(), form_display_accept_field(), form_display_field(), form_display_fields(), get_cmd_arg(), get_cmd_char(), init_pick(), init_view_boxwin(), main(), menu_cmd_processor(), menu_engine(), ncurses_input(), picker(), read_theme(), ui_draw_text_fill(), ui_get_event(), ui_restore_wins(), ui_surface_box(), ui_surface_destroy(), ui_timeout_prompt(), ui_tracked_sfc_box(), ui_update_timeout_prompt(), view_boxwin_resize(), and view_full_screen_resize().

Here is the caller graph for this function:

◆ ui_resume()

int ui_resume ( )

Resume the UI and enter the alternate screen.

Resume the UI, restoring the previous program state and updating the display.

This function resumes the UI and enters the alternate screen. It is typically used after a suspension of the UI, allowing the application to return to its previous state and continue rendering the UI.

Returns
0 on success, -1 on failure.

Definition at line 1020 of file ui_notcurses.c.

1020 {
1021 if (!ui)
1022 return -1;
1023 notcurses_enter_alternate_screen(ui->nc);
1024 notcurses_render(ui->nc);
1025 return 0;
1026}

References ui.

Referenced by fork_exec().

Here is the caller graph for this function:

◆ ui_scrollok()

int ui_scrollok ( UiSurface * s,
ss_t w,
bool enable )

Enable or disable scrolling for the specified window within a UI surface.

Enable or disable scrolling for a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
enableTrue to enable scrolling, false to disable scrolling.
Returns
0 on success, -1 on failure.

This function enables or disables scrolling for the specified window within a UI surface. If the surface or window is not initialized, it returns -1.

Definition at line 856 of file ui_notcurses.c.

856 {
857 if (!s)
858 return -1;
859 ncplane_set_scrolling(s->mplane[w], enable);
860 return 0;
861}

Referenced by init_view_boxwin(), init_view_full_screen(), menu_cmd_processor(), open_pick_win(), ui_surface_addpad(), and ui_surface_box().

Here is the caller graph for this function:

◆ ui_set_nccell()

int ui_set_nccell ( UiSurface * sfc,
ss_t w,
UiCell * cell,
const wchar_t * wstr,
const UiStyle style,
short pair )

Set the properties of a cell at the current cursor position in a window of a UI surface.

Parameters
sfcPointer to the UiSurface containing the window.
wThe index of the window within the surface.
cellPointer to a UiCell structure representing the cell properties to set.
wstrPointer to a wide character string representing the character(s) to set in the cell.
styleThe style attributes to set for the cell.
pairThe color pair index to set for the cell.
Returns
0 on success, -1 on failure.

This function sets the properties of a cell at the current cursor position in a window of a UI surface. It updates the specified UiCell structure with the provided character(s), style attributes, and color pair index. If any of the input pointers are NULL, it returns -1.

Definition at line 1260 of file ui_notcurses.c.

1266 {
1267 if (!cell)
1268 return -1;
1269 uint32_t fg, bg;
1270 nccell_init(cell);
1271 GCluster gc;
1272 unicode_to_utf8_gcluster(*wstr, &gc);
1273 nccell_set_styles(cell, style);
1274 UiChannels *chan = (UiChannels *)&cell->channels;
1275 ui_get_pair(pair, &fg, &bg);
1276 ui_color_content(fg, &chan->f_r, &chan->f_g, &chan->f_b);
1277 chan->f_a = 0x40;
1278 ui_color_content(bg, &chan->b_r, &chan->b_g, &chan->b_b);
1279 chan->b_a = 0x40;
1280 nccell_load_egc32(sfc->mplane[w], cell, gc.u32);
1281 return 0;
1282}

References GCluster::u32, ui_color_content(), and ui_get_pair().

Here is the call graph for this function:

◆ ui_setscrreg()

int ui_setscrreg ( UiSurface * s,
ss_t w,
uint top,
uint bottom )

Set the scrolling region for the specified window within a UI surface.

Set the scrolling region for a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
topThe top line of the scrolling region.
bottomThe bottom line of the scrolling region.
Returns
0 on success, -1 on failure.

This function does nothing.

Definition at line 899 of file ui_notcurses.c.

899 {
900 (void)s;
901 (void)w;
902 (void)top;
903 (void)bottom;
904 return 0;
905}

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

Here is the caller graph for this function:

◆ ui_shutdown()

void ui_shutdown ( )

Shutdown the UI runtime and free all associated resources.

Shutdown the UI runtime, cleaning up resources and freeing memory.

This function shuts down the UI runtime by destroying all surfaces, freeing memory, and stopping the NotCurses library. It also closes the terminal file pointer if it was opened. If the UI runtime is not initialized, the function does nothing.

Definition at line 435 of file ui_notcurses.c.

435 {
436 if (ui == NULL)
437 return;
438 while (sfc_ptr >= 0) {
439 if (ui_surface[sfc_ptr]) {
440 ui_log(INFO, _("Destroying surface: %d"), sfc_ptr);
442 ui_surface[sfc_ptr] = NULL;
443 }
444 sfc_ptr--;
445 }
446 if (stdsfc->mplane[BOX]) {
447 ui_log(INFO, _("Destroying mplane[%d]"), BOX);
448 ncplane_erase(stdsfc->mplane[BOX]);
449 ncplane_destroy(stdsfc->mplane[BOX]);
450 stdsfc->mplane[BOX] = NULL;
451 }
452 if (ui->tty_fp) {
453 // fclose(ui->tty_fp);
454 // ui->tty_fp = NULL;
455 }
456 if (stdsfc != NULL) {
457 ui_log(INFO, _("Destroying stdsfc"));
458 free(stdsfc);
459 stdsfc = NULL;
460 }
461 ui_log(INFO, _("Calling notcurses_stop"));
462 notcurses_stop(ui->nc);
463 f_notcurses_open = false;
464 if (ui != NULL) {
465 if (ui_pair != NULL) {
466 ui_log(INFO, _("Destroying ui_pair"));
467 free(ui_pair);
468 ui_pair = NULL;
469 }
470 if (ui_color != NULL) {
471 ui_log(INFO, _("Destroying ui_color"));
472 free(ui_color);
473 ui_color = NULL;
474 }
475 if (ui->sio) {
476 ui_log(INFO, _("Destroying ui->sio"));
477 free(ui->sio);
478 ui->sio = nullptr;
479 }
480 if (ui != NULL) {
481 ui_log(INFO, _("Destroying ui"));
482 free(ui);
483 ui = NULL;
484 }
485 }
486}
void ui_surface_destroy(UiSurface *s)
Destroy a UI surface and free its resources.
UiSurface * ui_surface[UI_SFC_MAX]
Definition ui_ncurses.c:40

References f_ncurses_open, f_notcurses_open, sfc_ptr, stdsfc, ui, ui_color, ui_pair, ui_surface, and ui_surface_destroy().

Referenced by cmenu_shutdown(), main(), ui_abend(), ui_destroy_curses(), ui_endwin(), and ui_init().

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

◆ ui_surface_addpad()

int ui_surface_addpad ( UiSurface * s,
ss_t pad,
ss_t win,
uint lines,
uint cols,
uint y,
uint x,
bool hidden )

Add padding to an existing UI surface.

Add a new pad to the specified UiSurface.

Parameters
sPointer to the UiSurface to which padding will be added.
wThe index of the new padded surface.
pThe index of the parent plane to attach to.
linesThe number of lines (rows) for the padded surface.
colsThe number of columns for the padded surface.
yThe y-coordinate for the padded surface's position.
xThe x-coordinate for the padded surface's position.
Returns
0 on success, -1 on failure.

This function adds padding to an existing UI surface by creating a new ncplane with the specified dimensions and position. It updates the metadata for the new padded surface and sets its background and scrolling properties. If any step fails, it cleans up and returns -1.

Definition at line 351 of file ui_notcurses.c.

351 {
352 uint plines, pcols;
353 ui_surface_addwin(s, VIEWPORT, win, lines, s->meta[win].cols - x, y, x);
354 int offset = 0;
355 ui_surface_addwin(s, pad, VIEWPORT, lines, cols, 0, 0);
356 ncplane_dim_yx(stdplane, &plines, &pcols);
357 if (hidden) {
358 s->meta[pad].hidden = true;
359 int absy, absx;
360 ui_plane_get_abs_yx(s, VIEWPORT, &absy, &absx);
361 offset = absy + s->meta[VIEWPORT].lines + 1;
362 ncplane_move_yx(s->mplane[pad], -offset, 0);
363 }
364 ui_log(INFO, "ncplane_move(%s, begy=%d, begx=%d) success", ss_n[pad], -offset - 1, 0);
365 ncplane_move_above(s->mplane[VIEWPORT], s->mplane[win]);
366 if (!hidden) {
367 ncplane_move_above(s->mplane[pad], s->mplane[VIEWPORT]);
368 ui_log(INFO, "ncplane_move_above(s->mplane[%s], s->mplane[%s]) success", ss_n[pad], ss_n[VIEWPORT]);
369 // PAD sits right on top of its background
370 ncplane_move_above(s->mplane[LNNO], s->mplane[pad]);
371 // Line numbers sit above PAD, clipping it on the left
372 ncplane_move_above(s->mplane[CMDLN], s->mplane[pad]);
373 // Command line sits above PAD, clipping it on the bottom
374 if (s->mplane[BOX])
375 ncplane_move_above(s->mplane[BOX], s->mplane[pad]);
376 ui_scrollok(s, pad, true);
377 }
378 return 0;
379}
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 an existing UI surface.
void ui_plane_get_abs_yx(UiSurface *s, ss_t w, int *absy, int *absx)
int ui_scrollok(UiSurface *s, ss_t w, bool enable)
Enable or disable scrolling for the specified window within a UI surface.
unsigned int lines
Definition ui_backend.h:371
unsigned int cols
Definition ui_backend.h:372

References stdplane, ui_log_write(), ui_plane_get_abs_yx(), ui_scrollok(), and ui_surface_addwin().

Referenced by init_view_boxwin(), and init_view_full_screen().

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

◆ ui_surface_addwin()

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 an existing UI surface.

Add a new window to the specified UiSurface.

Parameters
sPointer to the UiSurface to which the window will be added.
wThe index of the new window.
pThe index of the parent plane to attach to.
linesThe number of lines (rows) for the new window.
colsThe number of columns for the new window.
yThe y-coordinate for the new window's position.
xThe x-coordinate for the new window's position.
Returns
0 on success, -1 on failure.

This function adds a new window to an existing UI surface by creating a new ncplane with the specified dimensions and position. It updates the metadata for the new window and sets its background properties. If any step fails, it cleans up and returns -1.

Definition at line 395 of file ui_notcurses.c.

395 {
396 ncplane_options plane_opts = {
397 .y = y,
398 .x = x,
399 .rows = lines,
400 .cols = cols,
401 .name = NULL};
402 s->meta[w].y = y;
403 s->meta[w].x = x;
404 s->meta[w].lines = lines;
405 s->meta[w].cols = cols;
406 s->meta[w].hidden = false;
407 s->mplane[w] = ncplane_create(s->mplane[p], &plane_opts);
408 UiLogLevel level = INFO;
409 if (!s->mplane[w]) {
410 ui_log(level, "%s = ncplane_create(parent=%s, lines=%d, cols=%d, begy=%d, begx=%d) failed", ss_n[w], ss_n[p], lines, cols, y, x);
411 notcurses_stop(ui->nc);
412 f_notcurses_open = false;
413 return -1;
414 }
415 ui_log(level, "%s = ncplane_create(parent=%s, lines=%d, cols=%d, begy=%d, begx=%d) success", ss_n[w], ss_n[p], lines, cols, y, x);
416 return 0;
417}
UiLogLevel
Definition ui_backend.h:230
unsigned int y
Definition ui_backend.h:369
unsigned int x
Definition ui_backend.h:370

References f_notcurses_open, ui, and ui_log_write().

Referenced by init_view_boxwin(), init_view_full_screen(), ui_display_image(), ui_surface_addpad(), ui_tracked_sfc_box(), and ui_tracked_sfc_split_box().

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

◆ ui_surface_box()

UiSurface * ui_surface_box ( UiSurface * parent,
ss_t p,
uint lines,
uint cols,
uint y,
uint x,
const char * wtitle )

Create a new UI surface with a border box and optional title.

Parameters
parentPointer to the parent UiSurface, or NULL for no parent.
pThe index of the parent plane to attach to.
linesThe number of lines (rows) for the new surface.
colsThe number of columns for the new surface.
yThe y-coordinate for the new surface's position.
xThe x-coordinate for the new surface's position.
wtitleThe title to display on the border box, or NULL for no title.
Returns
Pointer to the newly created UiSurface, or NULL on failure.

This function creates a new UI surface with a border box and an optional title. It allocates memory for the surface, sets up its metadata, and creates a new ncplane for rendering. If any step fails, it cleans up and returns NULL.

Definition at line 294 of file ui_notcurses.c.

294 {
295 if (!ui)
296 return NULL;
297 UiSurface *s = calloc(1, sizeof(*s));
298 if (!s)
299 return NULL;
300 s->runtime = ui;
301 s->parent = parent;
302 UiLogLevel level = INFO;
303 ncplane_options plane_opts = {
304 .y = y,
305 .x = x,
306 .rows = lines,
307 .cols = cols,
308 .name = NULL};
309 s->meta[BOX].y = y;
310 s->meta[BOX].x = x;
311 s->meta[BOX].lines = lines + 2;
312 s->meta[BOX].cols = cols + 2;
313 s->meta[BOX].hidden = false;
314 strnz__cpy(s->meta[BOX].title, wtitle, MAXLEN - 1);
315 strnz__cpy(s->meta[BOX].name, "BOX", XLEN - 1);
316 ss_t w = BOX;
317 if (parent && parent->mplane[p]) {
318 s->mplane[w] = ncplane_create(parent->mplane[p], &plane_opts);
319 } else {
320 stdplane = notcurses_stdplane(ui->nc);
321 s->mplane[w] = ncplane_create(stdplane, &plane_opts);
322 }
323 if (!s->mplane[w]) {
324 level = ERROR;
325 ui_log(level, "ss_n[%s] = ncplane_create(%s, lines=%d, cols=%d, begy=%d, begx=%d) failed", ss_n[w], ss_n[p], lines, cols, y, x);
326 free(s);
327 return NULL;
328 }
329 ui_log(level, "ss_n[%s] = ncplane_create(%s, lines=%d, cols=%d, begy=%d, begx=%d) success", ss_n[w], ss_n[p], lines, cols, y, x);
330 ncplane_set_channels(s->mplane[w], cell_box.channels);
331 ui_border_draw(s, w);
332 ui_border_title(s, w, wtitle);
333 ui_render();
334 return s;
335}
ss_t
Definition ui_backend.h:84
#define XLEN
void ui_render()
Render the UI.
int ui_border_draw(UiSurface *sfc, ss_t w)
Definition ui_common.c:523
int ui_border_title(UiSurface *sfc, ss_t w, const char *title)
Draw a box with a title around the specified window.
Definition ui_common.c:621
UiCell cell_box
Definition ui_common.c:127
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition lf.c:2299
char title[MAXLEN]
Definition ui_backend.h:376
char name[MAXLEN]
Definition ui_backend.h:375
struct UiSurface * parent
Definition ui_backend.h:397
struct UiRuntime * runtime
Definition ui_backend.h:396

References cell_box, stdplane, strnz__cpy(), ui, ui_border_draw(), ui_border_title(), ui_get_screen_size(), ui_log_write(), ui_render(), and ui_scrollok().

Referenced by init_view_boxwin(), ui_display_image(), ui_tracked_sfc_box(), and ui_tracked_sfc_split_box().

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

◆ ui_surface_destroy()

void ui_surface_destroy ( UiSurface * s)

Destroy a UI surface and free its resources.

Destroy a UiSurface, cleaning up its windows and panels.

Parameters
sPointer to the UiSurface to be destroyed.

This function destroys a UI surface by freeing its associated ncplanes and metadata. It also frees the memory allocated for the UiSurface structure. If the provided pointer is NULL, the function does nothing.

Definition at line 494 of file ui_notcurses.c.

494 {
495 if (!s)
496 return;
497 ss_t w = SUB_SFC_MAX - 1;
498 while (1) {
499 if (s->mplane[w] != NULL) {
500 ui_log(INFO, _("Destroying mplane[%d]"), w);
501 ncplane_erase(s->mplane[w]);
502 ncplane_destroy(s->mplane[w]);
503 s->mplane[w] = NULL;
504 }
505 if (w == BOX)
506 break;
507 w--;
508 };
509 if (s != NULL) {
510 ui_log(INFO, _("Destroying surface: s"));
511 free(s);
512 s = NULL;
513 }
514}

References SUB_SFC_MAX, and ui_render().

Referenced by destroy_pick_view(), main(), ui_cm_surface_destroy(), ui_framed_surface_destroy(), ui_framed_surface_new(), ui_shutdown(), view_boxwin_resize(), view_file(), and view_full_screen_resize().

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

◆ ui_surface_hide()

int ui_surface_hide ( UiSurface * s,
ss_t w )

Hide the specified window within a UI surface.

Hide a UiSurface, making it invisible on the screen.

Parameters
sPointer to the UiSurface containing the window to hide.
wThe index of the window to hide.
Returns
0 on success, -1 on failure.

This function hides the specified window within a UI surface by updating its metadata and moving it far off-screen. If the surface or window is not initialized, it returns -1.

Definition at line 656 of file ui_notcurses.c.

656 {
657 if (!s)
658 return -1;
659 if (!s->meta[w].hidden) {
660 s->meta[w].hidden = true;
661 /* Move far off-screen so the plane does not obscure anything. */
662 ncplane_move_yx(s->mplane[w], -s->meta[w].lines - 1, 0);
663 }
664 return 0;
665}

◆ ui_surface_move()

int ui_surface_move ( UiSurface * s,
ss_t w,
uint y,
uint x )

Move a UI surface to a new position on the screen.

Move a UiSurface to a new position on the screen.

Parameters
sPointer to the UiSurface to be moved.
wThe index of the window within the surface to move.
yThe new y-coordinate for the surface's position.
xThe new x-coordinate for the surface's position.
Returns
0 on success, -1 on failure.

This function moves a UI surface to a new position on the screen by updating its metadata and moving the associated ncplane. If the surface is hidden, it only updates the metadata without moving the ncplane. If any step fails, it returns -1.

Definition at line 530 of file ui_notcurses.c.

530 {
531 if (!s)
532 return -1;
533 s->meta[w].y = y;
534 s->meta[w].x = x;
535 if (!s->meta[w].hidden)
536 return ncplane_move_yx(s->mplane[w], y, x) == 0 ? 0 : -1;
537 return 0;
538}

◆ ui_surface_new()

UiSurface * ui_surface_new ( ss_t w,
UiSurface * parent,
ss_t p,
uint lines,
uint cols,
uint y,
uint x )

Create a new UI surface with the specified parameters.

Parameters
wThe index of the surface to create.
parentPointer to the parent UiSurface, or NULL for no parent.
pThe index of the parent plane to attach to.
linesThe number of lines (rows) for the new surface.
colsThe number of columns for the new surface.
yThe y-coordinate for the new surface's position.
xThe x-coordinate for the new surface's position.
Returns
Pointer to the newly created UiSurface, or NULL on failure.

This function creates a new UI surface and initializes its properties based on the provided parameters. It allocates memory for the surface, sets up its metadata, and creates a new ncplane for rendering. If any step fails, it cleans up and returns NULL.

Definition at line 226 of file ui_notcurses.c.

226 {
227 if (!ui)
228 return NULL;
229 UiSurface *s = calloc(1, sizeof(*s));
230 if (!s) {
231 ui_log(ERROR, "Failed to allocate memory for UiSurface\n");
232 return NULL;
233 }
234 ui_log(INFO, _("Memory allocated for new surface"));
235 s->runtime = ui;
236 s->parent = parent;
237 UiLogLevel level = INFO;
238 ncplane_options plane_opts = {
239 .y = y,
240 .x = x,
241 .rows = lines,
242 .cols = cols};
243 s->meta[w].y = y;
244 s->meta[w].x = x;
245 s->meta[w].lines = lines;
246 s->meta[w].cols = cols;
247 s->meta[w].hidden = false;
248 if (parent && parent->mplane[p]) {
249 s->mplane[w] = ncplane_create(parent->mplane[p], &plane_opts);
250 if (!s->mplane[w]) {
251 level = ERROR;
252 ui_log(level, "%s = ncplane_create(parent=%s, lines=%d, cols=%d, begy=%d, begx=%d) failed", ss_n[w], ss_n[p], lines, cols, y, x);
253 notcurses_stop(ui->nc);
254 f_notcurses_open = false;
255 return NULL;
256 }
257 ui_log(level, "%s = ncplane_create(parent=%s, lines=%d, cols=%d, begy=%d, begx=%d) success", ss_n[w], ss_n[p], lines, cols, y, x);
258 ncplane_set_base(s->mplane[PAD], " ", 0, cell_nt.channels);
259 ncplane_set_channels(s->mplane[PAD], cell_nt.channels);
260 if (!s->mplane[w]) {
261 return NULL;
262 }
263 } else {
264 stdplane = notcurses_stdplane(ui->nc);
265 s->mplane[w] = ncplane_create(stdplane, &plane_opts);
266 if (!s->mplane[w]) {
267 level = ERROR;
268 ui_log(level, "%s = ncplane_create(parent=%s, lines=%d, cols=%d, begy=%d, begx=%d) failed", ss_n[w], "stdplane", lines, cols, y, x);
269 return NULL;
270 }
271 ui_log(level, "%s = ncplane_create(parent=%s, lines=%d, cols=%d, begy=%d, begx=%d) success", ss_n[w], ss_n[p], lines, cols, y, x);
272 }
273 if (!s->mplane[w]) {
274 notcurses_stop(ui->nc);
275 f_notcurses_open = false;
276 return NULL;
277 }
278 return s;
279}
UiCell cell_nt
Definition ui_common.c:123

References cell_nt, f_notcurses_open, stdplane, SUB_SFC_MAX, ui, ui_get_screen_size(), and ui_log_write().

Referenced by init_view_full_screen(), and ui_framed_surface_new().

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

◆ ui_surface_resize()

int ui_surface_resize ( UiSurface * s,
ss_t w,
uint lines,
uint cols )

Resize a UI surface to new dimensions.

Resize a UiSurface to new dimensions.

Parameters
sPointer to the UiSurface to be resized.
wThe index of the window within the surface to resize.
linesThe new number of lines (rows) for the surface.
colsThe new number of columns for the surface.
Returns
0 on success, -1 on failure.

This function resizes a UI surface to new dimensions by updating its metadata and resizing the associated ncplane. If any step fails, it returns -1.

Definition at line 549 of file ui_notcurses.c.

549 {
550 if (!s)
551 return -1;
552 return ncplane_resize_simple(s->mplane[w], (unsigned int)lines,
553 (unsigned int)cols) == 0
554 ? 0
555 : -1;
556}

◆ ui_surface_show()

int ui_surface_show ( UiSurface * s,
ss_t w )

Show the specified window within a UI surface.

Show a UiSurface, making it visible on the screen.

Parameters
sPointer to the UiSurface containing the window to show.
wThe index of the window to show.
Returns
0 on success, -1 on failure.

This function shows the specified window within a UI surface by updating its metadata and moving it to its designated position. If the surface or window is not initialized, it returns -1.

Definition at line 638 of file ui_notcurses.c.

638 {
639 if (!s)
640 return -1;
641 if (s->meta[w].hidden) {
642 s->meta[w].hidden = false;
643 ncplane_move_yx(s->mplane[w], s->meta[w].y, s->meta[w].x);
644 }
645 return 0;
646}

◆ ui_suspend()

int ui_suspend ( )

Suspend the UI and leave the alternate screen.

Suspend the UI, saving the current program state and ending the window session.

This function suspends the UI and leaves the alternate screen. It is typically used when the application needs to temporarily exit the UI mode, such as when executing a shell command or displaying a message outside of the UI context.

Returns
0 on success, -1 on failure.

Definition at line 1005 of file ui_notcurses.c.

1005 {
1006 if (!ui)
1007 return -1;
1008 notcurses_leave_alternate_screen(ui->nc);
1009 return 0;
1010}

References ui.

◆ ui_top_surface()

int ui_top_surface ( UiSurface * s,
ss_t w )

Move the specified window within a UI surface to the top of the z-order.

Hide a UiSurface, making it invisible on the screen.

Parameters
sPointer to the UiSurface containing the window to move.
wThe index of the window to move to the top.
Returns
0 on success, -1 on failure.

This function moves the specified window within a UI surface to the top of the z-order, making it the foremost window. If the surface or window is not initialized, it returns -1.

Definition at line 623 of file ui_notcurses.c.

623 {
624 if (!s)
625 return -1;
626 ncplane_move_top(s->mplane[w]);
627 return 0;
628}

Referenced by get_cmd_char(), and picker().

Here is the caller graph for this function:

◆ ui_update_panels()

void ui_update_panels ( )

Update the panels and render the UI.

Update the panels in the UI.

This function updates the panels and renders the UI.

Definition at line 946 of file ui_notcurses.c.

946 {
947 if (!ui)
948 return;
949 notcurses_render(ui->nc);
950 ui_log(INFO, "notcurses_render(ui->nc)");
951}

References ui.

◆ ui_wclear()

int ui_wclear ( UiSurface * s,
ss_t w )

Clear the contents of the specified window within a UI surface.

Clear the contents of a UiSurface or all surfaces.

Parameters
sPointer to the UiSurface containing the window to clear.
wThe index of the window to clear.
Returns
0 on success, -1 on failure.

This function clears the contents of the specified window within a UI surface by erasing its contents. If the surface or window is not initialized, it returns -1.

Definition at line 608 of file ui_notcurses.c.

608 {
609 if (!s)
610 return -1;
611 ncplane_erase_region(s->mplane[w], 0, 0, 0, 0);
612 return 0;
613}

References SUB_SFC_MAX.

◆ ui_werase()

int ui_werase ( UiSurface * s,
ss_t w )

Clear the contents of the specified window within a UI surface.

Erase the contents of a UiSurface or all surfaces.

Parameters
sPointer to the UiSurface containing the window to clear.
wThe index of the window to clear.
Returns
0 on success, -1 on failure.

This function clears the contents of the specified window within a UI surface by erasing its contents. If the surface or window is not initialized, it returns -1.

Definition at line 593 of file ui_notcurses.c.

593 {
594 if (!s)
595 return -1;
596 ncplane_erase_region(s->mplane[w], 0, 0, 0, 0);
597 return 0;
598}

References SUB_SFC_MAX.

Referenced by exec_objects(), full_screen_shell(), init_view_boxwin(), init_view_full_screen(), ui_display_error(), ui_perror(), and ui_tracked_sfc_split_box().

Here is the caller graph for this function:

◆ ui_wmove()

int ui_wmove ( UiSurface * s,
ss_t w,
uint y,
uint x )

Move the cursor to the specified position within a window of a UI surface.

Move the cursor to a specified position within a UiSurface.

Parameters
sPointer to the UiSurface containing the window.
wThe index of the window within the surface.
yThe y-coordinate for the new cursor position.
xThe x-coordinate for the new cursor position.
Returns
0 on success, -1 on failure.

This function moves the cursor to the specified position within a window of a UI surface. If the surface or window is not initialized, it returns -1.

Definition at line 679 of file ui_notcurses.c.

679 {
680 if (!s)
681 return -1;
682 if (ncplane_cursor_move_yx(s->mplane[w], y, x) != 0)
683 return -1;
684 return 0;
685}

Referenced by full_screen_shell(), menu_cmd_processor(), ui_display_chyron(), ui_mvwadd_wchnstr(), and ui_mvwadd_wchstr().

Here is the caller graph for this function:

◆ ui_wscrl()

int ui_wscrl ( UiSurface * s,
ss_t w,
int r )

Scroll the contents of the specified window up or down by the specified number of lines.

Scroll the contents of a UiSurface by a specified number of lines.

Parameters
sThe surface containing the window to scroll.
wThe index of the window to scroll.
rThe number of lines to scroll. Positive values scroll up, negative values scroll down.
Returns
0 on success, -1 on error.

If r is positive, the contents of the plane are moved up, leaving blank lines at the bottom. In the view application, the view scope is moved toward end of file (eof). - scope_toward_eof()

Note
ui_wscrl(-n) - If r is negative, the contents of the plane are moved down, leaving blank lines at the top. In the view application, the view scope is moved toward beginning of file (bof). - scope_toward_bof()

Definition at line 808 of file ui_notcurses.c.

808 {
809 uint rows, cols;
810 ncplane_dim_yx(s->mplane[w], &rows, &cols);
811
812 if (r > 0) {
813 // Scroll up (toward EOF): notcurses has this natively
814 ncplane_scrollup(s->mplane[w], r);
815 return 0;
816 }
817
818 // Scroll down (toward BOF): shift content down by |r| rows
819 r = -r;
820 if ((uint)r >= rows) {
821 ncplane_erase(s->mplane[w]);
822 return 0;
823 }
824
825 // Copy rows bottom-up to avoid overwriting source before reading
826 for (int src_row = (int)(rows - r) - 1; src_row >= 0; src_row--) {
827 int dst_row = src_row + r;
828 for (uint col = 0; col < cols; col++) {
829 nccell c = NCCELL_TRIVIAL_INITIALIZER;
830 ncplane_at_yx_cell(s->mplane[w], src_row, col, &c);
831 ncplane_putc_yx(s->mplane[w], dst_row, col, &c);
832 nccell_release(s->mplane[w], &c);
833 }
834 }
835 // Blank the top r rows
836 for (int row = 0; row < r; row++) {
837 for (uint col = 0; col < cols; col++) {
838 ncplane_putchar_yx(s->mplane[w], row, col, ' ');
839 }
840 }
841 return 0;
842}

Referenced by display_pick_page(), scroll_next(), and scroll_prev().

Here is the caller graph for this function:

Variable Documentation

◆ bkgd_cell

UiCell bkgd_cell

Definition at line 34 of file ui_notcurses.c.

◆ COLS

uint COLS

Definition at line 30 of file ui_notcurses.c.

◆ LINES

uint LINES

Definition at line 30 of file ui_notcurses.c.

◆ sfc_ptr

◆ stdplane

NcPlane* stdplane

◆ stdsfc

◆ ui

UiRuntime* ui = NULL

Definition at line 24 of file ui_notcurses.c.

◆ ui_color

UiColor * ui_color

Definition at line 28 of file ui_notcurses.c.

Referenced by ui_chg_color(), ui_init(), ui_init_color(), ui_init_color_hex(), and ui_shutdown().

◆ ui_color_cnt

uint ui_color_cnt = 0

Definition at line 25 of file ui_notcurses.c.

◆ ui_config

UiConfig * ui_config

Definition at line 32 of file ui_notcurses.c.

◆ ui_pair

UiPair * ui_pair

Definition at line 27 of file ui_notcurses.c.

Referenced by ui_add_pair(), ui_init(), ui_init_pair(), and ui_shutdown().

◆ ui_pair_cnt

uint ui_pair_cnt = 0

Definition at line 26 of file ui_notcurses.c.

◆ ui_surface

UiSurface* ui_surface[UI_SFC_MAX]

Definition at line 33 of file ui_notcurses.c.