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.
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 w, uint p, uint lines, uint cols, uint y, uint x)
 Add padding to an existing UI surface.
int ui_surface_addwin (UiSurface *s, ss_t w, uint p, uint lines, uint cols, uint y, uint x)
 Add a new window to an existing UI surface.
UiSurface * ui_surface_box (UiSurface *parent, uint 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, uint 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 709 of file ui_notcurses.c.

709 {
710 if (!s)
711 return;
712 ncplane_abs_yx(s->mplane[w], y, x);
713}
struct ncplane * mplane[SUB_SFC_MAX]
Definition ui_backend.h:351

◆ 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 1302 of file ui_notcurses.c.

1302 {
1303 uint16_t i;
1304 for (i = 1; i < ui_pair_cnt; i++) {
1305 if (ui_pair[i].fg == fg && ui_pair[i].bg == bg)
1306 return i;
1307 }
1308 if (i + 1 >= UI_PAIRS) {
1309 ssnprintf(em0, MAXLEN - 1, _("%s, line: %d"), __FILE__, __LINE__ - 1);
1310 ssnprintf(em1, MAXLEN - 1, _("NotCurses COLOR_PAIRS (%d) exceeded (%d)"),
1311 UI_PAIRS, i);
1312 strerror_r(errno, em2, MAXLEN);
1313 ui_display_error(em0, em1, em2, nullptr);
1314 return (EXIT_FAILURE);
1315 }
1316 if (i < UI_PAIRS) {
1317 ui_pair[i].fg = fg;
1318 ui_pair[i].bg = bg;
1319 ui_pair_cnt++;
1320 }
1321 return ui_pair_cnt - 1;
1322}
char em1[MAXLEN]
Definition ui_common.c:47
char em2[MAXLEN]
Definition ui_common.c:48
#define UI_PAIRS
Definition ui_backend.h:194
char em0[MAXLEN]
Definition ui_common.c:46
UiPair * ui_pair
uint ui_pair_cnt
Definition ui_ncurses.c:44
#define MAXLEN
Definition curskeys.c:15
#define _(String)
Definition amort.c:23
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:390
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:1200

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 1069 of file ui_notcurses.c.

1069 {
1070 if (!s)
1071 return -1;
1072 ncplane_set_styles(s->mplane[w], cell->stylemask);
1073 ncplane_set_channels(s->mplane[w], cell->channels);
1074 ncplane_set_base(s->mplane[w], " ",
1075 cell->stylemask, cell->channels);
1076 s->meta[w].bkgd_cell = *cell;
1077 return 0;
1078}
struct nccell bkgd_cell
Definition ui_backend.h:332
struct UiSurfaceMeta meta[SUB_SFC_MAX]
Definition ui_backend.h:354
uint16_t stylemask
Definition ui_backend.h:389
uint64_t channels
Definition ui_backend.h:406

Referenced by init_view_boxwin(), init_view_full_screen(), ui_surface_addpad(), and ui_surface_addwin().

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 1090 of file ui_notcurses.c.

1090 {
1091 if (!s)
1092 return -1;
1093 ncplane_set_styles(s->mplane[w], cell->stylemask);
1094 ncplane_set_channels(s->mplane[w], cell->channels);
1095 s->meta[w].bkgd_cell = *cell;
1096 // ncplane_set_base(s->mplane[w], " ",
1097 // cell->stylemask, cell->channels);
1098 return 0;
1099}

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(), ui_surface_addpad(), ui_surface_addwin(), 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 1111 of file ui_notcurses.c.

1111 {
1112 if (!s)
1113 return -1;
1114 ncplane_set_styles(s->mplane[w], cell->stylemask);
1115 ncplane_set_channels(s->mplane[w], cell->channels);
1116 ncplane_set_base(s->mplane[w], " ",
1117 cell->stylemask, cell->channels);
1118 return 0;
1119}

◆ 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 1131 of file ui_notcurses.c.

1131 {
1132 if (!s)
1133 return -1;
1134 ncplane_set_styles(s->mplane[w], cell->stylemask);
1135 ncplane_set_channels(s->mplane[w], cell->channels);
1136 ncplane_set_base(s->mplane[w], " ",
1137 cell->stylemask, cell->channels);
1138 return 0;
1139}

◆ 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 1239 of file ui_notcurses.c.

1239 {
1240 nccell cell;
1241 nccell_init(&cell);
1242 GCluster *gc = (GCluster *)&cell.gcluster;
1243 wchar_t wstr[2] = {ucp[0], L'\0'};
1244 // wcwidth expects Unicode codepoints, not UTF-8 encoded bytes
1245 cell.width = wcwidth(wstr[0]);
1246 // unicode_to_utf8_gcluster converts Unicode codepoints to UTF-8
1247 unicode_to_utf8_gcluster(wstr[0], gc);
1248 nccell_set_styles(&cell, WA_NORMAL);
1249 UiChannels *chan = (UiChannels *)&cell.channels;
1250 chan->bargb = *bg;
1251 chan->fargb = *fg;
1252 chan->b_a = chan->f_a = 0x40;
1253 return cell;
1254}
#define WA_NORMAL
uint8_t f_a
Definition ui_backend.h:371
uint32_t fargb
Definition ui_backend.h:373
uint32_t bargb
Definition ui_backend.h:367
uint8_t b_a
Definition ui_backend.h:365

◆ 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 1498 of file ui_notcurses.c.

1498 {
1499 RGB rgb;
1500 rgb.color = *color;
1501 if (color_idx + 1 >= UI_COLORS)
1502 return -1;
1503 ui_apply_gamma(&rgb);
1504 if (color_idx < 16) {
1505 std_color[color_idx].r = rgb.r;
1506 std_color[color_idx].g = rgb.g;
1507 std_color[color_idx].b = rgb.b;
1508 }
1509 ui_color[color_idx].r = rgb.r;
1510 ui_color[color_idx].g = rgb.g;
1511 ui_color[color_idx].b = rgb.b;
1512 return 0;
1513}
#define UI_COLORS
Definition ui_backend.h:193
UiColor * ui_color
STDRGB std_color[]
Definition ui_common.c:159
void ui_apply_gamma(RGB *rgb)
Apply gamma correction to RGB color.
Definition ui_common.c:941
uint32_t color
Definition ui_backend.h:310
uint8_t b
Definition ui_backend.h:308
uint8_t r
Definition ui_backend.h:308
uint8_t g
Definition ui_backend.h:308

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 548 of file ui_notcurses.c.

548 {
549 if (!stdplane)
550 return -1;
551 ncplane_erase_region(stdplane, 0, 0, 0, 0);
552 return 0;
553}
NcPlane * 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 1423 of file ui_notcurses.c.

1423 {
1424 if (color + 1 >= UI_COLORS)
1425 return -1;
1426 *r = ui_color[color].r;
1427 *g = ui_color[color].g;
1428 *b = ui_color[color].b;
1429 return 0;
1430}

◆ 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 1268 of file ui_notcurses.c.

1268 {
1269 uint i;
1270 RGB tmp;
1271 ui_apply_gamma(rgb);
1272 for (i = 0; i < ui_color_cnt && i < UI_COLORS; i++) {
1273 ui_color_content(i, &tmp.r, &tmp.g, &tmp.b);
1274 if (rgb->r == tmp.r && rgb->g == tmp.g && rgb->b == tmp.b)
1275 return i;
1276 }
1277 if (i < UI_COLORS) {
1278 if (i < 16) {
1279 std_color[i].r = rgb->r;
1280 std_color[i].g = rgb->g;
1281 std_color[i].b = rgb->b;
1282 }
1283 ui_init_color(i, rgb->r, rgb->g, rgb->b);
1284 if (ui_color_cnt + 1 < UI_COLORS)
1285 ui_color_cnt++;
1286 return ui_color_cnt - 1;
1287 }
1288 return -1;
1289}
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 985 of file ui_notcurses.c.

985 {
986 if (!ui)
987 return -1;
988 if (visible == 0) {
989 ui->cursor_visible = false;
990 notcurses_cursor_disable(ui->nc);
991 } else {
992 ui->cursor_visible = true;
993 int y, x;
994 notcurses_cursor_yx(ui->nc, &y, &x);
995 int rc = notcurses_cursor_enable(ui->nc, y, x);
996 return rc;
997 }
998 return 0;
999}
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 1037 of file ui_notcurses.c.

1037 {
1038 if (!s)
1039 return -1;
1040 if (!visible) {
1041 ui->cursor_visible = false;
1042 notcurses_cursor_disable(ui->nc);
1043 } else {
1044 uint y, x;
1045 ncplane_cursor_yx(s->mplane[w], &y, &x);
1046 int yy, xx;
1047 ncplane_abs_yx(s->mplane[w], &yy, &xx);
1048 y += yy;
1049 x += xx;
1050 ui->cursor_visible = true;
1051 return notcurses_cursor_enable(ui->nc, y, x) == 0 ? 0 : -1;
1052 }
1053 return 0;
1054}

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 1011 of file ui_notcurses.c.

1011 {
1012 if (!s)
1013 return -1;
1014 if (!visible) {
1015 ui->cursor_visible = false;
1016 notcurses_cursor_disable(ui->nc);
1017 } else {
1018 int yy, xx;
1019 ncplane_abs_yx(s->mplane[w], &yy, &xx);
1020 y += yy;
1021 x += xx;
1022 ui->cursor_visible = true;
1023 int rc = notcurses_cursor_enable(ui->nc, y, x);
1024 return rc;
1025 }
1026 return 0;
1027}

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 681 of file ui_notcurses.c.

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

Referenced by cf_accept(), display_line(), display_line_eod(), display_prompt(), display_split_line(), form_post(), form_process(), get_cmd_arg(), get_cmd_char(), 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 697 of file ui_notcurses.c.

697 {
698 notcurses_cursor_yx(ui->nc, y, x);
699}

References ui.

◆ ui_def_prog_mode()

void ui_def_prog_mode ( )

Definition at line 971 of file ui_notcurses.c.

971 {
972 return;
973}

◆ 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 410 of file ui_notcurses.c.

410 {
411 ui_shutdown();
412}
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 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}

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 61 of file ui_notcurses.c.

61 {
62 if (!caps)
63 return;
64 memset(caps, 0, sizeof(*caps));
65 if (!ui)
66 return;
67 // I don't know that it isn't truecolor
68 caps->truecolor = true;
69 caps->palette256 = true;
70 caps->mouse = ui->mouse_enabled;
71 caps->unicode = true;
72 caps->resize = true;
73 caps->color_pairs = 0;
74}
bool palette256
Definition ui_backend.h:458
bool mouse
Definition ui_backend.h:459
int color_pairs
Definition ui_backend.h:462
bool truecolor
Definition ui_backend.h:457
bool unicode
Definition ui_backend.h:460
bool resize
Definition ui_backend.h:461

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

◆ 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 1344 of file ui_notcurses.c.

1344 {
1345 uint fg, bg;
1346 // ui_channels is a struct that holds the foreground and background color
1347 // channels
1348 // use channels.fb to get the combined foreground and background color channels
1349 UiChannels ui_channels = {};
1350 ui_get_pair(pair, &fg, &bg);
1351 ui_color_content(fg, &ui_channels.f_r, &ui_channels.f_g, &ui_channels.f_b);
1352 ui_channels.f_a = 0x40;
1353 ui_channels.f_r = ui_color[fg].r;
1354 ui_channels.f_g = ui_color[fg].g;
1355 ui_channels.f_b = ui_color[fg].b;
1356 bg = ui_pair[pair].bg;
1357 ui_color_content(bg, &ui_channels.b_r, &ui_channels.b_g, &ui_channels.b_b);
1358 ui_channels.b_a = 0x40;
1359 ui_channels.b_r = ui_color[bg].r;
1360 ui_channels.b_g = ui_color[bg].g;
1361 ui_channels.b_b = ui_color[bg].b;
1362 return ui_channels.fb;
1363}
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:371
uint8_t f_b
Definition ui_backend.h:371
uint8_t b_r
Definition ui_backend.h:365
uint64_t fb
Definition ui_backend.h:376
uint8_t f_r
Definition ui_backend.h:371
uint8_t b_g
Definition ui_backend.h:365
uint8_t b_b
Definition ui_backend.h:365

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 1157 of file ui_notcurses.c.

1163 {
1164 (void)sfc;
1165 (void)w;
1166 if (!cell || !wstr || !style || !pair)
1167 return -1;
1168 GCluster gc;
1169 gc.u32 = cell->gcluster;
1170 *wstr = gc.w32;
1171 *style = cell->stylemask;
1172 // Convert the channels to a color pair index
1173 UiChannels channels;
1174 channels.fb = cell->channels;
1175 RGB rgb;
1176 rgb.r = channels.f_r;
1177 rgb.g = channels.f_g;
1178 rgb.b = channels.f_b;
1179 // If the color index does not exist, create a new one
1180 int fg = ui_color_from_rgb(&rgb);
1181 rgb.r = channels.b_r;
1182 rgb.g = channels.b_g;
1183 rgb.b = channels.b_b;
1184 // If the color index does not exist, create a new one
1185 int bg = ui_color_from_rgb(&rgb);
1186 // If the color pair does not exist, create a new one
1187 *pair = ui_add_pair(fg, bg);
1188 return 0;
1189}
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:122
uint32_t u32
Definition ui_backend.h:121
uint32_t gcluster
Definition ui_backend.h:381

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 1329 of file ui_notcurses.c.

1329 {
1330 *fg = ui_pair[pair].fg;
1331 *bg = ui_pair[pair].bg;
1332 return 0;
1333}

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 910 of file ui_notcurses.c.

910 {
911 if (!ui)
912 return;
913 unsigned int r = 0, c = 0;
914 notcurses_stddim_yx(ui->nc, &r, &c);
915 ui->lines = (int)r;
916 ui->cols = (int)c;
917 if (lines)
918 *lines = ui->lines;
919 if (cols)
920 *cols = ui->cols;
921}

References ui.

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 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 766 of file ui_notcurses.c.

766 {
767 if (!s)
768 return -1;
769 uint y, x;
770 ncplane_dim_yx(s->mplane[w], &y, &x);
771 return x;
772}

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 751 of file ui_notcurses.c.

751 {
752 if (!s)
753 return -1;
754 uint y, x;
755 ncplane_dim_yx(s->mplane[w], &y, &x);
756 return y;
757}

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 737 of file ui_notcurses.c.

737 {
738 if (!s)
739 return;
740 ncplane_dim_yx(s->mplane[w], y, x);
741}

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 723 of file ui_notcurses.c.

723 {
724 if (!s)
725 return;
726 ncplane_cursor_yx(s->mplane[w], y, x);
727}

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 1406 of file ui_notcurses.c.

1406 {
1407 RGB rgb;
1408 sscanf(s, "#%02hhX%02hhX%02hhX", &rgb.r, &rgb.g, &rgb.b);
1409 return rgb;
1410}

◆ 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 851 of file ui_notcurses.c.

851 {
852 (void)s;
853 (void)w;
854 (void)enable;
855 return 0;
856}

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 865 of file ui_notcurses.c.

865 {
866 (void)s;
867 (void)w;
868 (void)enable;
869 return 0;
870}

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 88 of file ui_notcurses.c.

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

References border_double, border_heavy, border_none, border_rounded, border_single, UiConfig::border_style, bw, f_ncurses_open, f_notcurses_open, UiConfig::log_level, sfc_ptr, stdplane, stdsfc, border_wide::str, SUB_SFC_MAX, ui, ui_color, ui_color_cnt, ui_initialize_sio(), ui_min_log_level, 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 1443 of file ui_notcurses.c.

1443 {
1444 if (color + 1 >= UI_COLORS)
1445 return -1;
1446 ui_color[color].r = r;
1447 ui_color[color].g = g;
1448 ui_color[color].b = b;
1449 return 0;
1450}

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 1374 of file ui_notcurses.c.

1374 {
1375 RGB rgb;
1376 rgb = ui_hex_to_rgb(s);
1377 ui_apply_gamma(&rgb);
1378 uint i;
1379 for (i = 0; i < ui_color_cnt && i < UI_COLORS; i++) {
1380 if (rgb.r == ui_color[i].r && rgb.g == ui_color[i].g && rgb.b == ui_color[i].b)
1381 return i;
1382 }
1383 if (i < UI_COLORS) {
1384 if (i < 16) {
1385 std_color[i].r = rgb.r;
1386 std_color[i].g = rgb.g;
1387 std_color[i].b = rgb.b;
1388 }
1389 ui_color[i].r = rgb.r;
1390 ui_color[i].g = rgb.g;
1391 ui_color[i].b = rgb.b;
1392 if (ui_color_cnt + 1 < UI_COLORS)
1393 ui_color_cnt++;
1394 return ui_color_cnt - 1;
1395 }
1396 return 0;
1397}
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 1481 of file ui_notcurses.c.

1481 {
1482 if (pair + 1 >= UI_PAIRS)
1483 return -1;
1484 ui_pair[pair].fg = fg;
1485 ui_pair[pair].bg = bg;
1486 return 0;
1487}

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 895 of file ui_notcurses.c.

895 {
896 (void)s;
897 (void)w;
898 (void)enable;
899 return 0;
900}

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 1562 of file ui_notcurses.c.

1562 {
1563 short cp;
1564 uint p1 = 0;
1565 uint *pos = &p1;
1566 if (p)
1567 pos = p;
1568 uint i = 0, len = 0;
1569 const char *s;
1570 attr_t style;
1571 UiCell cc;
1572 wchar_t wstr[5];
1573 ui_get_nccell(sfc, w, cell_base, &wstr[0], &style, &cp);
1574 mbstate_t mbstate;
1575 memset(&mbstate, 0, sizeof(mbstate));
1576 if (pos && *pos >= atmost - 1)
1577 return 0;
1578 while (str[i] != '\0') {
1579 s = &str[i];
1580 len = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
1581 if (len <= 0) {
1582 wstr[0] = L'?';
1583 wstr[1] = L'\0';
1584 len = 1;
1585 }
1586 wstr[1] = L'\0';
1587 if (*pos > atmost)
1588 break;
1589 if (ui_set_nccell(sfc, w, &cc, wstr, style, cp) != ERR) {
1590 if (len > 0 && (*pos + len) < atmost)
1591 cmplx_buf[(*pos)++] = cc;
1592 }
1593 i += len;
1594 }
1595 wstr[0] = L'\0';
1596 wstr[1] = L'\0';
1597 ui_set_nccell(sfc, w, &cc, wstr, style, cp);
1598 cmplx_buf[*pos] = cc;
1599 return *pos;
1600}
uint16_t attr_t
Definition ui_backend.h:417
#define ERR
Definition ui_backend.h:427
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 1523 of file ui_notcurses.c.

1523 {
1524 if (!ui)
1525 return NULL;
1526 return ui->nc;
1527}

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 1536 of file ui_notcurses.c.

1536 {
1537 (void)w;
1538 if (!s)
1539 return NULL;
1540 return s->mplane[w];
1541}

◆ 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 1462 of file ui_notcurses.c.

1462 {
1463 if (pair + 1 >= UI_PAIRS)
1464 return -1;
1465 *fg = ui_pair[pair].fg;
1466 *bg = ui_pair[pair].bg;
1467 return 0;
1468}

◆ 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 935 of file ui_notcurses.c.

935 {
936 if (!ui)
937 return;
938 notcurses_render(ui->nc);
939}

References ui.

Referenced by cf_accept(), display_form(), display_line(), display_pick_page(), field_editor(), form_display_accept_field(), form_display_field(), form_display_fields(), get_cmd_arg(), get_cmd_char(), init_pick(), main(), menu_cmd_processor(), menu_engine(), pad_refresh(), picker(), read_theme(), ui_draw_text_fill(), ui_get_event(), ui_restore_wins(), ui_surface_destroy(), ui_timeout_prompt(), ui_tracked_sfc_box(), ui_update_timeout_prompt(), view_boxwin_resize(), view_display_page(), 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 964 of file ui_notcurses.c.

964 {
965 if (!ui)
966 return -1;
967 notcurses_enter_alternate_screen(ui->nc);
968 notcurses_render(ui->nc);
969 return 0;
970}

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 837 of file ui_notcurses.c.

837 {
838 if (!s)
839 return -1;
840 ncplane_set_scrolling(s->mplane[w], enable);
841 return 0;
842}

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 1204 of file ui_notcurses.c.

1210 {
1211 if (!cell)
1212 return -1;
1213 uint32_t fg, bg;
1214 nccell_init(cell);
1215 GCluster gc;
1216 unicode_to_utf8_gcluster(*wstr, &gc);
1217 nccell_set_styles(cell, style);
1218 UiChannels *chan = (UiChannels *)&cell->channels;
1219 ui_get_pair(pair, &fg, &bg);
1220 ui_color_content(fg, &chan->f_r, &chan->f_g, &chan->f_b);
1221 chan->f_a = 0x40;
1222 ui_color_content(bg, &chan->b_r, &chan->b_g, &chan->b_b);
1223 chan->b_a = 0x40;
1224 nccell_load_egc32(sfc->mplane[w], cell, gc.u32);
1225 return 0;
1226}

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 880 of file ui_notcurses.c.

880 {
881 (void)s;
882 (void)w;
883 (void)top;
884 (void)bottom;
885 return 0;
886}

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 420 of file ui_notcurses.c.

420 {
421 if (ui == NULL)
422 return;
423 while (sfc_ptr >= 0) {
424 if (ui_surface[sfc_ptr]) {
425 ui_log(INFO, _("Destroying surface: %d"), sfc_ptr);
427 ui_surface[sfc_ptr] = NULL;
428 }
429 sfc_ptr--;
430 }
431 if (stdsfc->mplane[BOX]) {
432 ui_log(INFO, _("Destroying mplane[%d]"), BOX);
433 ncplane_erase(stdsfc->mplane[BOX]);
434 ncplane_destroy(stdsfc->mplane[BOX]);
435 stdsfc->mplane[BOX] = NULL;
436 }
437 if (ui->tty_fp) {
438 // fclose(ui->tty_fp);
439 // ui->tty_fp = NULL;
440 }
441 if (stdsfc != NULL) {
442 ui_log(INFO, _("Destroying stdsfc"));
443 free(stdsfc);
444 stdsfc = NULL;
445 }
446 ui_log(INFO, _("Calling notcurses_stop"));
447 notcurses_stop(ui->nc);
448 f_notcurses_open = false;
449 if (ui != NULL) {
450 if (ui_pair != NULL) {
451 ui_log(INFO, _("Destroying ui_pair"));
452 free(ui_pair);
453 ui_pair = NULL;
454 }
455 if (ui_color != NULL) {
456 ui_log(INFO, _("Destroying ui_color"));
457 free(ui_color);
458 ui_color = NULL;
459 }
460 if (ui->sio) {
461 ui_log(INFO, _("Destroying ui->sio"));
462 free(ui->sio);
463 ui->sio = nullptr;
464 }
465 if (ui != NULL) {
466 ui_log(INFO, _("Destroying ui"));
467 free(ui);
468 ui = NULL;
469 }
470 }
471}
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 w,
uint p,
uint lines,
uint cols,
uint y,
uint x )

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 333 of file ui_notcurses.c.

333 {
334 uint plines, pcols;
335 ncplane_dim_yx(s->mplane[p], &plines, &pcols);
336 pcols = min(pcols, cols);
337 plines = min(plines, lines);
338 ncplane_options plane_opts = {
339 .y = y,
340 .x = x,
341 .rows = plines - y,
342 .cols = pcols - x,
343 .name = NULL};
344 s->meta[w].y = y;
345 s->meta[w].x = x;
346 s->meta[w].lines = plines - y;
347 s->meta[w].cols = pcols - x;
348 s->meta[w].hidden = false;
349 s->mplane[w] = ncplane_create(s->mplane[p], &plane_opts);
350 if (!s->mplane[w]) {
351 ui_log(ERROR, _("failed to create mplane[%d]"), w);
352 notcurses_stop(ui->nc);
353 f_notcurses_open = false;
354 return -1;
355 }
356 ncplane_set_base(s->mplane[w], " ", 0, cell_nt.channels);
357 ncplane_set_channels(s->mplane[w], cell_nt.channels);
358 ui_bkgd(s, w, &cell_nt);
359 ui_bkgdset(s, w, &cell_nt);
360 ui_scrollok(s, w, true);
361 return 0;
362}
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:104
UiCell cell_nt
Definition ui_common.c:106
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_scrollok(UiSurface *s, ss_t w, bool enable)
Enable or disable scrolling 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 charac...
unsigned int y
Definition ui_backend.h:328
unsigned int lines
Definition ui_backend.h:330
unsigned int cols
Definition ui_backend.h:331
unsigned int x
Definition ui_backend.h:329

References cell_nt, f_notcurses_open, ui, ui_bkgd(), ui_bkgdset(), and ui_scrollok().

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,
uint 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 378 of file ui_notcurses.c.

378 {
379 ncplane_options plane_opts = {
380 .y = y,
381 .x = x,
382 .rows = lines,
383 .cols = cols,
384 .name = NULL};
385 s->meta[w].y = y;
386 s->meta[w].x = x;
387 s->meta[w].lines = lines;
388 s->meta[w].cols = cols;
389 s->meta[w].hidden = false;
390 s->mplane[w] = ncplane_create(s->mplane[p], &plane_opts);
391 if (!s->mplane[w]) {
392 ui_log(ERROR, _("failed to create mplane[%d]"), w);
393 notcurses_stop(ui->nc);
394 f_notcurses_open = false;
395 return -1;
396 }
397 ncplane_set_base(s->mplane[w], " ", 0, cell_nt.channels);
398 ncplane_set_channels(s->mplane[w], cell_nt.channels);
399 ui_bkgd(s, w, &cell_nt);
400 ui_bkgdset(s, w, &cell_nt);
401 return 0;
402}

References cell_nt, f_notcurses_open, ui, ui_bkgd(), and ui_bkgdset().

Referenced by init_view_boxwin(), init_view_full_screen(), 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_box()

UiSurface * ui_surface_box ( UiSurface * parent,
uint 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 279 of file ui_notcurses.c.

279 {
280 if (!ui)
281 return NULL;
282 UiSurface *s = calloc(1, sizeof(*s));
283 if (!s)
284 return NULL;
285 s->runtime = ui;
286 s->parent = parent;
287 ncplane_options plane_opts = {
288 .y = y,
289 .x = x,
290 .rows = lines,
291 .cols = cols,
292 .name = NULL};
293 s->meta[BOX].y = y;
294 s->meta[BOX].x = x;
295 s->meta[BOX].lines = lines + 2;
296 s->meta[BOX].cols = cols + 2;
297 s->meta[BOX].hidden = false;
298 strnz__cpy(s->meta[BOX].name, "BOX", XLEN - 1);
299 if (parent && parent->mplane[p]) {
300 s->mplane[BOX] = ncplane_create(parent->mplane[p], &plane_opts);
301 } else {
302 stdplane = notcurses_stdplane(ui->nc);
303 s->mplane[BOX] = ncplane_create(stdplane, &plane_opts);
304 }
305 if (!s->mplane[BOX]) {
306 free(s);
307 return NULL;
308 }
309 ncplane_set_base(s->mplane[BOX],
310 " ",
311 0,
312 cell_box.channels);
313 ncplane_set_channels(s->mplane[BOX], cell_box.channels);
315 ui_border_title(s, wtitle);
316 return s;
317}
int ui_border_draw(UiSurface *sfc)
Definition ui_common.c:474
int ui_border_title(UiSurface *sfc, const char *title)
Draw a box with a title around the specified window.
Definition ui_common.c:563
UiCell cell_box
Definition ui_common.c:110
#define XLEN
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition whence.c:291
char name[MAXLEN]
Definition ui_backend.h:334
struct UiSurface * parent
Definition ui_backend.h:356
struct UiRuntime * runtime
Definition ui_backend.h:355

References cell_box, em0, em1, em2, ssnprintf(), stdplane, strnz__cpy(), ui, ui_border_draw(), ui_border_title(), ui_display_error(), ui_get_screen_size(), 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 479 of file ui_notcurses.c.

479 {
480 if (!s)
481 return;
482 ss_t w = SUB_SFC_MAX;
483 while (1) {
484 if (s->mplane[w] != NULL) {
485 ui_log(INFO, _("Destroying mplane[%d]"), w);
486 ncplane_erase(s->mplane[w]);
487 ncplane_destroy(s->mplane[w]);
488 s->mplane[w] = NULL;
489 }
490 if (w == BOX)
491 break;
492 w--;
493 };
494 if (s != NULL) {
495 ui_log(INFO, _("Destroying surface: s"));
496 free(s);
497 s = NULL;
498 }
499}
ss_t
Definition ui_backend.h:45

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 641 of file ui_notcurses.c.

641 {
642 if (!s)
643 return -1;
644 if (!s->meta[w].hidden) {
645 s->meta[w].hidden = true;
646 /* Move far off-screen so the plane does not obscure anything. */
647 ncplane_move_yx(s->mplane[w], -s->meta[w].lines - 1, 0);
648 }
649 return 0;
650}

◆ 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 515 of file ui_notcurses.c.

515 {
516 if (!s)
517 return -1;
518 s->meta[w].y = y;
519 s->meta[w].x = x;
520 if (!s->meta[w].hidden)
521 return ncplane_move_yx(s->mplane[w], y, x) == 0 ? 0 : -1;
522 return 0;
523}

◆ ui_surface_new()

UiSurface * ui_surface_new ( ss_t w,
UiSurface * parent,
uint 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 224 of file ui_notcurses.c.

224 {
225 if (!ui)
226 return NULL;
227 UiSurface *s = calloc(1, sizeof(*s));
228 if (!s) {
229 ui_log(ERROR, "Failed to allocate memory for UiSurface\n");
230 return NULL;
231 }
232 ui_log(INFO, _("Memory allocated for new surface"));
233 s->runtime = ui;
234 s->parent = parent;
235 ncplane_options plane_opts = {
236 .y = y,
237 .x = x,
238 .rows = lines,
239 .cols = cols};
240 s->meta[w].y = y;
241 s->meta[w].x = x;
242 s->meta[w].lines = lines;
243 s->meta[w].cols = cols;
244 s->meta[w].hidden = false;
245 if (parent && parent->mplane[p]) {
246 s->mplane[w] = ncplane_create(parent->mplane[p], &plane_opts);
247 if (!s->mplane[w]) {
248 ui_log(ERROR, _("Failed to create mplane: %d"), w);
249 }
250 } else {
251 stdplane = notcurses_stdplane(ui->nc);
252 s->mplane[w] = ncplane_create(stdplane, &plane_opts);
253 if (!s->mplane[w]) {
254 ui_log(ERROR, _("Failed to create stdplane"));
255 }
256 }
257 ui_log(ERROR, _("mplane[%d] created"), w);
258 if (!s->mplane[w]) {
259 notcurses_stop(ui->nc);
260 f_notcurses_open = false;
261 return NULL;
262 }
263 return s;
264}

References em0, em1, em2, f_notcurses_open, ssnprintf(), stdplane, SUB_SFC_MAX, ui, ui_display_error(), and ui_get_screen_size().

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 534 of file ui_notcurses.c.

534 {
535 if (!s)
536 return -1;
537 return ncplane_resize_simple(s->mplane[w], (unsigned int)lines,
538 (unsigned int)cols) == 0
539 ? 0
540 : -1;
541}

◆ 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 623 of file ui_notcurses.c.

623 {
624 if (!s)
625 return -1;
626 if (s->meta[w].hidden) {
627 s->meta[w].hidden = false;
628 ncplane_move_yx(s->mplane[w], s->meta[w].y, s->meta[w].x);
629 }
630 return 0;
631}

◆ 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 949 of file ui_notcurses.c.

949 {
950 if (!ui)
951 return -1;
952 notcurses_leave_alternate_screen(ui->nc);
953 return 0;
954}

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 608 of file ui_notcurses.c.

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

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 926 of file ui_notcurses.c.

926 {
927 if (!ui)
928 return;
929 notcurses_render(ui->nc);
930}

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

◆ 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 578 of file ui_notcurses.c.

578 {
579 if (!s)
580 return -1;
581 ncplane_erase_region(s->mplane[w], 0, 0, 0, 0);
582 return 0;
583}

References SUB_SFC_MAX.

Referenced by exec_objects(), and full_screen_shell().

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 664 of file ui_notcurses.c.

664 {
665 if (!s)
666 return -1;
667 if (ncplane_cursor_move_yx(s->mplane[w], y, x) != 0)
668 return -1;
669 return 0;
670}

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 789 of file ui_notcurses.c.

789 {
790 uint rows, cols;
791 ncplane_dim_yx(s->mplane[w], &rows, &cols);
792
793 if (r > 0) {
794 // Scroll up (toward EOF): notcurses has this natively
795 ncplane_scrollup(s->mplane[w], r);
796 return 0;
797 }
798
799 // Scroll down (toward BOF): shift content down by |r| rows
800 r = -r;
801 if ((uint)r >= rows) {
802 ncplane_erase(s->mplane[w]);
803 return 0;
804 }
805
806 // Copy rows bottom-up to avoid overwriting source before reading
807 for (int src_row = (int)(rows - r) - 1; src_row >= 0; src_row--) {
808 int dst_row = src_row + r;
809 for (uint col = 0; col < cols; col++) {
810 nccell c = NCCELL_TRIVIAL_INITIALIZER;
811 ncplane_at_yx_cell(s->mplane[w], src_row, col, &c);
812 ncplane_putc_yx(s->mplane[w], dst_row, col, &c);
813 nccell_release(s->mplane[w], &c);
814 }
815 }
816 // Blank the top r rows
817 for (int row = 0; row < r; row++) {
818 for (uint col = 0; col < cols; col++) {
819 ncplane_putchar_yx(s->mplane[w], row, col, ' ');
820 }
821 }
822 return 0;
823}

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

Definition at line 37 of file ui_notcurses.c.

Referenced by ui_init(), ui_surface_box(), and ui_surface_new().

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