C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
ui_ncurses_internal.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7/** @file ui_ncurses_internal.h
8 @ingroup ui_ncurses
9 @brief Internal header for the NCurses UI backend.
10
11 This header defines the concrete (non-opaque) layouts of UiRuntime and
12 UiSurface for the NCurses backend. It must only be included by NCurses
13 backend source files — never by application code.
14*/
15
16#define _XOPEN_SOURCE_EXTENDED 1
17#define _GNU_SOURCE
18#define NCURSES_WIDECHAR 1
19#include <ncursesw/ncurses.h>
20#include <ncursesw/panel.h>
21#include <stdbool.h>
22#include <stdint.h>
23
24#define UIKEY_RESIZE KEY_RESIZE
25#define UIKEY_UP KEY_UP
26#define UIKEY_RIGHT KEY_RIGHT
27#define UIKEY_DOWN KEY_DOWN
28#define UIKEY_LEFT KEY_LEFT
29#define UIKEY_IC KEY_IC
30#define UIKEY_DC KEY_DC
31#define UIKEY_BACKSPACE KEY_BACKSPACE
32#define UIKEY_NPAGE KEY_NPAGE
33#define UIKEY_PPAGE KEY_PPAGE
34#define UIKEY_HOME KEY_HOME
35#define UIKEY_END KEY_END
36#define UIKEY_F01 KEY_F(1)
37#define UIKEY_F02 KEY_F(2)
38#define UIKEY_F03 KEY_F(3)
39#define UIKEY_F04 KEY_F(4)
40#define UIKEY_F05 KEY_F(5)
41#define UIKEY_F06 KEY_F(6)
42#define UIKEY_F07 KEY_F(7)
43#define UIKEY_F08 KEY_F(8)
44#define UIKEY_F09 KEY_F(9)
45#define UIKEY_F10 KEY_F(10)
46#define UIKEY_F11 KEY_F(11)
47#define UIKEY_F12 KEY_F(12)
48#define UIKEY_ENTER KEY_ENTER
49#define UIKEY_CLEAR KEY_CLEAR
50#define UIKEY_BEG KEY_BEG
51#define UIKEY_CANCEL KEY_CANCEL
52#define UIKEY_CLOSE KEY_CLOSE
53#define UIKEY_COMMAND KEY_COMMAND
54#define UIKEY_COPY KEY_COPY
55#define UIKEY_EXIT KEY_EXIT
56#define UIKEY_PRINT KEY_PRINT
57#define UIKEY_REFRESH KEY_REFRESH
58#define UIKEY_MOUSE KEY_MOUSE
59#define UIKEY_RSHIFT KEY_SRIGHT
60#define UIKEY_LSHIFT KEY_SLEFT
61
62#ifdef TO_BE_ADDED
63#define UIKEY_CAPS_LOCK KEY_CAPS_LOCK
64#define UIKEY_SCROLL_LOCK KEY_SCROLL_LOCK
65#define UIKEY_NUM_LOCK KEY_NUM_LOCK
66#define UIKEY_PRINT_SCREEN KEY_PRINT_SCREEN
67#define UIKEY_BUTTON1 KEY_BUTTON1
68#define UIKEY_BUTTON2 KEY_BUTTON2
69#define UIKEY_BUTTON3 KEY_BUTTON3
70#define UIKEY_MEDIA_PLAY KEY_MEDIA_PLAY
71#define UIKEY_MEDIA_PAUSE KEY_MEDIA_PAUSE
72#define UIKEY_MEDIA_PPAUSE KEY_MEDIA_PPAUSE
73#define UIKEY_MEDIA_REV KEY_MEDIA_REV
74#define UIKEY_MEDIA_STOP KEY_MEDIA_STOP
75#define UIKEY_MEDIA_FF KEY_MEDIA_FF
76#define UIKEY_MEDIA_REWIND KEY_MEDIA_REWIND
77#define UIKEY_MEDIA_NEXT KEY_MEDIA_NEXT
78#define UIKEY_MEDIA_PREV KEY_MEDIA_PREV
79#define UIKEY_MEDIA_RECORD KEY_MEDIA_RECORD
80#define UIKEY_MEDIA_LVOL KEY_MEDIA_LVOL
81#define UIKEY_MEDIA_RVOL KEY_MEDIA_RVOL
82#define UIKEY_MEDIA_MUTE KEY_MEDIA_MUTE
83#define UIKEY_EOF KEY_EOF
84#endif
85#define UIKEY_BTAB KEY_BTAB
86#define UIKEY_RETURN KEY_ENTER
87#define UIKEY_TAB 0x09
88#define UIKEY_ESCAPE 0x1B
89#define UIKEY_SPACE 0x20
90#define UIKEY_MOD_SHIFT 1
91#define UIKEY_MOD_ALT 2
92#define UIKEY_MOD_CTRL 4
93#define UIKEY_MOD_SUPER 8
94#define UIKEY_MOD_HYPER 16
95#define UIKEY_MOD_META 32
96#define UIKEY_MOD_CAPSLOCK 64
97#define UIKEY_MOD_NUMLOCK 128
98#define UIKEY_NONE 0700
99#define UIKEY_CHAR 0703
100
101#define UIKEY_SCROLL_UP BUTTON4_PRESSED
102#define UIKEY_SCROLL_DOWN BUTTON5_PRESSED
103#define UIKEY_BUTTON1_CLICKED BUTTON1_CLICKED
104#define UIKEY_BUTTON1_PRESSED BUTTON1_PRESSED
105#define UIKEY_BUTTON1_RELEASED BUTTON1_RELEASED
106#define UIKEY_BUTTON2_CLICKED BUTTON2_CLICKED
107#define UIKEY_BUTTON2_PRESSED BUTTON2_PRESSED
108#define UIKEY_BUTTON2_RELEASED BUTTON2_RELEASED
109#define UIKEY_BUTTON3_CLICKED BUTTON3_CLICKED
110#define UIKEY_BUTTON3_PRESSED BUTTON3_PRESSED
111#define UIKEY_BUTTON3_RELEASED BUTTON3_RELEASED
112#define UIKEY_BUTTON4_CLICKED BUTTON4_CLICKED
113#define UIKEY_BUTTON4_PRESSED BUTTON4_PRESSED
114#define UIKEY_BUTTON4_RELEASED BUTTON4_RELEASED
115#define UIKEY_BUTTON5_CLICKED BUTTON5_CLICKED
116#define UIKEY_BUTTON5_PRESSED BUTTON5_PRESSED
117#define UIKEY_BUTTON5_RELEASED BUTTON5_RELEASED
118#define UIKEY_BUTTON1 0730
119#define UIKEY_BUTTON2 0731
120#define UIKEY_BUTTON3 0732
121#define UIKEY_BUTTON4 0733
122#define UIKEY_BUTTON5 0734
123#define UIKEY_SIGNAL 0737
124#define UIKEY_STREAM_DATA 0740
125#define UIKEY_TIMEOUT 0741
126
127#define UI_MASK WA_ATTRIBUTES
128#define UI_NORMAL WA_NORMAL
129#define UI_STANDOUT WA_STANDOUT
130#define UI_UNDERLINE WA_UNDERLINE
131#define UI_REVERSE WA_REVERSE
132#define UI_BLINK WA_BLINK
133#define UI_DIM WA_DIM
134#define UI_BOLD WA_BOLD
135#define UI_ALTCHARSET WA_ALTCHARSET
136#define UI_INVIS WA_INVIS
137#define UI_PROTECT WA_PROTECT
138#define UI_UNDERCURL WA_DIM
139#define UI_STRUCK WA_INVIS
140#define UI_NONE WA_NORMAL
141#define UI_ITALIC WA_ITALIC
142
143#ifdef __cplusplus
144}
145#endif
int ui_border_draw(UiSurface *sfc)
Definition ui_common.c:474
int ui_surface_resize(UiSurface *s, ss_t w, uint lines, uint cols)
Resize a UiSurface to new dimensions.
Definition ui_ncurses.c:536
int ui_surface_addwin(UiSurface *s, ss_t w, uint p, uint lines, uint cols, uint y, uint x)
Add a new window to the specified UiSurface.
Definition ui_ncurses.c:395
const wchar_t * border_none
Definition ui_common.c:72
UiRuntime * ui_init(const UiConfig *config, SIO *sio)
Initialize the UI runtime with the given configuration and SIO.
Definition ui_ncurses.c:129
void ui_render()
Render the UI by updating panels and refreshing the display.
Definition ui_ncurses.c:884
void ui_getyx(UiSurface *s, ss_t w, uint *lines, uint *cols)
Get the current cursor position within a window of a UI surface.
Definition ui_ncurses.c:675
UiCell cell_nt
Definition ui_common.c:106
bool f_ncurses_open
Definition ui_common.c:50
char em1[MAXLEN]
Definition ui_common.c:47
int ui_setscrreg(UiSurface *s, ss_t w, uint top, uint bottom)
Set the scrolling region for a UiSurface.
Definition ui_ncurses.c:820
int ui_wmove(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
Definition ui_ncurses.c:653
void ui_getmaxyx(UiSurface *s, ss_t w, uint *lines, uint *cols)
Get the maximum dimensions of a UiSurface.
Definition ui_ncurses.c:690
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 within a UiSurface.
Definition ui_ncurses.c:855
char em2[MAXLEN]
Definition ui_common.c:48
int ui_wscrl(UiSurface *s, ss_t w, int rows)
Scroll the contents of a UiSurface by a specified number of lines.
Definition ui_ncurses.c:738
int ui_idcok(UiSurface *s, ss_t w, bool enable)
Enable or disable the use of the insert/delete character capabilities for a UiSurface.
Definition ui_ncurses.c:803
int ui_surface_addpad(UiSurface *s, ss_t w, uint view_win, uint lines, uint cols, uint begy, uint begx)
Add a new pad to the specified UiSurface.
Definition ui_ncurses.c:369
BorderWide bw
Definition ui_common.c:27
int ui_cursor_move(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
Definition ui_ncurses.c:666
#define UI_SFC_MAX
Definition ui_backend.h:196
#define UI_PAIRS
Definition ui_backend.h:194
int ui_suspend()
Suspend the UI, saving the current program state and ending the window session.
Definition ui_ncurses.c:494
void ui_surface_destroy(UiSurface *s)
Destroy a UiSurface, cleaning up its windows and panels.
Definition ui_ncurses.c:468
@ SUB_SFC_MAX
Definition ui_backend.h:47
int ui_border_title(UiSurface *sfc, const char *title)
Draw a box with a title around the specified window.
Definition ui_common.c:563
void ui_update_panels()
Update the panels in the UI.
Definition ui_ncurses.c:890
int ui_bkgd(UiSurface *s, ss_t w, const UiCell *cell)
Set the background of a specific window within a UiSurface.
Definition ui_ncurses.c:927
#define ERR
Definition ui_backend.h:427
int ui_idlok(UiSurface *s, ss_t w, bool enable)
Enable or disable the use of the insert/delete line capabilities for a UiSurface.
Definition ui_ncurses.c:787
const wchar_t * border_double
Definition ui_common.c:69
int ui_surface_move(UiSurface *s, ss_t w, uint y, uint x)
Move a UiSurface to a new position on the screen.
Definition ui_ncurses.c:521
int ui_getmaxy(UiSurface *s, ss_t w)
Get the maximum number of lines (rows) of a UiSurface.
Definition ui_ncurses.c:701
UiSurface * ui_surface_box(UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x, const char *title)
Create a new UI surface with a border box and optional title.
Definition ui_ncurses.c:288
const wchar_t * border_single
Definition ui_common.c:68
void ui_get_screen_size(uint *lines, uint *cols)
Get the current screen size (number of lines and columns).
Definition ui_ncurses.c:722
int ui_surface_show(UiSurface *s, ss_t w)
Show a UiSurface, making it visible on the screen.
Definition ui_ncurses.c:609
int ui_erase()
Erase the entire screen.
Definition ui_ncurses.c:591
void ui_shutdown()
Shutdown the UI runtime, cleaning up resources and freeing memory.
Definition ui_ncurses.c:418
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.
Definition ui_ncurses.c:229
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
int ui_curs_set(int visibility)
Set the visibility of the cursor.
Definition ui_ncurses.c:840
int ui_resume()
Resume the UI, restoring the previous program state and updating the display.
Definition ui_ncurses.c:503
int ui_bkgrndset(UiSurface *s, ss_t w, const UiCell *cell)
Set the background for new content to be written to a specific window within a UiSurface.
Definition ui_ncurses.c:969
int ui_top_surface(UiSurface *s, ss_t w)
Hide a UiSurface, making it invisible on the screen.
Definition ui_ncurses.c:623
int ui_wclear(UiSurface *s, ss_t w)
Clear the contents of a UiSurface or all surfaces.
Definition ui_ncurses.c:571
char em0[MAXLEN]
Definition ui_common.c:46
void ui_endwin()
End the UI application, cleaning up resources and shutting down the UI runtime.
Definition ui_ncurses.c:412
int ui_cursor_enable(UiSurface *s, ss_t w, bool visible)
Enable or disable the cursor for a UiSurface.
Definition ui_ncurses.c:870
int ui_clear()
Clear the entire screen.
Definition ui_ncurses.c:599
int ui_getmaxx(UiSurface *s, ss_t w)
Get the maximum number of columns of a UiSurface.
Definition ui_ncurses.c:712
const wchar_t * border_heavy
Definition ui_common.c:71
int ui_surface_hide(UiSurface *s, ss_t w)
Hide a UiSurface, making it invisible on the screen.
Definition ui_ncurses.c:635
bool f_notcurses_open
Definition ui_common.c:51
const wchar_t * border_rounded
Definition ui_common.c:70
int ui_bkgrnd(UiSurface *s, ss_t w, const UiCell *cell)
Set the background of a specific window within a UiSurface.
Definition ui_ncurses.c:955
int ui_scrollok(UiSurface *s, ss_t w, bool enable)
Enable or disable scrolling for a UiSurface.
Definition ui_ncurses.c:755
int ui_wnoutrefresh(UiSurface *s, ss_t w)
Refresh a specific window within a UiSurface.
Definition ui_ncurses.c:908
#define UI_COLORS
Definition ui_backend.h:193
void ui_get_caps(UiCaps *caps)
Get the UI backend capabilities.
Definition ui_ncurses.c:62
int ui_bkgdset(UiSurface *s, ss_t w, const UiCell *cell)
Set the background for new content to be written to a specific window within a UiSurface.
Definition ui_ncurses.c:941
int ui_doupdate()
Refresh the display by updating the screen.
Definition ui_ncurses.c:895
int ui_werase(UiSurface *s, ss_t w)
Erase the contents of a UiSurface or all surfaces.
Definition ui_ncurses.c:551
@ UI_BACKEND_NCURSES
Definition ui_backend.h:452
#define ALLWINS
Definition ui_backend.h:195
int ui_keypad(UiSurface *s, ss_t w, bool enable)
Enable or disable the keypad for a UiSurface.
Definition ui_ncurses.c:771
#define WA_NORMAL
#define WA_ATTRIBUTES
#define WA_BLINK
#define WA_PROTECT
#define WA_ITALIC
#define WA_DIM
#define WA_INVIS
#define WA_BOLD
#define WA_REVERSE
#define WA_STANDOUT
#define WA_UNDERLINE
#define WA_ALTCHARSET
STDRGB std_color[]
Definition ui_common.c:159
UiLogLevel ui_min_log_level
Definition ui_common.c:1390
void ui_apply_gamma(RGB *rgb)
Apply gamma correction to RGB color.
Definition ui_common.c:941
int ui_setcchar(UiCell *cell, const wchar_t *wstr, const attr_t attrs, short pair, const void *opts)
Set the character and attributes of a UiCell.
uint ui__mbstr_to_cellstr(UiCell *cmplx_buf, const char *str, const UiCell *cell_base, uint *p, const uint atmost)
int ui_chg_pair(uint pair, uint fg, uint bg)
Change the foreground and background colors of an existing color pair.
int ui_pair_content(uint pair, uint *fg, uint *bg)
Get the foreground and background colors of a specified color pair.
SCREEN * ui_ncurses_get_screen()
Get the current SCREEN pointer used by the UI.
int ui_getcchar(const UiCell *cell, wchar_t *wstr, attr_t *attrs, short *pair, const void *opts)
Get the character and attributes from a UiCell.
Definition ui_ncurses.c:987
int ui_init_color(uint color, uint r, uint g, uint b)
Initialize a color in the curses color table with specified RGB values.
int ui_init_pair(uint pair, uint fg, uint bg)
Initialize a color pair in the curses color table with specified foreground and background colors.
uint ui_add_pair(uint fg, uint bg)
Add a new color pair to the UI, or retrieve the index of an existing pair.
UiSurface * ui_surface[UI_SFC_MAX]
Definition ui_ncurses.c:40
uint32_t ui_get_color(uint16_t color_idx)
Get the RGB color value for a given color index.
int ui_color_content(uint color, uint *r, uint *g, uint *b)
void fast_exit(UiSurface *s)
Exit the UI application quickly, cleaning up resources.
Definition ui_ncurses.c:339
UiRuntime * ui
Definition ui_ncurses.c:39
RGB ui_hex_to_rgb(char *s)
Convert a hexadecimal color string to an RGB structure.
int ui_pair_from_hex(const char *fg, const char *bg)
Convert hex color strings to a curses color pair index.
Definition ui_ncurses.c:86
WINDOW * ui_ncurses_surface_get_win(const UiSurface *s, ss_t w)
Get the current FILE pointer for the TTY used by the UI.
void ui_destroy_curses()
UiCell ui_cell_from_ucp(const wchar_t *ucp, const uint32_t *fg, const uint32_t *bg)
Convert a Unicode code point to a curses UiCell with specified foreground and background colors.
Definition ui_ncurses.c:101
uint ui_pair_cnt
Definition ui_ncurses.c:44
PANEL * ui_ncurses_surface_get_panel(const UiSurface *s, ss_t w)
Get the current PANEL pointer for a specific window within a UiSurface.
uint ui_color_cnt
Definition ui_ncurses.c:43
void ui_def_prog_mode()
Definition ui_ncurses.c:826
int ui_color_from_rgb(RGB *rgb)
Convert RGB to curses color index, adding new color if necessary.
int ui_chg_color(uint16_t color_idx, uint32_t *color)
Change the RGB color value for a given color index.
#define TRUE
Definition iloan.c:31
#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
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:57
void sig_dfl_mode()
Set signal handlers to default behavior.
Definition sig.c:41
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
UiBackend ui_get_backend()
Get the UI backend type.
Definition ui_ncurses.c:55
UiBorderStyle border_style
Definition ui_backend.h:445
UiLogLevel log_level
Definition ui_backend.h:447
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
wchar_t str[11]
Definition ui_backend.h:563