C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
Window Support

Manage NCurses windows and color settings. More...

Functions

int bare_box_new (int wlines, int wcols, int wbegy, int wbegx, char *wtitle)
 Create a new window with optional box and title.
int border_hsplit (WINDOW *box, int y)
 Draw a box with a separator line around the specified window.
int border_hsplit_text (WINDOW *box, char *text, int separator_line)
 Draw a box with a separator line and text around the specified window.
int border_title (WINDOW *box, char *title)
 Draw a box with a title around the specified window.
int box_hsplit_new (int wlines, int split_win_lines, int wcols, int wbegy, int wbegx, char *wtitle)
 Create a new window with optional box and title, and a second window inside it, split horizontally.
int box_new (int wlines, int wcols, int wbegy, int wbegx, char *wtitle)
 Create a new window with optional box and title.
void check_panels (int i)
 Check and display the panels for a given window index.
void destroy_curses ()
 Gracefully shut down NCurses and restore terminal settings.
int dxwgetch (WINDOW *win_0, WINDOW *win_1, WINDOW *win_2, WINDOW *win_3, WINDOW *win_c, Chyron *chyron, int n)
 Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line, and accepts a sinigle character answer.
void mvwaddstr_fill (WINDOW *w, int y, int x, char *s, int l)
 For lines shorter than their display area, fill the rest with spaces.
bool open_curses (SIO *sio)
 Initialize NCurses and color settings.
void restore_wins ()
 Restore all windows after a screen resize.
int vgetch (WINDOW *win, int n)
 Wrapper for wgetch that handles signals and mouse events, and accepts a single character answer.
void view_boxwin_resize (Init *init)
 Resize the current window and its box.
void view_full_screen_resize (Init *init)
 Resize the full screen view and its components.
int win2_box_new (int wlines, int wcols, int wbegy, int wbegx, char *wtitle)
 Create a new window with optional box and title, and a second window inside it.
int win2_new (int wlines, int wcols, int wbegy, int wbegx)
 Create a new subwindow (win2) with specified dimensions and position.
void win_del ()
 Delete the current window and its associated box window.
void win_init_attrs ()
 Initialize window attributes.
int win_new (int wlines, int wcols)
 Create a new window with specified dimensions and position.
void win_redraw (WINDOW *win)
 Redraw the specified window.
void win_resize (int wlines, int wcols, char *title)
 Resize the current window and its box, and update the title.
int xwgetch (WINDOW *win, Chyron *chyron, int n)
 Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line, and accepts a sinigle character answer.

Detailed Description

Manage NCurses windows and color settings.

Function Documentation

◆ bare_box_new()

int bare_box_new ( int wlines,
int wcols,
int wbegy,
int wbegx,
char * wtitle )

Create a new window with optional box and title.

box_new

Parameters
wlinesNumber of lines
wcolsNumber of columns
wbegyBeginning Y position
wbegxBeginning X position
wtitleWindow title
Returns
0 if successful, 1 if error

Definition at line 981 of file dwin.c.

981 {
982 int maxy, maxx;
983 if (win_ptr >= MAXWIN) {
984 Perror("Maximum number of windows (%d) exceeded");
985 exit(EXIT_FAILURE);
986 }
987#ifdef NCURSES_UI
988 getmaxyx(stdscr, maxy, maxx);
989#else
990 ui_get_screen_size(ui_runtime, &maxy, &maxx);
991#endif
992 wlines = min(wlines, maxy - 2);
993 wcols = min(wcols, maxx - 2);
994 win_ptr++;
995 // -------------------> win_box <-------------------
996#ifdef UAL_UI
997 ui_rect_set(&ui_rect, wbegy, wbegx, wlines + 2, wcols + 2);
999 win_box[win_ptr] = ui_box[win_ptr]->win;
1001
1002 UiStyle *ui_style = ui_style_from_cch(&CC_BOX);
1003 ui_bkgrnd(ui_box[win_ptr], ui_style, " "); // flood fill_char
1004 ui_bkgrnd_set(ui_box[win_ptr], ui_style, " "); // like wattron
1005 wborder_set(win_box[win_ptr], &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br);
1006 border_title(win_box[win_ptr], wtitle);
1007
1008 ui_rect_set(&ui_rect, 1, 1, wlines, wcols);
1010 ui_style = ui_style_from_cch(&CC_NT);
1011 ui_bkgrnd(ui_win[win_ptr], ui_style, " "); // flood fill_char
1012 ui_bkgrnd_set(ui_win[win_ptr], ui_style, " "); // like wattron
1013 win_win[win_ptr] = ui_win[win_ptr]->win;
1015 mvwaddstr(win_win[win_ptr], 10, 1, "Hello!");
1016
1017#else
1018 win_box[win_ptr] = newwin(wlines + 2, wcols + 2, wbegy, wbegx);
1019 if (win_box[win_ptr] == nullptr) {
1020 Perror("win_box[win_ptr] = newwin() failed");
1021 exit(EXIT_FAILURE);
1022 }
1023 panel_box[win_ptr] = new_panel(win_box[win_ptr]);
1024 wbkgrnd(win_box[win_ptr], &CC_BOX);
1025 wbkgrndset(win_box[win_ptr], &CC_BOX);
1027 border_title(win_box[win_ptr], wtitle);
1028#endif
1029 return 0;
1030}
#define MAXWIN
Definition cm.h:37
WINDOW * win_win[MAXWIN]
Definition dwin.c:52
cchar_t tl
Definition cm.h:501
cchar_t br
Definition cm.h:501
cchar_t CC_NT
Definition dwin.c:204
cchar_t rs
Definition cm.h:501
cchar_t CC_BOX
Definition dwin.c:199
cchar_t bl
Definition cm.h:501
PANEL * panel_win[MAXWIN]
Definition dwin.c:56
int win_ptr
Definition dwin.c:164
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:89
cchar_t ts
Definition cm.h:501
PANEL * panel_box[MAXWIN]
Definition dwin.c:57
cchar_t tr
Definition cm.h:501
cchar_t ls
Definition cm.h:631
WINDOW * win_box[MAXWIN]
Definition dwin.c:53
cchar_t bs
Definition cm.h:501
int ui_bkgrnd(UiSurface *, const UiStyle *, const char *)
Definition ui_ncurses.c:330
int ui_bkgrnd_set(UiSurface *, const UiStyle *, const char *)
Definition ui_ncurses.c:338
UiStyle * ui_style_from_cch(const cchar_t *)
Definition ui_ncurses.c:345
UiSurface * ui_box[MAXWIN]
Definition dwin.c:46
int border_draw(WINDOW *)
Definition dwin.c:1236
UiRuntime * ui_runtime
Definition dwin.c:44
UiRect ui_rect
Definition dwin.c:49
UiSurface * ui_win[MAXWIN]
Definition dwin.c:47
int border_title(WINDOW *box, char *title)
Draw a box with a title around the specified window.
Definition dwin.c:1327
int Perror(char *)
Display a simple error message window or print to stderr.
Definition dwin.c:1526
void ui_rect_set(UiRect *, int, int, int, int)
Set the properties of a UiRect structure.
Definition dwin.c:908
UiSurface * ui_surface_new(UiRuntime *ui, UiSurface *parent, UiRect rect)
Create a new UI surface.
Definition ui_ncurses.c:37
void ui_get_screen_size(UiRuntime *ui, int *rows, int *cols)
Get the current screen size.
Definition ui_ncurses.c:257
Structure representing the style attributes for UI elements.
Definition ui_backend.h:158

References border_draw(), border_title(), CC_BOX, panel_box, Perror(), ui_get_screen_size(), ui_runtime, win_box, and win_ptr.

Referenced by box_hsplit_new(), box_new(), and win2_box_new().

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

◆ border_hsplit()

int border_hsplit ( WINDOW * box,
int y )

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

border-hsplit

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

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

Definition at line 1269 of file dwin.c.

1269 {
1270 int maxx = getmaxx(box);
1271 mvwaddnwstr(box, y, 0, &bw_lt, 1);
1272 for (int x = 1; x < maxx - 1; x++)
1273 waddnwstr(box, &bw_ho, 1);
1274 mvwaddnwstr(box, y, maxx - 1, &bw_rt, 1);
1275 return 0;
1276}
const wchar_t bw_rt
Definition dwin.c:145
const wchar_t bw_ho
Definition dwin.c:138
const wchar_t bw_lt
Definition dwin.c:144

References bw_ho, bw_lt, and bw_rt.

Referenced by box_hsplit_new().

Here is the caller graph for this function:

◆ border_hsplit_text()

int border_hsplit_text ( WINDOW * box,
char * text,
int separator_line )

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

border_hsplit_text

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

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

Definition at line 1289 of file dwin.c.

1289 {
1290 int pos = 0;
1291 int maxx = getmaxx(box);
1292 int l;
1293 int y = separator_line;
1294 int x = 0;
1295 // Clearly, this is a bit hacky, but it works. We want to draw the
1296 // horizontal line with text in the middle, so we start by drawing the left
1297 // edge, then the text, then the right edge, and finally fill in the
1298 // horizontal line on either side of the text. mvwadd_wchnstr(box, y, x++,
1299 // &lt, 1);
1300 mvwadd_wchnstr(box, y, x++, &lt, 1);
1301 mvwadd_wchnstr(box, y, x++, &ts, 1);
1302 mvwadd_wchnstr(box, y, x++, &rt, 1);
1303 mvwadd_wchnstr(box, y, x++, &sp, 1);
1304 strnz(text, maxx - 7);
1305 cchar_t text_cc[MAXLEN] = {0};
1306 l = mb_to_cc(text_cc, text, WA_NORMAL, cp_box, &pos, MAXLEN - 1);
1307 mvwadd_wchnstr(box, y, x, text_cc, l);
1308 x += l;
1309 mvwadd_wchnstr(box, y, x++, &sp, 1);
1310 mvwadd_wchnstr(box, y, x++, &lt, 1);
1311
1312 while (x < maxx - 1)
1313 mvwadd_wchnstr(box, y, x++, &ts, 1);
1314 mvwadd_wchnstr(box, y, x++, &rt, 1);
1315 return 0;
1316}
int cp_box
Definition dwin.c:179
cchar_t lt
Definition cm.h:631
cchar_t sp
Definition cm.h:631
cchar_t rt
Definition cm.h:631
#define MAXLEN
Definition curskeys.c:15
int mb_to_cc(cchar_t *, char *, attr_t, int, int *, int)
Convert multibyte string to complex character array.
Definition dwin.c:705
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:615

References cp_box, lt, mb_to_cc(), rt, sp, strnz(), and ts.

Referenced by picker().

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

◆ border_title()

int border_title ( WINDOW * box,
char * title )

Draw a box with a title around the specified window.

border_title

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

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

Definition at line 1327 of file dwin.c.

1327 {
1328 int pos = 0;
1329 int maxx = getmaxx(box);
1330 int y = 0;
1331 int x = 0;
1332 int l;
1333 mvwadd_wchnstr(box, y, x++, &tl, 1); // top left
1334 mvwadd_wchnstr(box, y, x++, &rt, 1); // right tee
1335 mvwadd_wchnstr(box, y, x++, &sp, 1); // space
1336 cchar_t title_cc[MAXLEN] = {0};
1337 l = mb_to_cc(title_cc, title, WA_NORMAL, cp_title, &pos, MAXLEN - 1);
1338 l = min(l, maxx - 7);
1339 mvwadd_wchnstr(box, y, x, title_cc, l);
1340 x += l;
1341 mvwadd_wchnstr(box, y, x++, &sp, 1); // space
1342 mvwadd_wchnstr(box, y, x++, &lt, 1); // left tee
1343 while (x < maxx - 1)
1344 mvwadd_wchnstr(box, y, x++, &ts, 1); // horizontal line
1345 return 0;
1346}
int cp_title
Definition dwin.c:182

References cp_title, lt, mb_to_cc(), rt, sp, tl, and ts.

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

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

◆ box_hsplit_new()

int box_hsplit_new ( int wlines,
int split_win_lines,
int wcols,
int wbegy,
int wbegx,
char * wtitle )

Create a new window with optional box and title, and a second window inside it, split horizontally.

box_hsplit_new

Parameters
wlinesNumber of lines for the first window
split_win_linesNumber of lines for the second window
wcolsNumber of columns for the first window
wbegyBeginning Y position for the first window
wbegxBeginning X position for the first window
wtitleWindow title for the first window
Returns
0 if successful, 1 if error

Definition at line 925 of file dwin.c.

925 {
926 if (win_ptr >= MAXWIN) {
927 Perror("Maximum number of windows (%d) exceeded");
928 exit(EXIT_FAILURE);
929 }
930 wlines = min(wlines, LINES - 2);
931 wcols = min(wcols, COLS - 2);
932 bare_box_new(wlines + split_win_lines + 1, wcols, wbegy, wbegx, wtitle);
933 wbkgrnd(win_box[win_ptr], &CC_BOX);
934 wbkgrndset(win_box[win_ptr], &CC_BOX);
935 border_hsplit(win_box[win_ptr], wlines + 1);
936 update_panels();
937 doupdate();
938 win_new(wlines, wcols);
939 win2_new(2, wcols, wlines + 2, 1);
940 return 0;
941}
int bare_box_new(int, int, int, int, char *)
Create a new window with optional box and title.
Definition dwin.c:981
int win_new(int, int)
Create a new window with specified dimensions and position.
Definition dwin.c:1037
int border_hsplit(WINDOW *, int)
Draw a box with a separator line around the specified window.
Definition dwin.c:1269
int win2_new(int wlines, int wcols, int wbegy, int wbegx)
Create a new subwindow (win2) with specified dimensions and position.
Definition dwin.c:1066

References bare_box_new(), border_hsplit(), CC_BOX, Perror(), win2_new(), win_box, win_new(), and win_ptr.

Referenced by open_pick_win().

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

◆ box_new()

int box_new ( int wlines,
int wcols,
int wbegy,
int wbegx,
char * wtitle )

Create a new window with optional box and title.

box_new

Parameters
wlinesNumber of lines
wcolsNumber of columns
wbegyBeginning Y position
wbegxBeginning X position
wtitleWindow title
Returns
0 if successful, 1 if error

Definition at line 967 of file dwin.c.

967 {
968 bare_box_new(wlines, wcols, wbegy, wbegx, wtitle);
969 win_new(wlines, wcols);
970 return 0;
971}

References bare_box_new(), and win_new().

Referenced by action_disposition(), answer_yn(), display_error(), display_form(), menu_engine(), Perror(), popup_ckeys(), and wait_mk_win().

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

◆ check_panels()

void check_panels ( int i)

Check and display the panels for a given window index.

check_panels

Parameters
iIndex of the window to check

This function checks the panels associated with the specified window index. It sets the background color for each panel, displays a label indicating the panel type, and updates the display. The function pauses after displaying each panel to allow the user to view the changes.

Definition at line 1090 of file dwin.c.

1090 {
1091 if (i == -1)
1092 return;
1093 char tmp_str[MAXLEN];
1094 wbkgrnd(win_box[i], &CC_RED);
1095 ssnprintf(tmp_str, MAXLEN - 1, "box[%d]", i);
1096 mvwaddstr(win_box[i], 5, 2, tmp_str);
1097 show_panel(panel_box[i]);
1098 update_panels();
1099 doupdate();
1100 getch();
1101
1102 wbkgrnd(win_win[i], &CC_GREEN);
1103 ssnprintf(tmp_str, MAXLEN - 1, "win[%d]", i);
1104 mvwaddstr(win_win[i], 6, 2, tmp_str);
1105 show_panel(panel_win[i]);
1106 update_panels();
1107 doupdate();
1108 getch();
1109
1110 wbkgrnd(win_win2[i], &CC_BLUE);
1111 ssnprintf(tmp_str, MAXLEN - 1, "win2[%d]", i);
1112 mvwaddstr(win_win2[i], 0, 0, tmp_str);
1113 update_panels();
1114 doupdate();
1115 show_panel(panel_win2[i]);
1116 getch();
1117}
PANEL * panel_win2[MAXWIN]
Definition dwin.c:55
WINDOW * win_win2[MAXWIN]
Definition dwin.c:51
cchar_t CC_BLUE
Definition dwin.c:217
cchar_t CC_GREEN
Definition dwin.c:215
cchar_t CC_RED
Definition dwin.c:214
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:420

References CC_BLUE, CC_GREEN, CC_RED, panel_box, panel_win, panel_win2, ssnprintf(), win_box, win_win, and win_win2.

Here is the call graph for this function:

◆ destroy_curses()

void destroy_curses ( )

Gracefully shut down NCurses and restore terminal settings.

destroy_curses

This function should be called before exiting the program to ensure that the terminal is left in a usable state. It checks if NCurses was initialized and, if so, it erases the screen, and ends the NCurses session. It also restores the original terminal settings using restore_shell_tioctl and resets signal handlers to their default state with sig_dfl_mode.

Definition at line 670 of file dwin.c.

670 {
671 if (!f_curses_open)
672 return;
673 for (win_ptr = 0; win_ptr < MAXWIN; win_ptr++) {
674 del_panel(panel_box[win_ptr]);
675 delwin(win_win2[win_ptr]);
676 delwin(win_win[win_ptr]);
677 delwin(win_box[win_ptr]);
678 }
679 win_ptr = -1;
680 endwin();
681 delscreen(screen);
682 fclose(tty_fp);
683 f_curses_open = false;
685 sig_dfl_mode();
686 return;
687}
bool f_curses_open
Definition sig.c:33
SCREEN * screen
Definition dwin.c:42
FILE * tty_fp
Definition dwin.c:43
bool restore_shell_tioctl()
restore_shell_tioctl() - restore shell terminal settings
Definition scriou.c:56
void sig_dfl_mode()
Set signal handlers to default behavior.
Definition sig.c:42

References f_curses_open, panel_box, restore_shell_tioctl(), screen, sig_dfl_mode(), tty_fp, win_box, win_ptr, win_win, and win_win2.

Referenced by abend(), main(), and open_curses().

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

◆ dxwgetch()

int dxwgetch ( WINDOW * win_0,
WINDOW * win_1,
WINDOW * win_2,
WINDOW * win_3,
WINDOW * win_c,
Chyron * chyron,
int n )

Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line, and accepts a sinigle character answer.

dxwgetch

Parameters
win_0Pointer to window 0
win_1Pointer to window 1
win_2Pointer to window 2
win_3Pointer to window 3
win_cPointer to chyron window
chyronPointer to chyron struct
nNumber of seconds to wait before timing out
     0: Wait indefinitely for user input (raw mode)
         accept a single character answer, and don't wait for Enter key
     1: Wait for 1 decisecond
     n > 1: Wait for n/10 seconds
Returns
Key code or ERR if interrupted by signal

Get mouse event and check if it's a left click or double click. If the click is outside the windows, ignore it. If it's on the chyron line, get the corresponding key command. Otherwise, store the click coordinates as click_y and click_x for later use.

Definition at line 2180 of file dwin.c.

2180 {
2181 int c;
2182 MEVENT event;
2183 mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON4_PRESSED | BUTTON5_PRESSED,
2184 nullptr);
2185 click_y = event.y = -1;
2186 click_x = event.x = -1;
2187
2188 if (n == -1) {
2189 struct termios raw_tioctl;
2190 raw_tioctl = curses_tioctl;
2191 mk_raw_tioctl(&raw_tioctl);
2192 } else if (n == 0)
2193 halfdelay(1);
2194 else
2195 halfdelay(min(255, max(0, n * 10)));
2196 tcflush(2, TCIFLUSH);
2197 do {
2198 curs_set(1);
2199 c = wgetch(win_0);
2200 curs_set(0);
2201 if (sig_received != 0) {
2203 c = display_error(em0, em1, em2, nullptr);
2204 if (c == 'q' || c == 'Q' || c == KEY_F(9))
2205 exit(EXIT_FAILURE);
2206 }
2207 if (n > 0 && c == ERR) {
2208 c = 0;
2209 break;
2210 }
2211 if (c == ERR)
2212 continue;
2213 if (c == KEY_MOUSE) {
2214 if (getmouse(&event) != OK) {
2215 c = 0;
2216 continue;
2217 }
2218 if (event.bstate & BUTTON4_PRESSED) {
2219 return KEY_UP;
2220 } else if (event.bstate & BUTTON5_PRESSED) {
2221 return KEY_DOWN;
2222 }
2223 if (event.bstate & BUTTON1_CLICKED || event.bstate & BUTTON1_DOUBLE_CLICKED) {
2224 // Check if the click is in win_0, win_1, or win_2, and set
2225 // mouse_win
2226 // accordingly
2227 // don't free mouse_win, since it is borrowed
2228 mouse_win = nullptr;
2229 if (win_1 != nullptr && wenclose(win_1, event.y, event.x) && wmouse_trafo(win_1, &event.y, &event.x, false))
2230 mouse_win = win_1;
2231 else if (win_2 != nullptr && wenclose(win_2, event.y, event.x) && wmouse_trafo(win_2, &event.y, &event.x, false))
2232 mouse_win = win_2;
2233 else if (win_3 != nullptr && wenclose(win_3, event.y, event.x) && wmouse_trafo(win_3, &event.y, &event.x, false))
2234 mouse_win = win_3;
2235 click_y = event.y;
2236 click_x = event.x;
2237 if (mouse_win == nullptr) {
2238 c = 0;
2239 break;
2240 }
2241 if (mouse_win == win_c && chyron && (event.y == getmaxy(mouse_win) - 1))
2242 c = get_chyron_key(chyron, event.x);
2243 break;
2244 }
2245 }
2246 } while (c == ERR);
2248 return c;
2249}
volatile sig_atomic_t sig_received
Definition sig.c:31
bool handle_signal(sig_atomic_t)
char em1[MAXLEN]
Definition dwin.c:176
struct termios shell_tioctl curses_tioctl
Definition scriou.c:34
WINDOW * mouse_win
Definition dwin.c:118
int click_x
Definition dwin.c:81
int click_y
Definition dwin.c:80
char em0[MAXLEN]
Definition dwin.c:175
char em2[MAXLEN]
Definition dwin.c:177
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
Definition cm.h:82
int display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
Definition dwin.c:1467
int get_chyron_key(Chyron *, int)
Get keycode from chyron.
Definition dwin.c:1917
bool restore_curses_tioctl()
restore_curses_tioctl() - restore curses terminal settings
Definition scriou.c:81
bool mk_raw_tioctl(struct termios *)
mk_raw_tioctl() - set terminal to raw mode
Definition scriou.c:126

References click_x, click_y, curses_tioctl, display_error(), em0, em1, em2, get_chyron_key(), handle_signal(), mk_raw_tioctl(), mouse_win, restore_curses_tioctl(), and sig_received.

Referenced by picker().

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

◆ mvwaddstr_fill()

void mvwaddstr_fill ( WINDOW * w,
int y,
int x,
char * s,
int l )

For lines shorter than their display area, fill the rest with spaces.

mvwaddstr_fill

Parameters
wPointer to window
yY coordinate
xX coordinate
sString to display
lLength of display area

Definition at line 1941 of file dwin.c.

1941 {
1942 char *d, *e;
1943 int maxy, maxx;
1944 char tmp_str[MAXLEN];
1945 getmaxyx(w, maxy, maxx);
1946 y = min(y, maxy);
1947 l = min(l, maxx);
1948 l = min(l, MAXLEN - 1);
1949 e = d = tmp_str;
1950 e += l;
1951 while (d < e) {
1952 if (*s == '\0' || *s == '\n')
1953 *d++ = ' ';
1954 else
1955 *d++ = *s++;
1956 }
1957 *d = '\0';
1958 l = strlen(tmp_str);
1959 mvwaddstr(w, y, x, tmp_str);
1960}

Referenced by display_pick_page(), menu_cmd_processor(), menu_engine(), picker(), reverse_object(), and unreverse_object().

Here is the caller graph for this function:

◆ open_curses()

bool open_curses ( SIO * sio)

Initialize NCurses and color settings.

open_curses

Parameters
sioPointer to SIO struct with terminal and color settings
Returns
true if successful, false if error

This function initializes NCurses and sets up color pairs based on the settings in the SIO struct. It also applies gamma correction to colors. Use this function to initialize NCurses if you don't want NCurses to receive data from the stdin pipe

1. saves stdin and stdout file descriptors in SIO
2. opens a terminal device for NCurses screen IO
3. replaces STDERR_FILENO with terminal file descriptor
SCREEN * screen
Definition dwin.c:42
The SIO structure encapsulates various aspects of the terminal's state and configuration,...
Definition cm.h:805

Definition at line 244 of file dwin.c.

244 {
245 char tmp_str[MAXLEN];
246 char emsg0[MAXLEN];
247
248 // Get the name of the terminal device
249 sio->stdin_fd = dup(STDIN_FILENO);
250 sio->stdout_fd = dup(STDOUT_FILENO);
251 sio->stderr_fd = dup(STDERR_FILENO);
252 if (ttyname_r(STDERR_FILENO, sio->tty_name, sizeof(sio->tty_name)) != 0) {
253 strerror_r(errno, tmp_str, MAXLEN - 1);
254 strnz__cpy(emsg0, "ttyname_r failed ", MAXLEN - 1);
255 strnz__cat(emsg0, tmp_str, MAXLEN - 1);
256 fprintf(stderr, "%s\n", tmp_str);
257 exit(0);
258 }
259 // open the terminal device for NCurses input and output
260 tty_fp = fopen(sio->tty_name, "r+");
261 if (tty_fp == nullptr) {
262 strerror_r(errno, tmp_str, MAXLEN - 1);
263 strnz__cpy(emsg0, "fopen(sio->tty_name) failed ", MAXLEN - 1);
264 strnz__cat(emsg0, tmp_str, MAXLEN - 1);
265 fprintf(stderr, "%s\n", tmp_str);
266 exit(0);
267 }
268 // newterm() allows us to specify a tty device for NCurses input and
269 // output.
270 screen = newterm(nullptr, tty_fp, tty_fp);
271 if (screen == nullptr) {
272 strerror_r(errno, tmp_str, MAXLEN - 1);
273 strnz__cpy(emsg0, "newterm failed ", MAXLEN - 1);
274 strnz__cat(emsg0, tmp_str, MAXLEN - 1);
275 fprintf(stderr, "%s\n", tmp_str);
276 exit(0);
277 }
278 set_term(screen);
279 f_curses_open = true;
280 if (!has_colors()) {
282 abend(-1, "Terminal color support required");
283 }
284 start_color();
285 if (!can_change_color()) {
287 fprintf(stderr, "Terminal cannot change colors\n");
288 fprintf(stderr, "Check TERM environment variable\n");
289 fprintf(stderr, "Check terminfo for missing \"ccc\"\n");
290 abend(-1, "fatal error");
291 }
292 panel_main = new_panel(stdscr);
293 noecho();
294 keypad(stdscr, true);
295 idlok(stdscr, false);
296 idcok(stdscr, false);
297 wbkgrnd(stdscr, &CC_NORM);
298 for (win_ptr = 0; win_ptr < MAXWIN; win_ptr++) {
299 panel_box[win_ptr] = nullptr;
300 ui_win[win_ptr] = nullptr;
301 ui_win2[win_ptr] = nullptr;
302 ui_box[win_ptr] = nullptr;
303 win_win[win_ptr] = nullptr;
304 win_win2[win_ptr] = nullptr;
305 win_box[win_ptr] = nullptr;
306 }
307 win_ptr = -1;
308 return sio;
309}
cchar_t CC_NORM
Definition dwin.c:208
UiSurface * ui_win2[MAXWIN]
Definition dwin.c:48
PANEL * panel_main
Definition dwin.c:83
void destroy_curses()
Gracefully shut down NCurses and restore terminal settings.
Definition dwin.c:670
void abend(int, char *)
Abnormal program termination.
Definition dwin.c:2018
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:544
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition futil.c:573
int stdout_fd
Definition cm.h:861
int stderr_fd
Definition cm.h:862
char tty_name[MAXLEN]
Definition cm.h:855
int stdin_fd
Definition cm.h:860

References abend(), CC_NORM, destroy_curses(), f_curses_open, panel_box, panel_main, screen, SIO::stderr_fd, SIO::stdin_fd, SIO::stdout_fd, strnz__cat(), strnz__cpy(), tty_fp, SIO::tty_name, ui_box, ui_win, ui_win2, win_box, win_ptr, win_win, and win_win2.

Referenced by main().

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

◆ restore_wins()

void restore_wins ( )

Restore all windows after a screen resize.

restore_wins

This function is used to restore the display of all windows after a screen resize event. It clears the standard screen and then iterates through all existing windows, touching them to ensure they are redrawn correctly on the resized screen. Use this function in response to a SIGWINCH signal to handle terminal resizing gracefully.

Definition at line 1225 of file dwin.c.

1225 {
1226 touchwin(stdscr);
1227 for (int i = 0; i <= win_ptr; i++) {
1228 if (win_box[i] != nullptr)
1229 touchwin(win_box[i]);
1230 if (win_win[i] != nullptr)
1231 touchwin(win_win[i]);
1232 if (win_win2[i] == nullptr)
1233 touchwin(win_win2[i]);
1234 }
1235}

References win_box, win_ptr, win_win, and win_win2.

Referenced by enter_file_spec(), exec_objects(), fork_exec(), form_exec_receiver(), full_screen_shell(), menu_cmd_processor(), menu_engine(), view_cmd_processor(), view_init_input(), and write_view_buffer().

Here is the caller graph for this function:

◆ vgetch()

int vgetch ( WINDOW * win,
int n )

Wrapper for wgetch that handles signals and mouse events, and accepts a single character answer.

vgetch

Parameters
winPointer to window
nNumber of seconds to wait before timing out
Returns
Key code or ERR if interrupted by signal

This function is similar to xwgetch, but it does not handle chyron clicks. It sets the terminal to raw mode if n is -1, or halfdelay mode if n is 0 or greater. It waits for user input and returns the key code. If a signal is received, it handles the signal and may display an error message. If the user presses 'q', 'Q', or F9, the program exits.

Definition at line 2258 of file dwin.c.

2258 {
2259 int c;
2260 mousemask(0, nullptr);
2261
2262 curs_set(1);
2263 if (n == -1) {
2264 struct termios raw_tioctl;
2265 raw_tioctl = curses_tioctl;
2266 mk_raw_tioctl(&raw_tioctl);
2267 } else if (n == 0)
2268 halfdelay(1);
2269 else
2270 halfdelay(min(255, max(0, n * 10)));
2271 do {
2272 c = wgetch(win);
2273 if (n > 0 && c == ERR) {
2274 c = 0;
2275 break;
2276 }
2277 } while (c == ERR);
2278 curs_set(0);
2279 // restore_curses_tioctl();
2280 return c;
2281}

References curses_tioctl, and mk_raw_tioctl().

Referenced by cf_accept(), get_cmd_char(), and remove_file().

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

◆ view_boxwin_resize()

void view_boxwin_resize ( Init * init)

Resize the current window and its box.

Parameters
initPointer to the Init structure containing view settings.

This function resizes the current window and its associated box window to the specified number of lines and columns.

Definition at line 346 of file init_view.c.

346 {
347 destroy_view_win(init);
348 init_view_boxwin(init);
349 border_title(init->view->box_win, init->view->title);
350 // initialize_line_table(init->view);
351}
void destroy_view_win(Init *)
Definition init_view.c:318
int init_view_boxwin(Init *init)
Initialize the C-Menu View in box window mode.
Definition init_view.c:194
View * view
Definition common.h:188
char title[MAXLEN]
Definition view.h:62
WINDOW * box_win
Definition view.h:72

References border_title(), View::box_win, destroy_view_win(), init_view_boxwin(), View::title, and Init::view.

Referenced by view_cmd_processor().

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

◆ view_full_screen_resize()

void view_full_screen_resize ( Init * init)

Resize the full screen view and its components.

Parameters
initPointer to the Init structure containing view settings.

This function resizes the full screen view and its components, including the command line window, line number window, and main content pad. It also recalculates the dimensions for the full screen mode and updates the scroll regions accordingly.

Definition at line 140 of file init_view.c.

140 {
141 erase();
142 View *view = init->view;
144 mvwin(view->cmdln_win, view->lines - 1, 0);
145 wresize(view->cmdln_win, 1, view->cols);
146 wresize(view->lnno_win, view->ln_win_lines - 1, view->ln_win_cols);
147 wsetscrreg(view->lnno_win, 0, view->scroll_lines - 1);
148 wresize(view->pad, view->lines - 1, PAD_COLS);
149 wsetscrreg(view->pad, 0, view->lines - 1);
150}
#define PAD_COLS
Definition view.h:32
View * view
Definition mem.c:49
void view_calc_full_screen_dimensions(Init *)
Calculate the dimensions for full screen mode.
Definition init_view.c:159
Definition view.h:42

References View::cmdln_win, View::cols, View::lines, View::ln_win_cols, View::ln_win_lines, View::lnno_win, View::pad, View::scroll_lines, Init::view, and view_calc_full_screen_dimensions().

Referenced by view_cmd_processor().

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

◆ win2_box_new()

int win2_box_new ( int wlines,
int wcols,
int wbegy,
int wbegx,
char * wtitle )

Create a new window with optional box and title, and a second window inside it.

win2_box_new

Parameters
wlinesNumber of lines for the first window
wcolsNumber of columns for the first window
wbegyBeginning Y position for the first window
wbegxBeginning X position for the first window
wtitleWindow title for the first window
Returns
0 if successful, 1 if error

Definition at line 952 of file dwin.c.

952 {
953 bare_box_new(wlines, wcols, wbegy, wbegx, wtitle);
954 win_new(wlines, wcols);
955 win2_new(wlines, wcols, 1, 1);
956 return 0;
957}

References bare_box_new(), win2_new(), and win_new().

Here is the call graph for this function:

◆ win2_new()

int win2_new ( int wlines,
int wcols,
int wbegy,
int wbegx )

Create a new subwindow (win2) with specified dimensions and position.

win2_new

Parameters
wlinesNumber of lines
wcolsNumber of columns
wbegyBeginning Y position relative to the parent window
wbegxBeginning X position relative to the parent window
Returns
0 if successful, 1 if error

Definition at line 1066 of file dwin.c.

1066 {
1067
1068 // -------------------> win2_win <-------------------
1069 win_win2[win_ptr] = derwin(win_box[win_ptr], wlines, wcols, wbegy, wbegx);
1070 if (win_win2[win_ptr] == nullptr) {
1071 Perror("win_win2[win_ptr] = derwin() failed");
1072 exit(EXIT_FAILURE);
1073 }
1074 panel_win2[win_ptr] = new_panel(win_win2[win_ptr]);
1075 wbkgrnd(win_win2[win_ptr], &CC_NT);
1076 keypad(win_win2[win_ptr], true);
1077 idlok(win_win2[win_ptr], false);
1078 idcok(win_win2[win_ptr], false);
1079 return 0;
1080}

References CC_NT, panel_win2, Perror(), win_box, win_ptr, and win_win2.

Referenced by box_hsplit_new(), and win2_box_new().

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

◆ win_del()

void win_del ( )

Delete the current window and its associated box window.

win_del

This function deletes the current window and its associated box window, if they exist. It also refreshes the remaining windows to ensure the display is updated correctly. After calling this function, the global win_ptr variable is decremented to point to the previous window in the stack.

Definition at line 1179 of file dwin.c.

1179 {
1180 if (win_ptr >= MAXWIN) {
1181 Perror("win_ptr >= MAXWIN");
1182 exit(EXIT_FAILURE);
1183 }
1184 if (win_ptr >= 0) {
1185
1186 if (panel_win[win_ptr] != nullptr) {
1187 del_panel(panel_win[win_ptr]);
1188 panel_win[win_ptr] = nullptr;
1189 }
1190 if (win_win[win_ptr] != nullptr) {
1191 delwin(win_win[win_ptr]);
1192 win_win[win_ptr] = nullptr;
1193 }
1194
1195 if (panel_win2[win_ptr] != nullptr) {
1196 del_panel(panel_win2[win_ptr]);
1197 panel_win2[win_ptr] = nullptr;
1198 }
1199 if (win_win2[win_ptr] != nullptr) {
1200 delwin(win_win2[win_ptr]);
1201 win_win2[win_ptr] = nullptr;
1202 }
1203
1204 if (panel_box[win_ptr] != nullptr) {
1205 del_panel(panel_box[win_ptr]);
1206 panel_box[win_ptr] = nullptr;
1207 }
1208
1209 if (win_box[win_ptr] != nullptr) {
1210 delwin(win_box[win_ptr]);
1211 win_box[win_ptr] = nullptr;
1212 }
1213 win_ptr--;
1214 }
1215}

References panel_box, panel_win, panel_win2, Perror(), win_box, win_ptr, win_win, and win_win2.

Referenced by action_disposition(), answer_yn(), display_error(), init_form(), init_pick(), menu_engine(), Perror(), popup_ckeys(), wait_destroy(), and waitpid_with_timeout().

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

◆ win_init_attrs()

void win_init_attrs ( )

Initialize window attributes.

This function initializes color pairs for the window cp_nt, and cp_box are global variables

Definition at line 226 of file dwin.c.

226 {
227 return;
228}

◆ win_new()

int win_new ( int wlines,
int wcols )

Create a new window with specified dimensions and position.

win_new

Parameters
wlinesNumber of lines
wcolsNumber of columns
Returns
0 if successful, 1 if error

Definition at line 1037 of file dwin.c.

1037 {
1038 // -------------------> win_win <-------------------
1039 win_win[win_ptr] = derwin(win_box[win_ptr], wlines, wcols, 1, 1);
1040 if (win_win[win_ptr] == nullptr) {
1041 Perror("win_win[win_ptr] = derwin() failed");
1042 exit(EXIT_FAILURE);
1043 }
1044 panel_win[win_ptr] = new_panel(win_win[win_ptr]);
1045 wbkgrnd(win_win[win_ptr], &CC_NT);
1046 wbkgrndset(win_win[win_ptr], &CC_NT);
1047 keypad(win_win[win_ptr], true);
1048 idlok(win_win[win_ptr], false);
1049 idcok(win_win[win_ptr], false);
1050 wsetscrreg(win_win[win_ptr], 0, wlines - 1);
1051 scrollok(win_win[win_ptr], true);
1052 return 0;
1053}

References CC_NT, panel_win, Perror(), win_box, win_ptr, and win_win.

Referenced by box_hsplit_new(), box_new(), and win2_box_new().

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

◆ win_redraw()

void win_redraw ( WINDOW * win)

Redraw the specified window.

win_redraw

Parameters
winPointer to the window to redraw

This function erases the contents of the specified window and then refreshes it to update the display. Use this function when you need to clear and redraw a window, such as after resizing or when updating its contents.

Definition at line 1168 of file dwin.c.

1168 {
1169 werase(win);
1170 update_panels();
1171}

◆ win_resize()

void win_resize ( int wlines,
int wcols,
char * title )

Resize the current window and its box, and update the title.

win_resize

Parameters
wlinesNumber of lines
wcolsNumber of columns
titleWindow title

This function resizes the current window and its associated box window to the specified number of lines and columns. It also updates the title of the box window if a title is provided. After resizing, it refreshes the windows to apply the changes.

Definition at line 1128 of file dwin.c.

1128 {
1129 int maxx;
1130 update_panels();
1131 doupdate();
1132 wresize(win_box[win_ptr], wlines + 2, wcols + 2);
1133 wbkgrndset(win_box[win_ptr], &CC_BOX);
1134 wborder_set(win_box[win_ptr], &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br);
1135 if (title != nullptr && *title != '\0') {
1136 wmove(win_box[win_ptr], 0, 1);
1137 waddnstr(win_box[win_ptr], (const char *)&bw_rt, 1);
1138 wmove(win_box[win_ptr], 0, 2);
1139 waddnstr(win_box[win_ptr], (const char *)&bw_sp, 1);
1140 mvwaddnwstr(win_box[win_ptr], 0, 1, &bw_rt, 1);
1141 mvwaddnwstr(win_box[win_ptr], 0, 2, &bw_sp, 1);
1142 mvwaddstr(win_box[win_ptr], 0, 3, title);
1143 maxx = getmaxx(win_box[win_ptr]);
1144 int s = strlen(title);
1145 if ((s + 3) < maxx)
1146 mvwaddch(win_box[win_ptr], 0, (s + 3), ' ');
1147 if ((s + 4) < maxx)
1148 mvwaddnwstr(win_box[win_ptr], 0, (s + 4), &bw_lt, 1);
1149 }
1150 update_panels();
1151 wresize(win_win[win_ptr], wlines, wcols);
1152 wbkgrndset(win_win[win_ptr], &CC_NT);
1153 wsetscrreg(win_win[win_ptr], 0, wlines - 1);
1154 keypad(win_win[win_ptr], TRUE);
1155 idlok(win_win[win_ptr], false);
1156 idcok(win_win[win_ptr], false);
1157 scrollok(win_win[win_ptr], true);
1158 update_panels();
1159 doupdate();
1160}
const wchar_t bw_sp
Definition dwin.c:146
#define TRUE
Definition iloan.c:19

References bl, br, bs, bw_lt, bw_rt, bw_sp, CC_BOX, CC_NT, ls, rs, tl, tr, ts, win_box, win_ptr, and win_win.

◆ xwgetch()

int xwgetch ( WINDOW * win,
Chyron * chyron,
int n )

Wrapper for wgetch that handles signals, mouse events, checks for clicks on the chyron line, and accepts a sinigle character answer.

xwgetch

Parameters
winPointer to window
chyronPointer to chyron struct
nNumber of seconds to wait before timing out
     0: Wait indefinitely for user input (raw mode)
         accept a single character answer, and don't wait for Enter key
     1: Wait for 1 decisecond
     n > 1: Wait for n/10 seconds
Returns
Key code or ERR if interrupted by signal

Get mouse event and check if it's a left click or double click. If the click is outside the window, ignore it. If it's on the chyron line, get the corresponding key command. Otherwise, store the click coordinates as click_y and click_x for later use.

Definition at line 2094 of file dwin.c.

2094 {
2095 int c;
2096 MEVENT event;
2097 mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON4_PRESSED | BUTTON5_PRESSED,
2098 nullptr);
2099 click_y = event.y = -1;
2100 click_x = event.x = -1;
2101
2102 if (n == -1) {
2103 struct termios raw_tioctl;
2104 raw_tioctl = curses_tioctl;
2105 mk_raw_tioctl(&raw_tioctl);
2106 } else if (n == 0)
2107 halfdelay(1);
2108 else
2109 halfdelay(min(255, max(0, n * 10)));
2110 tcflush(2, TCIFLUSH);
2111 do {
2112 curs_set(1);
2113 c = wgetch(win);
2114 curs_set(0);
2115 if (sig_received != 0) {
2117 c = display_error(em0, em1, em2, nullptr);
2118 if (c == 'q' || c == 'Q' || c == KEY_F(9))
2119 exit(EXIT_FAILURE);
2120 }
2121 if (n > 0 && c == ERR) {
2122 c = 0;
2123 break;
2124 }
2125 if (c == ERR)
2126 continue;
2127 if (c == KEY_MOUSE) {
2128 if (getmouse(&event) != OK) {
2129 c = 0;
2130 continue;
2131 }
2132 if (event.bstate & BUTTON4_PRESSED) {
2133 return KEY_UP;
2134 } else if (event.bstate & BUTTON5_PRESSED) {
2135 return KEY_DOWN;
2136 }
2137 if (event.bstate & BUTTON1_CLICKED || event.bstate & BUTTON1_DOUBLE_CLICKED) {
2138 if (wenclose(win, event.y, event.x)) {
2139 wmouse_trafo(win, &event.y, &event.x, false);
2140 click_y = event.y;
2141 click_x = event.x;
2142 if (chyron && event.y == getmaxy(win) - 1) {
2143 c = get_chyron_key(chyron, event.x);
2144 break;
2145 } else
2146 break;
2147 }
2148 c = ERR;
2149 continue;
2150 }
2151 }
2152 } while (c == ERR);
2154 return c;
2155}

References click_x, click_y, curses_tioctl, display_error(), em0, em1, em2, get_chyron_key(), handle_signal(), mk_raw_tioctl(), restore_curses_tioctl(), and sig_received.

Referenced by action_disposition(), answer_yn(), display_error(), field_editor(), form_post(), form_process(), menu_cmd_processor(), Perror(), and wait_continue().

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