8
9
10
11
12
13
14
16#define _XOPEN_SOURCE_EXTENDED 1
18#define NCURSES_WIDECHAR 1
19#include <ncursesw/ncurses.h>
20#include <ncursesw/panel.h>
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
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
85#define UIKEY_BTAB KEY_BTAB
86#define UIKEY_RETURN KEY_ENTER
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
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
int ui_border_draw(UiSurface *sfc)
int ui_surface_resize(UiSurface *s, ss_t w, uint lines, uint cols)
Resize a UiSurface to new dimensions.
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.
const wchar_t * border_none
UiRuntime * ui_init(const UiConfig *config, SIO *sio)
Initialize the UI runtime with the given configuration and SIO.
void ui_render()
Render the UI by updating panels and refreshing the display.
void ui_getyx(UiSurface *s, ss_t w, uint *lines, uint *cols)
Get the current cursor position within a window of a UI surface.
int ui_setscrreg(UiSurface *s, ss_t w, uint top, uint bottom)
Set the scrolling region for a UiSurface.
int ui_wmove(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
void ui_getmaxyx(UiSurface *s, ss_t w, uint *lines, uint *cols)
Get the maximum dimensions of a UiSurface.
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.
int ui_wscrl(UiSurface *s, ss_t w, int rows)
Scroll the contents of a UiSurface by a specified number of lines.
int ui_idcok(UiSurface *s, ss_t w, bool enable)
Enable or disable the use of the insert/delete character capabilities for a UiSurface.
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.
int ui_cursor_move(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
int ui_suspend()
Suspend the UI, saving the current program state and ending the window session.
void ui_surface_destroy(UiSurface *s)
Destroy a UiSurface, cleaning up its windows and panels.
int ui_border_title(UiSurface *sfc, const char *title)
Draw a box with a title around the specified window.
void ui_update_panels()
Update the panels in the UI.
int ui_bkgd(UiSurface *s, ss_t w, const UiCell *cell)
Set the background of a specific window within a UiSurface.
int ui_idlok(UiSurface *s, ss_t w, bool enable)
Enable or disable the use of the insert/delete line capabilities for a UiSurface.
const wchar_t * border_double
int ui_surface_move(UiSurface *s, ss_t w, uint y, uint x)
Move a UiSurface to a new position on the screen.
int ui_getmaxy(UiSurface *s, ss_t w)
Get the maximum number of lines (rows) of a UiSurface.
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.
const wchar_t * border_single
void ui_get_screen_size(uint *lines, uint *cols)
Get the current screen size (number of lines and columns).
int ui_surface_show(UiSurface *s, ss_t w)
Show a UiSurface, making it visible on the screen.
int ui_erase()
Erase the entire screen.
void ui_shutdown()
Shutdown the UI runtime, cleaning up resources and freeing memory.
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.
void ui_initialize_sio(SIO *sio)
int ui_curs_set(int visibility)
Set the visibility of the cursor.
int ui_resume()
Resume the UI, restoring the previous program state and updating the display.
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.
int ui_top_surface(UiSurface *s, ss_t w)
Hide a UiSurface, making it invisible on the screen.
int ui_wclear(UiSurface *s, ss_t w)
Clear the contents of a UiSurface or all surfaces.
void ui_endwin()
End the UI application, cleaning up resources and shutting down the UI runtime.
int ui_cursor_enable(UiSurface *s, ss_t w, bool visible)
Enable or disable the cursor for a UiSurface.
int ui_clear()
Clear the entire screen.
int ui_getmaxx(UiSurface *s, ss_t w)
Get the maximum number of columns of a UiSurface.
const wchar_t * border_heavy
int ui_surface_hide(UiSurface *s, ss_t w)
Hide a UiSurface, making it invisible on the screen.
const wchar_t * border_rounded
int ui_bkgrnd(UiSurface *s, ss_t w, const UiCell *cell)
Set the background of a specific window within a UiSurface.
int ui_scrollok(UiSurface *s, ss_t w, bool enable)
Enable or disable scrolling for a UiSurface.
int ui_wnoutrefresh(UiSurface *s, ss_t w)
Refresh a specific window within a UiSurface.
void ui_get_caps(UiCaps *caps)
Get the UI backend capabilities.
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.
int ui_doupdate()
Refresh the display by updating the screen.
int ui_werase(UiSurface *s, ss_t w)
Erase the contents of a UiSurface or all surfaces.
int ui_keypad(UiSurface *s, ss_t w, bool enable)
Enable or disable the keypad for a UiSurface.
UiLogLevel ui_min_log_level
void ui_apply_gamma(RGB *rgb)
Apply gamma correction to RGB color.
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.
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]
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.
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.
WINDOW * ui_ncurses_surface_get_win(const UiSurface *s, ss_t w)
Get the current FILE pointer for the TTY used by the UI.
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.
PANEL * ui_ncurses_surface_get_panel(const UiSurface *s, ss_t w)
Get the current PANEL pointer for a specific window within a UiSurface.
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.
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
void sig_dfl_mode()
Set signal handlers to default behavior.
int ui_display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
UiBackend ui_get_backend()
Get the UI backend type.
UiBorderStyle border_style