C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
dwin.c
Go to the documentation of this file.
1/** @file dwin.c
2 @brief Window support for C-Menu - EXPERIMENTAL
3 @details This file contains functions for managing NCurses windows and color
4 settings for the Chyron structure for function key labels and mouse click
5 handling. This file is a work in progress and may be subject to change as the
6 C-Menu project evolves. Generally, don't try to use it yet unless you want
7 complete the half-done code modifications.
8 @author Bill Waller
9 Copyright (c) 2025
10 MIT License
11 billxwaller@gmail.com
12 @date 2026-02-09
13 */
14
15/** @defgroup window_support Window Support
16 @brief Manage NCurses windows and color settings
17 */
18
19#include "cm.h"
20#include "ui_backend.h"
21#include <errno.h>
22#include <fcntl.h>
23#include <iso646.h>
24#include <math.h>
25#ifdef UAL_UI
26#include "ui_ncurses_internal.h"
27#include <ncursesw/ncurses.h>
28#include <ncursesw/panel.h>
29#endif
30#ifdef NOTCURSES_UI
31#include "ui_notcurses_internal.h"
32#include <notcurses/notcurses.h>
33#endif
34#include <stdbool.h>
35#include <stdlib.h>
36#include <string.h>
37#include <sys/ioctl.h>
38#include <sys/stat.h>
39#include <sys/types.h>
40#include <termios.h>
41#include <unistd.h>
42#include <wchar.h>
43
46
47/** colors_text
48 @brief Color names for .minitrc overrides
49 @details These names are used in .minitrc to specify color overrides The
50 order of these names corresponds to the ColorsEnum values */
51char const colors_text[][10] = {
52 "black", "red", "green", "yellow", "blue", "magenta", "cyan",
53 "white", "orange", "bg", "abg", "bblack", "bred", "bgreen",
54 "byellow", "bblue", "bcyan", "bmagenta", "bwhite", "borange", ""};
55
56typedef enum Cells {
88} cells_t;
89
121
122double GRAY_GAMMA = 1.2; /**< Gamma correction. Set in .minitrc */
123double RED_GAMMA = 1.2;
124double GREEN_GAMMA = 1.2;
125double BLUE_GAMMA = 1.2;
126
128unsigned int cmd_key;
129bool f_sigwench = false;
130uint16_t win_attr;
131uint16_t box_attr;
134uint m_begy = -1;
135uint m_begx = -1;
141char fn[MAXLEN];
146
147ushort cp_box;
148ushort cp_ind;
149ushort cp_cmdln;
150ushort cp_title;
151ushort cp_nt;
153ushort cp_nt_hl;
155ushort cp_ln;
159ushort cp_red;
160ushort cp_green;
162ushort cp_blue;
163
165
166/** @brief Initialize local color variables and color pairs based on SIO
167 * settings
168 @ingroup color_management
169 @param sio Pointer to SIO struct with color settings
170 @details This function initializes local color variables and color pairs
171 based on the settings in the SIO struct. It applies gamma correction to
172 colors and sets up cchar_t variables for use in NCurses functions. The color
173 pair indices are stored in global variables for easy reference throughout the
174 code when applying colors to various parts of the interface using NCurses
175 functions that accept color pair indices.
176 */
177void initialize_cells(SIO *sio) {
178 /** gamma correction values */
179 /** These are read from ~/.minitrc */
180 /** used when initializing colors */
186 //
187 // Standardized color pairs
188 //
189 // strcpy(sio->nt_bg, "#0000ff");
190 // strcpy(sio->box_bg, "#00ff00");
207 //
208 // Standardized UiCells
209 //
212
213 mbstate_t mbstate;
214 memset(&mbstate, 0, sizeof(mbstate));
215 wchar_t brktl = sio->brackets[0];
217 wchar_t brktr = sio->brackets[1];
242}
243/** rgb_to_xterm256_idx
244 @brief Convert RGB color to XTerm 256 color index
245 @ingroup color_management
246 @param rgb RGB color
247 @return XTerm 256 color index
248 @details This function converts an RGB color to the nearest XTerm 256 color
249 index. It first checks if the color is a shade of gray, and if so, it uses
250 the gray ramp. Otherwise, it calculates the nearest color in the 6x6x6 color
251 cube. */
252uint rgb_to_xterm256_idx(RGB *rgb) {
253 if (rgb->r == rgb->g && rgb->g == rgb->b) {
254 if (rgb->r < 8)
255 return 16;
256 if (rgb->r > 248)
257 return 231;
258 return ((rgb->r - 8) / 10) + 231;
259 } else {
260 uint r_index = (rgb->r < 45) ? 0 : (rgb->r - 60) / 40 + 1;
261 uint g_index = (rgb->g < 45) ? 0 : (rgb->g - 60) / 40 + 1;
262 uint b_index = (rgb->b < 45) ? 0 : (rgb->b - 60) / 40 + 1;
263 return 16 + (36 * r_index) + (6 * g_index) + b_index;
264 }
265}
266/** xterm256_idx_to_rgb
267 @brief Convert XTerm 256 color index to RGB
268 @ingroup color_management
269 @param idx XTerm 256 color index
270 @return RGB color
271 @details This function converts an XTerm 256 color index to an RGB color. It
272 first checks if the index is in the standard 16 colors, then checks if it's
273 in the 6x6x6 color cube, and finally checks if it's in the gray ramp. */
274RGB xterm256_idx_to_rgb(uint idx) {
275 /** Convert XTerm 256 color index to RGB
276 @param idx - XTerm 256 color index
277 @return RGB struct */
278 RGB rgb;
279 if (idx > 255)
280 idx = 255;
281 rgb.r = rgb.g = rgb.b = 0;
282 if (idx < 16) {
283 rgb.r = std_color[idx].r;
284 rgb.g = std_color[idx].g;
285 rgb.b = std_color[idx].b;
286 } else if (idx >= 16 && idx <= 231) {
287 idx -= 16;
288 rgb.r = (idx / 36) % 6 * 51;
289 rgb.g = (idx / 6) % 6 * 51;
290 rgb.b = (idx % 6) * 51;
291 } else if (idx >= 232 && idx <= 255) {
292 uint gray = (idx - 232) * 11;
293 rgb.r = rgb.g = rgb.b = gray;
294 }
295 return rgb;
296}
297
298/** apply_gamma
299 @brief Apply gamma correction to RGB color
300 @ingroup color_management
301 @param rgb Pointer to RGB color
302 @details This function modifies the RGB color in place. It applies gamma
303 correction to the RGB color based on the gamma values set in the SIO struct.
304 If the color is a shade of gray, it applies the gray gamma correction.
305 Otherwise, it applies the individual red, green, and blue gamma corrections.
306 */
307void apply_gamma(RGB *rgb) {
308 if (rgb->r == rgb->g && rgb->r == rgb->b) {
309 if (GRAY_GAMMA > 0.0f && GRAY_GAMMA != 1.0f) {
310 rgb->r = (int)(pow((rgb->r / 255.0f), 1.0f / GRAY_GAMMA) * 255.0f);
311 rgb->g = rgb->r;
312 rgb->b = rgb->r;
313 }
314 return;
315 }
316 if (rgb->r != 0 && RED_GAMMA > 0.0f && RED_GAMMA != 1.0f)
317 rgb->r = (int)(pow((rgb->r / 255.0f), 1.0f / RED_GAMMA) * 255.0f);
318 if (rgb->g != 0 && GREEN_GAMMA > 0.0f && GREEN_GAMMA != 1.0f)
319 rgb->g = (int)(pow((rgb->g / 255.0f), 1.0f / GREEN_GAMMA) * 255.0f);
320 if (rgb->b != 0 && BLUE_GAMMA > 0.0f && BLUE_GAMMA != 1.0f)
321 rgb->b = (int)(pow((rgb->b / 255.0f), 1.0f / BLUE_GAMMA) * 255.0f);
322}
323/** init_clr_palette
324 @brief Initialize color palette based on SIO settings
325 @ingroup color_management
326 @param sio Pointer to SIO struct with color settings
327 @return true if successful, false if error
328 @details This function initializes the xterm256 color cube and applies any
329 color overrides specified in the SIO struct. The color strings in the SIO
330 struct are expected to be six-digit HTML style hex color codes (e.g.,
331 "#RRGGBB"). If a color override is specified for any of the standard colors,
332 it is applied using the ui_add_color_hex function. */
333bool init_clr_palette(SIO *sio) {
373 return true;
374}
375/** destroy_curses
376 @brief Gracefully shut down NCurses and restore terminal settings
377 @ingroup window_support
378 @details This function should be called before exiting the program to ensure
379 that the terminal is left in a usable state. It checks if NCurses was
380 initialized and, if so, it erases the screen, and ends the
381 NCurses session. It also restores the original terminal settings using
382 restore_shell_tioctl and resets signal handlers to their default state with
383 sig_dfl_mode. */
385 if (!f_curses_open)
386 return;
388 f_curses_open = false;
391 return;
392}
393void mbc_to_wc(wchar_t wc[2], const char mbc) {
394 wc[0] = wc[1] = L'\0';
395 mbstate_t state = {0};
396 size_t len = mbrtowc(wc, &mbc, MB_CUR_MAX, &state);
397 if (len <= 0) {
398 wc[0] = L'?';
399 wc[1] = L'\0';
400 len = 1;
401 }
402}
403
404wchar_t *mbstr_to_wcstr(const char *mb_str) {
405 const char *src_ptr = mb_str;
406 mbstate_t state = {0};
407 size_t wc_count = mbsrtowcs(NULL, &src_ptr, 0, &state);
408 if (wc_count == (size_t)-1)
409 return nullptr;
410 src_ptr = mb_str;
411 wmemset((wchar_t *)&state, 0, sizeof(state) / sizeof(wchar_t));
412 wchar_t *wc_str = malloc((wc_count + 1) * sizeof(wchar_t));
413 if (!wc_str)
414 return nullptr;
415 mbsrtowcs(wc_str, &src_ptr, wc_count + 1, &state);
416 return wc_str;
417}
418
419/** mbstr_to_cellstr
420 @brief Convert multibyte string to complex character array
421 @ingroup Chyron
422 @param cmplx_buf Output buffer for complex characters
423 @param str Input multibyte string
424 @param attr Attributes to apply to the complex characters
425 @param cpx Color pair index for the complex characters
426 @param pos Pointer to current position in the output buffer, updated as
427 characters are added
428 @param maxlen Maximum length of the output buffer
429 @return Number of bytes processed from the input string
430 @details This function converts a multibyte string to an array of complex
431 characters (cchar_t) that can be used with NCurses functions. It handles
432 multibyte characters and applies the specified color pair to each character.
433 The pos parameter is updated to reflect the current position in the output
434 buffer, and the function ensures that it does not exceed the maximum length.
435*/
436
437#ifdef NCURSES_UI
438uint mbstr_to_cellstr(UiCell *cmplx_buf, const char *str, const UiCell *cell_base, uint *p, const uint atmost) {
439 attr_t attrs;
440 short cp;
441 uint p1 = 0;
442 uint *pos = &p1;
443 if (p)
444 pos = p;
445 else
446 pos = &p1;
447 uint i = 0, len = 0;
448 const char *s;
449 UiCell cc = {0};
450 wchar_t wstr[5];
451 getcchar(cell_base, &wstr[0], &attrs, &cp, nullptr);
452 mbstate_t mbstate;
453 memset(&mbstate, 0, sizeof(mbstate));
454 if (pos && *pos >= atmost - 1)
455 return 0;
456 while (str[i] != '\0') {
457 s = &str[i];
458 len = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
459 if (len <= 0) {
460 wstr[0] = L'?';
461 wstr[1] = L'\0';
462 len = 1;
463 }
464 wstr[1] = L'\0';
465 if (*pos > atmost)
466 break;
467 if (setcchar(&cc, wstr, attrs, cp, nullptr) != ERR) {
468 if (len > 0 && (*pos + len) < atmost)
469 cmplx_buf[(*pos)++] = cc;
470 }
471 i += len;
472 }
473 wstr[0] = L'\0';
474 wstr[1] = L'\0';
475 setcchar(&cc, wstr, attrs, cp, nullptr);
476 cmplx_buf[*pos] = cc;
477 return *pos;
478}
479#else
480uint mbstr_to_cellstr(UiCell *cmplx_buf, const char *str, const UiCell *cell_base, uint *p, const uint atmost) {
481 ushort cp;
482 uint p1 = 0;
483 uint *pos = &p1;
484 if (p)
485 pos = p;
486 uint i = 0, len = 0;
487 const char *s;
488 attr_t style;
489 UiCell cc;
490 wchar_t wstr[5];
491 ui_getcchar(cell_base, &wstr[0], &style, &cp, nullptr);
492 mbstate_t mbstate;
493 memset(&mbstate, 0, sizeof(mbstate));
494 if (pos && *pos >= atmost - 1)
495 return 0;
496 while (str[i] != '\0') {
497 s = &str[i];
498 len = mbrtowc(wstr, s, MB_CUR_MAX, &mbstate);
499 if (len <= 0) {
500 wstr[0] = L'?';
501 wstr[1] = L'\0';
502 len = 1;
503 }
504 wstr[1] = L'\0';
505 if (*pos > atmost)
506 break;
507 if (ui_setcchar(&cc, wstr, style, cp, nullptr) != ERR) {
508 if (len > 0 && (*pos + len) < atmost)
509 cmplx_buf[(*pos)++] = cc;
510 }
511 i += len;
512 }
513 wstr[0] = L'\0';
514 wstr[1] = L'\0';
515 ui_setcchar(&cc, wstr, style, cp, nullptr);
516 cmplx_buf[*pos] = cc;
517 return *pos;
518}
519#endif
520// -------------------> surface_box_win_new <-------------------
521int surface_box_win_new(uint wlines, uint wcols, uint wbegy, uint wbegx, char *wtitle) {
522 if (sfc_ptr >= SFC_MAX) {
523 Perror("Maximum number of surfaces (%d) exceeded");
524 exit(EXIT_FAILURE);
525 }
526 uint maxy, maxx;
527 ui_get_screen_size(&maxy, &maxx);
528 wlines = min(wlines, maxy - 2);
529 wcols = min(wcols, maxx - 2);
530 sfc_ptr++;
531 // -------------------> UAL_win_box <-------------------
532 ui_surface[sfc_ptr] = ui_box_surface_new(nullptr, 0, wlines, wcols, wbegy, wbegx, wtitle);
533 UiSurface *sfc = ui_surface[sfc_ptr];
534 ui_surface_addwin(sfc, WIN, BOX, wlines, wcols, 1, 1);
536 return 0;
537}
538// -------------------> box_split_new <-------------------
539int surface_split_box_win_new(uint wlines, uint wcols, uint split_y, uint split_x, uint wbegy, uint wbegx, char *wtitle) {
540 if (sfc_ptr >= SFC_MAX) {
541 Perror("Maximum number of surfaces (%d) exceeded");
542 exit(EXIT_FAILURE);
543 }
544 if (sfc_ptr >= SFC_MAX) {
545 Perror("Maximum number of surfaces (%d) exceeded");
546 exit(EXIT_FAILURE);
547 }
548 uint maxy, maxx;
549 ui_get_screen_size(&maxy, &maxx);
550 wlines = min(wlines, maxy - 2);
551 wcols = min(wcols, maxx - 2);
552 split_x = min(split_x, maxx - 2); // not implemented yet
553 uint split_wlines = min(wlines + split_y + 1, maxy - 2);
554 wcols = min(wcols, maxx - 2);
555 sfc_ptr++;
556 // -------------------> surface_new <-------------------
557 ui_surface[sfc_ptr] = ui_box_surface_new(nullptr, 0, split_wlines, wcols, wbegy, wbegx, wtitle);
558 UiSurface *sfc = ui_surface[sfc_ptr];
559
560 ui_surface_addwin(sfc, WIN, BOX, wlines, wcols, 1, 1);
562
563 border_ysplit(sfc, wlines + 1);
565 ui_surface_addwin(sfc, WIN2, BOX, 2, wcols, wlines + 2, 1);
567 return 0;
568}
569/** cm_destroy_surface
570 @brief Destroy the most recently created surface
571 @ingroup window_support
572 @return 0 on success, -1 if no surfaces exist
573 @details This function destroys the most recently created surface and decrements the surface pointer. It should be called when a surface is no longer needed to free up resources. If there are no surfaces to destroy, it returns -1.
574 @note The difference between this function and ui_surface_destroy() is that this function destroys the surface pointed to by the surface pointer (sfc_ptr) and decrements the surface pointer after destroying the surface.
575 */
576int cm_surface_destroy(UiSurface *sfc) {
578 sfc_ptr--;
579 return 0;
580}
581int border_draw(UiSurface *sfc) {
582 uint maxy = ui_getmaxy(sfc, BOX);
583 uint maxx = ui_getmaxx(sfc, BOX);
584 uint y = 0;
585 uint x = 0;
588 for (x = 1; x < maxx - 1; x++)
591 ui_mvwadd_wchnstr(sfc, BOX, y, maxx - 1, &cell_tr, 1);
593 for (y = 1; y < maxy - 1; y++) {
596 ui_mvwadd_wchnstr(sfc, BOX, y, maxx - 1, &cell_ve, 1);
598 }
600 for (x = 1; x < maxx - 1; x++)
602 ui_mvwadd_wchnstr(sfc, BOX, y, maxx - 1, &cell_br, 1);
604 return 0;
605}
606/** border-ysplit
607 @brief Draw a box with a separator line around the specified window
608 @ingroup window_support
609 @param box Pointer to the window to draw the box around
610 @param y Line number where the separator line should be drawn
611 @details This function draws a box around the specified window, similar to
612 border_draw(), but it also includes a horizontal separator line that divides the box
613 into two sections. The separator line is drawn at a fixed position (line 00,
614 page 00) and extends across the width of the box. Use this function when you
615 want to visually separate two sections within a window, such as for a header
616 and content area. */
617int border_ysplit(UiSurface *sfc, uint y) {
618 uint maxx = ui_getmaxx(sfc, BOX);
620 for (uint x = 1; x < maxx - 1; x++)
622 ui_mvwadd_wchnstr(sfc, BOX, y, maxx - 1, &cell_rt, 1);
623 return 0;
624}
625/** border_ysplit_text
626 @brief Draw a box with a separator line and text around the specified window
627 @ingroup window_support
628 @param box Pointer to the window to draw the box around
629 @param text Text to display in the middle of the separator line
630 @param separator_line Line number where the separator line should be drawn
631 @details This function draws a box around the specified window, similar to
632 border_draw(), but it also includes a horizontal separator line that divides the box
633 into two sections. The separator line is drawn at the specified line number and
634 extends across the width of the box, with the provided text displayed in the
635 middle of the line. Use this function when you want to visually separate two
636 sections within a window and label the separator with descriptive text. */
637int border_ysplit_text(UiSurface *sfc, char *text, uint separator_line) {
638 uint maxx = ui_getmaxx(sfc, BOX);
639 uint l;
640 uint y = separator_line;
641 uint x = 0;
642 // Draw the horizontal line with text in the middle, so we start by drawing
643 // the left edge, then the text, then the right edge, and finally fill in the
644 // horizontal line on either side of the text.
649 strnz(text, maxx - 7);
650 wchar_t *text_wc;
651 text_wc = mbstr_to_wcstr(text);
652 l = wcswidth(text_wc, wcslen(text_wc));
654 ui_mvwaddnwstr(sfc, BOX, y, x, text_wc, l);
655 x += l;
656 l = min(l, maxx - 7);
657 free(text_wc);
660
661 while (x < maxx - 1)
664 return 0;
665}
666/** border_title
667 @brief Draw a box with a title around the specified window
668 @ingroup window_support
669 @param box Pointer to the window to draw the box around
670 @param title Title text to display at the top of the box
671 @details This function draws a box around the specified window, similar to
672 border_draw(), but it also includes a title at the top of the box. The title
673 is displayed in the center of the top edge of the box, and the horizontal line
674 is drawn on either side of the title. Use this function when you want to
675 visually label a window with a title. */
676int border_title(UiSurface *sfc, char *title) {
677 if (!title || !*title)
678 return 0;
679 uint y = 0;
680 uint x = 0;
681 uint l;
682 uint maxx = ui_getmaxx(sfc, BOX);
686 wchar_t *title_wc;
687 title_wc = mbstr_to_wcstr(title);
688 l = wcswidth(title_wc, wcslen(title_wc));
689 l = min(l, maxx - 7);
691 ui_mvwaddnwstr(sfc, BOX, y, x, title_wc, l);
693 x += l;
694 free(title_wc);
697 while (x < maxx - 1)
700 return 0;
701}
702
703/** @defgroup error_handling Error Handling
704 @brief Display Error messages
705 */
706
707/** answer_yn
708 @brief Accept a single letter answer
709 @ingroup error_handling
710 @param msg0 First error message line
711 @param msg1 Second error message line
712 @param msg2 Third error message line
713 @param msg3 Fourth error message line
714 @return Key code of user command */
715int answer_yn(char *msg0, char *msg1, char *msg2, char *msg3) {
716 char title[MAXLEN];
717 uint line, pos, msg_l, msg0_l, msg1_l, msg2_l, msg3_l;
718
719 if (!f_curses_open) {
720 fprintf(stderr, "\n\n%s\n%s\n%s\n%s\n\n", msg0, msg1, msg2, msg3);
721 return 1;
722 }
723
724 Chyron *chyron = new_chyron();
725 set_chyron_key(chyron, 1, "F1 Help", KEY_F01);
726 set_chyron_key(chyron, 2, "N - No", 'n');
727 set_chyron_key(chyron, 3, "Y - Yes", 'y');
728 compile_chyron(chyron);
729
730 uint maxy, maxx;
731 ui_get_screen_size(&maxy, &maxx);
732 msg0_l = strnz(msg0, maxx - 4);
733 msg1_l = strnz(msg1, maxx - 4);
734 msg2_l = strnz(msg2, maxx - 4);
735 msg3_l = strnz(msg1, maxx - 4);
736 msg_l = max(msg0_l, msg1_l);
737 msg_l = max(msg_l, msg2_l);
738 msg_l = max(msg_l, msg3_l);
739 msg_l = max(msg_l, chyron->l);
740 msg_l = min(msg_l, maxx - 4);
741
742 pos = ((maxx - msg_l) - 4) / 2;
743 line = (maxy - 6) / 2;
744 strnz__cpy(title, "Notification", MAXLEN - 1);
745 if (surface_box_win_new(5, msg_l + 2, line, pos, title)) {
746 ssnprintf(title, MAXLEN - 1, "surface_box_win_new(%d, %d, %d, %d, %s) failed", 5,
747 msg_l + 2, line, pos, title);
748 destroy_chyron(chyron);
749 abend(-1, title);
750 }
751 UiSurface *sfc = ui_surface[sfc_ptr];
752 UiEvent event;
753 ui_draw_text(sfc, WIN, 0, 1, msg0);
754 ui_draw_text(sfc, WIN, 1, 1, msg1);
755 ui_draw_text(sfc, WIN, 2, 1, msg2);
756 ui_draw_text(sfc, WIN, 3, 1, msg3);
757 display_chyron(sfc, WIN, chyron, 4, chyron->l + 1);
758
759 do {
761 event.y = event.x = -1;
762 cmd_key = ui_get_event(sfc, WIN, &event, -1);
763 if (cmd_key == KEY_F01 || cmd_key == 'N' || cmd_key == 'n' || cmd_key == 'Y' || cmd_key == 'y')
764 break;
765 } while (1);
767 destroy_chyron(chyron);
768 return (cmd_key);
769}
770/** display_error
771 @brief Display an error message window or print to stderr
772 @ingroup error_handling
773 @param msg0 First error message line
774 @param msg1 Second error message line
775 @param msg2 Third error message line
776 @param msg3 Fourth error message line
777 @return Key code of user command */
778int display_error(char *msg0, char *msg1, char *msg2, char *msg3) {
779 char title[MAXLEN];
780 uint line, pos, msg_l, msg0_l, msg1_l, msg2_l, msg3_l;
781
782 if (!f_curses_open) {
783 fprintf(stderr, "\n\n%s\n", msg0);
784 fprintf(stderr, "%s\n", msg1);
785 fprintf(stderr, "%s\n", msg2);
786 fprintf(stderr, "%s\n\n", msg3);
787 return 1;
788 }
789
790 Chyron *chyron = new_chyron();
791 set_chyron_key(chyron, 1, "F1 Help", KEY_F01);
792 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F09);
793 set_chyron_key(chyron, 10, "F10 Continue", KEY_F10);
794 compile_chyron(chyron);
795
796 uint maxy, maxx;
797 ui_get_screen_size(&maxy, &maxx);
798 msg0_l = strnz(msg0, maxx - 4);
799 msg1_l = strnz(msg1, maxx - 4);
800 msg2_l = strnz(msg2, maxx - 4);
801 msg3_l = strnz(msg1, maxx - 4);
802 msg_l = max(msg0_l, msg1_l);
803 msg_l = max(msg_l, msg2_l);
804 msg_l = max(msg_l, msg3_l);
805 msg_l = max(msg_l, chyron->l);
806 msg_l = min(msg_l, maxx - 4);
807
808 pos = ((maxx - msg_l) - 4) / 2;
809 line = (maxy - 6) / 2;
810 strnz__cpy(title, "Notification", MAXLEN - 1);
811 if (surface_box_win_new(5, msg_l + 2, line, pos, title)) {
812 ssnprintf(title, MAXLEN - 1, "box_win_new(%d, %d, %d, %d, %s) failed", 5,
813 msg_l + 2, line, pos, title);
814 destroy_chyron(chyron);
815 abend(-1, title);
816 }
817 UiSurface *sfc = ui_surface[sfc_ptr];
818 UiEvent event;
819 ui_draw_text(sfc, WIN, 0, 1, msg0);
820 ui_draw_text(sfc, WIN, 1, 1, msg1);
821 ui_draw_text(sfc, WIN, 2, 1, msg2);
822 ui_draw_text(sfc, WIN, 3, 1, msg3);
823
824 display_chyron(sfc, WIN, chyron, 4, chyron->l + 1);
825 do {
826 event.y = event.x = -1;
827 cmd_key = ui_get_event(sfc, WIN, &event, -1);
828 if (cmd_key == KEY_F09 || cmd_key == KEY_F10 || cmd_key == 'q' || cmd_key == 'Q')
829 break;
830 } while (1);
832 destroy_chyron(chyron);
833 return (cmd_key);
834}
835
836/** Perror
837 @brief Display a simple error message window or print to stderr
838 @ingroup error_handling
839 @param emsg_str Error message string
840 @return Key code of user command */
841int Perror(char *emsg_str) {
842 char emsg[MAXLEN];
843 unsigned in_key;
844 uint line, pos, cols;
845 char title[MAXLEN];
846 bool f_xwgetch = true;
847 if (emsg_str[0] == '␛' && emsg_str[1] == 'w') {
848 emsg_str += 2;
849 f_xwgetch = false;
850 }
851 strnz__cpy(emsg, emsg_str, 79);
852 if (!f_curses_open) {
853 fprintf(stderr, "\n%s\n", emsg);
854 return 1;
855 }
856 Chyron *chyron = new_chyron();
857 set_chyron_key(chyron, 1, "F1 Help", KEY_F01);
858 set_chyron_key(chyron, 9, "F9 Cancel", KEY_F09);
859 set_chyron_key(chyron, 10, "F10 Continue", KEY_F10);
860 compile_chyron(chyron);
861 uint maxy, maxx;
862 ui_get_screen_size(&maxy, &maxx);
863 cols = strnz(emsg, maxx - 4);
864 cols = max(cols, chyron->l);
865 ui_get_screen_size(&maxy, &maxx);
866 pos = (maxx - cols - 4) / 2;
867 line = (maxy - 4) / 2;
868 strnz__cpy(title, "Notification", MAXLEN - 1);
869 if (surface_box_win_new(2, cols + 2, line, pos, title)) {
870 ssnprintf(title, MAXLEN - 1, "surface_box_win_new(%d, %d, %d, %d, %s, %b) failed",
871 4, line, line, pos, title);
872 destroy_chyron(chyron);
873 abend(-1, title);
874 }
875 UiSurface *sfc = ui_surface[sfc_ptr];
876 UiEvent event;
877 ui_draw_text(sfc, WIN, 0, 1, emsg_str);
878 display_chyron(sfc, WIN, chyron, 1, chyron->l + 1);
879 if (f_xwgetch) {
880 event.y = event.x = -1;
881 in_key = ui_get_event(sfc, WIN, &event, -1);
882 } else {
883 in_key = KEY_F10;
884 }
885 destroy_chyron(chyron);
887 return (in_key);
888}
889/** action_disposition
890 @brief Display a simple action disposition message window or print to stderr
891 @ingroup error_handling
892 @param title Window title
893 @param action_str Action description string
894 @return true if successful */
895bool action_disposition(char *title, char *action_str) {
896 uint len;
897 uint line, col;
898
899 if (!f_curses_open) {
900 fprintf(stderr, "\n%s\n", title);
901 fprintf(stderr, "%s\n", action_str);
902 return true;
903 }
904 Chyron *chyron = new_chyron();
905 set_chyron_key(chyron, 10, "F10 Continue", KEY_F10);
906 compile_chyron(chyron);
907 len = max(strlen(title), strlen(action_str));
908 uint maxy, maxx;
909 ui_get_screen_size(&maxy, &maxx);
910 col = (maxx - len - 4) / 2;
911 line = (maxy - 4) / 2;
912 if (surface_box_win_new(2, len + 2, line, col, title)) {
913 ssnprintf(em0, MAXLEN - 1, "surface_box_win_new(%d, %d, %d, %d, %s) failed", 4,
914 line, line, col, title);
916 }
917 UiSurface *sfc = ui_surface[sfc_ptr];
918 UiEvent event;
919 ui_draw_text(sfc, WIN, 0, 1, action_str);
920 display_chyron(sfc, WIN, chyron, 1, 0);
921 event.y = event.x = -1;
922 cmd_key = ui_get_event(sfc, WIN, &event, -1);
924 destroy_chyron(chyron);
925 return true;
926}
927/** @defgroup Chyron Chyron Management
928 @brief Create and manage the Chyron
929 */
930
931/** new_chyron
932 @brief Create and initialize Chyron structure
933 @ingroup Chyron
934 @return pointer to new Chyron structure
935 @details This function allocates memory for a new Chyron structure and
936 initializes the key pointers. Each key pointer is allocated memory for a
937 ChyronKey structure. The Chyron structure is used to manage function key
938 labels and their associated keycodes for mouse click handling in the chyron
939 area of the interface.
940 The use of calloc ensures that the allocated memory is initialized to
941 zero, which means that the text for each key will be initialized to an empty
942 string and the keycodes will be initialized to zero. This allows the
943 is_set_chyron_key function to check if a key is set by checking if the first
944 character of the text is not '\0'. If any memory allocation fails, the
945 function will call abend to handle the error and return nullptr.
946 */
947Chyron *new_chyron() {
948 Chyron *chyron = (Chyron *)calloc(1, sizeof(Chyron));
949 if (!chyron) {
950 abend(-1, "calloc chyron failed");
951 return nullptr;
952 }
953 for (int i = 0; i < CHYRON_KEYS; i++) {
954 chyron->key[i] = (ChyronKey *)calloc(1, sizeof(ChyronKey));
955 if (!chyron->key[i]) {
956 abend(-1, "calloc chyron->key[i] failed");
957 return nullptr;
958 }
959 }
960 return chyron;
961}
962int assign_chyron_win(Chyron *chyron, UiSurface *sfc, uint win, char *y) {
963 bool a_toi_error = false;
964 if (!sfc)
965 return -1;
966 chyron->sfc = sfc;
967 chyron->win = win;
968 if (*y == '-')
969 chyron->y = ui_getmaxy(sfc, win) - 1;
970 else {
971 chyron->y = a_toi(y, &a_toi_error);
972 if (a_toi_error)
973 return -1;
974 chyron->y = min(chyron->y, ui_getmaxy(sfc, win) - 1);
975 }
976 return 0;
977}
978/** destroy_chyron
979 @brief Destroy Chyron structure
980 @ingroup Chyron
981 @param chyron pointer to Chyron structure
982 @return nullptr
983 */
984Chyron *destroy_chyron(Chyron *chyron) {
985 uint i;
986
987 if (!chyron)
988 return nullptr;
989 for (i = 0; i < CHYRON_KEYS; i++) {
990 if (chyron->key[i]) {
991 free(chyron->key[i]);
992 chyron->key[i] = nullptr;
993 }
994 }
995 free(chyron);
996 chyron = nullptr;
997 return chyron;
998}
999/** is_set_chyron_key
1000 @brief Check if function key label is set
1001 @ingroup Chyron
1002 @param chyron structure
1003 @param k Function key index (0-19)
1004 @return true if set, false if not set */
1005bool is_set_chyron_key(Chyron *chyron, uint k) {
1006 if (chyron->key[k]->text[0] != '\0')
1007 return true;
1008 else
1009 return false;
1010}
1011/** set_chyron_key
1012 @brief Set chyron key with color pair (cp)
1013 @ingroup Chyron
1014 @param chyron structure
1015 @param k chyron key index (0-19)
1016 @param s chyron key label
1017 @param kc chyron key code
1018 @param cp color pair index for the key label
1019 @details This function is like set_chyron_key, except it includes a color
1020 pair numbers */
1021void set_chyron_key_cb(Chyron *chyron, uint k, char *s, uint kc, UiCell cell_base) {
1022 if (*s != '\0')
1023 ssnprintf(chyron->key[k]->text, CHYRON_KEY_MAXLEN - 1, "%s", s);
1024 else
1025 chyron->key[k]->text[0] = '\0';
1026 chyron->key[k]->keycode = kc;
1027 chyron->key[k]->active = true;
1028 chyron->key[k]->cell_base = cell_base;
1029}
1030/** set_chyron_key
1031 @brief Set chyron key with default color pair (cp_nt_rev)
1032 @ingroup Chyron
1033 @param chyron structure
1034 @param k chyron key index (0-19)
1035 @param s chyron key label
1036 @param kc chyron key code
1037 @details This function sets the label and keycode for a function key in the
1038 chyron structure. It uses the default color pair cp_nt_rev for the key
1039 label. If the input string s is not empty, it copies the string into the
1040 chyron key's text field. If the input string is empty, it sets the first
1041 character of the text field to '\0' to indicate that the key is not set.
1042 The keycode is stored in the chyron key's keycode field, and the color pair
1043 index is set to cp_nt_rev.
1044 */
1045void set_chyron_key(Chyron *chyron, uint k, char *s, uint kc) {
1046 if (*s != '\0')
1047 ssnprintf(chyron->key[k]->text, CHYRON_KEY_MAXLEN - 1, "%s", s);
1048 else
1049 chyron->key[k]->text[0] = '\0';
1050 chyron->key[k]->keycode = kc;
1051 chyron->key[k]->active = true;
1052 chyron->key[k]->cell_base = cell_nt_rev;
1053}
1054/** unset_chyron_key
1055 @brief Unset chyron key
1056 @ingroup Chyron
1057 @param chyron structure
1058 @param k chyron_key index
1059*/
1060void unset_chyron_key(Chyron *chyron, uint k) {
1061 chyron->key[k]->text[0] = '\0';
1062}
1063/** activate_chyron_key
1064 @brief Activate chyron key
1065 @ingroup Chyron
1066 @param chyron structure
1067 @param k chyron_key index
1068*/
1069void activate_chyron_key(Chyron *chyron, uint k) {
1070 chyron->key[k]->active = true;
1071}
1072/** deactivate_chyron_key
1073 @brief Deactivate chyron key
1074 @ingroup Chyron
1075 @param chyron structure
1076 @param k chyron_key index
1077*/
1078void activate_all_chyron_keys(Chyron *chyron) {
1079 for (int k = 0; k < CHYRON_KEYS; k++)
1080 chyron->key[k]->active = true;
1081}
1082/** deactivate_chyron_key
1083 @brief Deactivate chyron key
1084 @ingroup Chyron
1085 @param chyron structure
1086 @param k chyron_key index
1087*/
1088void deactivate_chyron_key(Chyron *chyron, uint k) {
1089 chyron->key[k]->active = false;
1090}
1091/** deactivate_all_chyron_keys
1092 @brief Deactivate all chyron keys
1093 @ingroup Chyron
1094 @param chyron structure
1095*/
1096void deactivate_all_chyron_keys(Chyron *chyron) {
1097 for (int k = 0; k < CHYRON_KEYS; k++)
1098 chyron->key[k]->active = false;
1099}
1100/** compile_chyron
1101 @brief construct the chyron string from the chyron structure
1102 @ingroup Chyron
1103 @param chyron
1104 @details The chyron string is constructed by concatenating the labels of the
1105 set keys, separated by " | ". The end_pos values for each key are set to
1106 determine the zones for mouse clicks. When a mouse click occurs, the
1107 get_chyron_key function uses the end_pos values to determine which key was
1108 clicked based on the X position of the click.
1109*/
1110void compile_chyron(Chyron *chyron) {
1111 uint end_pos = 0;
1112 uint k = 0;
1113 uint pos = 0;
1114 UiCell cell_base = cell_nt_rev;
1115 UiCell *cx;
1116 char tmp_str[MAXLEN];
1117 while (k < CHYRON_KEYS) {
1118 if (chyron->key[k]->text[0] == '\0' || !chyron->key[k]->active) {
1119 k++;
1120 continue;
1121 }
1122 cell_base = chyron->key[k]->cell_base;
1123 if (end_pos == 0) {
1124 cx = chyron->cmplx_buf;
1126 " ",
1127 &cell_base,
1128 &pos,
1129 MAXLEN - 1);
1130 } else {
1132 "|",
1133 &cell_base,
1134 &pos,
1135 MAXLEN - 1);
1136 }
1137 cx = chyron->cmplx_buf;
1138 mbstr_to_cellstr(cx, chyron->key[k]->text, &cell_base, &pos, MAXLEN - 1);
1139 end_pos = pos;
1140 chyron->l = end_pos;
1141 chyron->key[k]->end_pos = end_pos;
1142 ssnprintf(tmp_str, MAXLEN - 1, "k=%d, text=%s, end_pos=%d", k,
1143 chyron->key[k]->text, chyron->key[k]->end_pos);
1144 k++;
1145 }
1146 mbstr_to_cellstr(chyron->cmplx_buf, " ", &cell_base, &pos, MAXLEN - 1);
1147 chyron->l = end_pos;
1148}
1149/** display_chyron
1150 * @brief Display chyron on the specified line and column of the surface
1151 @ingroup Chyron
1152 @param sfc Pointer to the UiSurface structure
1153 @param w Window index (WIN or BOX)
1154 @param chyron Pointer to the Chyron structure
1155 @param line Line number where the chyron should be displayed
1156 @param col Column number where the chyron should start
1157 @details This function displays the compiled chyron string on the specified
1158 line and column of the given surface. It first moves the cursor to the
1159 specified position, clears to the end of the line, and then writes the chyron
1160 string. Finally, it moves the cursor back to the specified column for user
1161 input.
1162 */
1163void display_chyron(UiSurface *sfc, uint w, Chyron *chyron, uint line, uint col) {
1164 ui_wmove(sfc, w, line, 0);
1165 ui_wclrtoeol(sfc, w);
1166 ui_wmove(sfc, w, line, 0);
1167 ui_mvwadd_wchstr(sfc, w, line, 0, chyron->cmplx_buf);
1168 ui_wmove(sfc, w, line, col);
1169 return;
1170}
1171/** get_chyron_key
1172 @brief Get keycode from chyron
1173 @ingroup Chyron
1174 @param chyron structure
1175 @param x Mouse X position
1176 @return Keycode
1177 @details This function uses the end_pos values set in compile_chyron
1178 to determine which key was clicked.
1179 The chyron functions provide xwgetch() with a mechanism to translate
1180 mouse click positions into key codes based on the labels set in the chyron
1181 structure. When a mouse click occurs, xwgetch() can call get_chyron_key()
1182 with the X position of the click to determine which function key was clicked,
1183 allowing for dynamic and customizable function key behavior in the chyron
1184 area of the interface.
1185*/
1186int get_chyron_key(Chyron *chyron, uint x) {
1187 uint i = 0;
1188 uint k = -1;
1189 while (i < CHYRON_KEYS - 1) {
1190 if (chyron->key[i]->text[0] != '\0' && chyron->key[i]->active)
1191 if (chyron->key[i]->end_pos >= x) {
1192 k = i;
1193 break;
1194 }
1195 i++;
1196 }
1197 return chyron->key[k]->keycode;
1198}
1199/** abend
1200 @brief Abnormal program termination
1201 @ingroup error_handling
1202 @param ec Exit code
1203 @param s Error message */
1204void abend(int ec, char *s) {
1208 fprintf(stderr, "\n\nABEND: %s (code: %d)\n", s, ec);
1209 exit(EXIT_FAILURE);
1210}
bool f_curses_open
Definition sig.c:33
#define CHYRON_KEYS
Definition cm.h:375
#define CHYRON_KEY_MAXLEN
Definition cm.h:372
@ CLR_CMDLN_BG
Definition cm.h:197
@ CLR_FILL_CHAR_BG
Definition cm.h:193
@ CLR_BOX_BG
Definition cm.h:187
@ CLR_FILL_CHAR_FG
Definition cm.h:192
@ CLR_FG
Definition cm.h:184
@ CLR_RED
Definition cm.h:168
@ CLR_NT_FG
Definition cm.h:198
@ CLR_BRACKETS_FG
Definition cm.h:190
@ CLR_YELLOW
Definition cm.h:170
@ CLR_IND_FG
Definition cm.h:188
@ CLR_BCYAN
Definition cm.h:181
@ CLR_TITLE_FG
Definition cm.h:206
@ CLR_WHITE
Definition cm.h:174
@ CLR_MAGENTA
Definition cm.h:172
@ CLR_BRACKETS_BG
Definition cm.h:191
@ CLR_NT_REV_BG
Definition cm.h:201
@ CLR_BLACK
Definition cm.h:167
@ CLR_BWHITE
Definition cm.h:182
@ CLR_LN_BG
Definition cm.h:195
@ CLR_NT_HL_REV_BG
Definition cm.h:205
@ CLR_BBLACK
Definition cm.h:175
@ CLR_LN_FG
Definition cm.h:194
@ CLR_NT_HL_FG
Definition cm.h:202
@ CLR_BBLUE
Definition cm.h:179
@ CLR_BGREEN
Definition cm.h:177
@ CLR_BYELLOW
Definition cm.h:178
@ CLR_BMAGENTA
Definition cm.h:180
@ CLR_BORANGE
Definition cm.h:183
@ CLR_NT_HL_BG
Definition cm.h:203
@ CLR_NT_HL_REV_FG
Definition cm.h:204
@ CLR_BG
Definition cm.h:185
@ CLR_BOX_FG
Definition cm.h:186
@ CLR_NT_BG
Definition cm.h:199
@ CLR_TITLE_BG
Definition cm.h:207
@ CLR_BRED
Definition cm.h:176
@ CLR_NCOLORS
Definition cm.h:208
@ CLR_BLUE
Definition cm.h:171
@ CLR_IND_BG
Definition cm.h:189
@ CLR_GREEN
Definition cm.h:169
@ CLR_CMDLN_FG
Definition cm.h:196
@ CLR_NT_REV_FG
Definition cm.h:200
@ CLR_CYAN
Definition cm.h:173
#define min(x, y)
min macro evaluates two expressions, returning least result
Definition cm.h:91
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
Definition cm.h:84
#define bw_ho
Definition ui_backend.h:213
const wchar_t * bw_sp
Definition ui_ncurses.c:52
void ui_render()
Definition ui_ncurses.c:800
int ui_mvwadd_wchstr(UiSurface *s, uint w, uint y, uint x, const UiCell *cell)
const wchar_t * bw_ran
Definition ui_ncurses.c:57
int ui_bkgdset(UiSurface *s, uint w, const UiCell *cell)
Definition ui_ncurses.c:760
int ui_mvwaddnwstr(UiSurface *s, uint w, uint y, uint x, const wchar_t *wstr, int m)
int ui_mvwadd_wchnstr(UiSurface *s, uint w, uint y, uint x, const UiCell *cell, uint m)
#define bw_tr
Definition ui_backend.h:221
const wchar_t * bw_chk
Definition ui_ncurses.c:59
int ui_get_event(UiSurface *s, uint w, UiEvent *ev, int timeout_ms)
Wait for an input event on target (or stdscr if NULL).
uint16_t attr_t
Definition ui_backend.h:256
int ui_draw_text(UiSurface *s, uint w, uint y, uint x, const char *text)
#define bw_lt
Definition ui_backend.h:215
void ui_surface_destroy(UiSurface *s)
Definition ui_ncurses.c:377
#define bw_br
Definition ui_backend.h:223
#define ERR
Definition ui_backend.h:249
STDRGB std_color[]
Definition ui_ncurses.c:62
int ui_wmove(UiSurface *s, uint w, uint y, uint x)
Definition ui_ncurses.c:732
#define bw_bl
Definition ui_backend.h:222
UiSurface * ui_surface[UI_SFC_MAX]
Definition ui_ncurses.c:28
void ui_get_screen_size(uint *lines, uint *cols)
Definition ui_ncurses.c:692
void ui_shutdown()
Definition ui_ncurses.c:344
int ui_wclrtoeol(UiSurface *s, uint w)
int sfc_ptr
Definition nckeys.c:47
UiCell ui_cell_from_ucp(const wchar_t *ucp, const uint32_t *fg, const uint32_t *bg)
Definition ui_ncurses.c:239
int ui_curs_set(int visibility)
Definition ui_ncurses.c:737
#define bw_tt
Definition ui_backend.h:217
struct nccell UiCell
Definition ui_backend.h:250
#define bw_cr
Definition ui_backend.h:219
uint ui_color_cnt
Definition ui_ncurses.c:33
#define bw_bt
Definition ui_backend.h:218
UiSurface * ui_box_surface_new(UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x, char *title)
Definition ui_ncurses.c:453
#define bw_ve
Definition ui_backend.h:214
#define bw_rt
Definition ui_backend.h:216
#define SFC_MAX
Definition ui_backend.h:25
#define bw_tl
Definition ui_backend.h:220
int ui_surface_addwin(UiSurface *s, uint w, uint p, uint lines, uint cols, uint y, uint x)
Definition ui_ncurses.c:523
int ui_chg_color(uint16_t color_idx, uint32_t *color)
Definition ui_ncurses.c:206
#define KEY_F01
#define KEY_F09
#define KEY_F10
int ui_getmaxx(UiSurface *s, uint w)
Definition ui_ncurses.c:686
uint ui_add_pair(uint fg, uint bg)
Definition ui_ncurses.c:105
int ui_getcchar(const UiCell *uc, wchar_t *wstr, attr_t *attrs, uint16_t *pair, void *opts)
Definition ui_ncurses.c:784
int ui_getmaxy(UiSurface *s, uint w)
Definition ui_ncurses.c:681
int ui_setcchar(cchar_t *wch, const wchar_t *wc, const attr_t attrs, short pair, const void *opts)
Definition ui_ncurses.c:792
#define MAXLEN
Definition curskeys.c:15
uint rgb_to_xterm256_idx(RGB *rgb)
Convert RGB color to XTerm 256 color index.
Definition dwin.c:252
uint16_t box_attr
Definition dwin.c:131
unsigned int cmd_key
Definition dwin.c:128
UiCell cell_sp
Definition dwin.c:120
uint m_begx
Definition dwin.c:135
UiCell cell_ve
Definition dwin.c:112
ushort cp_nt
Definition dwin.c:151
UiCell cell_tr
Definition dwin.c:110
int surface_box_win_new(uint wlines, uint wcols, uint wbegy, uint wbegx, char *wtitle)
Definition dwin.c:521
UiCell cell_nt
Definition dwin.c:94
int pipe_in
Definition dwin.c:164
char const colors_text[][10]
Color names for .minitrc overrides.
Definition dwin.c:51
UiCell cell_ls
Definition dwin.c:105
UiCell cell_nt_hl_rev
Definition dwin.c:97
char em1[MAXLEN]
Definition dwin.c:143
UiCell cell_bt
Definition dwin.c:118
UiCell cell_br
Definition dwin.c:114
bool f_sigwench
Definition dwin.c:129
ushort cp_green
Definition dwin.c:160
UiCell cell_tl
Definition dwin.c:109
int tty_fd
Definition dwin.c:164
ushort cp_red
Definition dwin.c:159
ushort cp_box
Definition dwin.c:147
char em2[MAXLEN]
Definition dwin.c:144
wchar_t * mbstr_to_wcstr(const char *mb_str)
Definition dwin.c:404
ushort cp_blue
Definition dwin.c:162
UiCell cell_ln
Definition dwin.c:102
int stdout_fd
Definition dwin.c:138
uint m_lines
Definition dwin.c:132
void initialize_cells(SIO *sio)
Initialize local color variables and color pairs based on SIO settings.
Definition dwin.c:177
UiCell cell_ts
Definition dwin.c:107
double BLUE_GAMMA
Definition dwin.c:125
Cells
Definition dwin.c:56
@ _FILL_CHAR
Definition dwin.c:58
@ _BRKTL
Definition dwin.c:59
@ _CMDLN
Definition dwin.c:67
@ _BT
Definition dwin.c:85
@ _NT_HL
Definition dwin.c:63
@ _NT_HL_REV
Definition dwin.c:64
@ _IND
Definition dwin.c:66
@ _SP
Definition dwin.c:87
@ _BS
Definition dwin.c:75
@ _RAN
Definition dwin.c:70
@ _BRKTR
Definition dwin.c:60
@ _NT
Definition dwin.c:61
@ _TITLE
Definition dwin.c:68
@ _BL
Definition dwin.c:80
@ _VE
Definition dwin.c:79
@ _HO
Definition dwin.c:78
@ _LN
Definition dwin.c:69
@ _TT
Definition dwin.c:84
@ _CR
Definition dwin.c:86
@ _CHK
Definition dwin.c:71
@ _TS
Definition dwin.c:74
@ _TR
Definition dwin.c:77
@ _LS
Definition dwin.c:72
@ _NT_REV
Definition dwin.c:62
@ _BOX
Definition dwin.c:65
@ _DEFAULT
Definition dwin.c:57
@ _BR
Definition dwin.c:81
@ _TL
Definition dwin.c:76
@ _RT
Definition dwin.c:83
@ _RS
Definition dwin.c:73
@ _LT
Definition dwin.c:82
ushort cp_nt_hl
Definition dwin.c:153
int border_draw(UiSurface *sfc)
Definition dwin.c:581
ushort cp_cmdln
Definition dwin.c:149
ushort cp_fill_char
Definition dwin.c:157
UiCell cell_tt
Definition dwin.c:117
UiCell cell_bs
Definition dwin.c:108
ushort cp_brackets
Definition dwin.c:158
ushort cp_yellow
Definition dwin.c:161
UiCell cell_ho
Definition dwin.c:111
uint mouse_support
Definition dwin.c:136
UiCell cell_rs
Definition dwin.c:106
bool init_clr_palette(SIO *sio)
Initialize color palette based on SIO settings.
Definition dwin.c:333
UiCell cell_default
Definition dwin.c:90
uint m_cols
Definition dwin.c:133
int click_x
Definition dwin.c:45
char fn[MAXLEN]
Definition dwin.c:141
int surface_split_box_win_new(uint wlines, uint wcols, uint split_y, uint split_x, uint wbegy, uint wbegx, char *wtitle)
Definition dwin.c:539
void mbc_to_wc(wchar_t wc[2], const char mbc)
Definition dwin.c:393
ushort cp_nt_hl_rev
Definition dwin.c:154
ushort cp_default
Definition dwin.c:156
UiCell cell_nt_hl
Definition dwin.c:96
ushort cp_nt_rev
Definition dwin.c:152
ushort cp_ln
Definition dwin.c:155
char em3[MAXLEN]
Definition dwin.c:145
ushort cp_title
Definition dwin.c:150
uint src_line
Definition dwin.c:139
void apply_gamma(RGB *rgb)
Apply gamma correction to RGB color.
Definition dwin.c:307
RGB xterm256_idx_to_rgb(uint idx)
Convert XTerm 256 color index to RGB.
Definition dwin.c:274
UiCell cell_lt
Definition dwin.c:115
int exit_code
Definition dwin.c:127
UiCell cell_brktl
Definition dwin.c:92
UiCell cell_cr
Definition dwin.c:119
UiCell cell_title
Definition dwin.c:101
int click_y
Definition dwin.c:44
uint16_t win_attr
Definition dwin.c:130
int stdin_fd
Definition dwin.c:137
char em0[MAXLEN]
Definition dwin.c:142
UiCell cell_ind
Definition dwin.c:99
uint m_begy
Definition dwin.c:134
double GRAY_GAMMA
Definition dwin.c:122
UiCell cell_ran
Definition dwin.c:103
double RED_GAMMA
Definition dwin.c:123
int assign_chyron_win(Chyron *chyron, UiSurface *sfc, uint win, char *y)
Definition dwin.c:962
char * src_name
Definition dwin.c:140
UiCell cell_cmdln
Definition dwin.c:100
UiCell cell_brktr
Definition dwin.c:93
ushort cp_ind
Definition dwin.c:148
int pipe_out
Definition dwin.c:164
double GREEN_GAMMA
Definition dwin.c:124
UiCell cell_fill_char
Definition dwin.c:91
UiCell cell_box
Definition dwin.c:98
UiCell cell_rt
Definition dwin.c:116
UiCell cell_bl
Definition dwin.c:113
UiCell cell_chk
Definition dwin.c:104
UiCell cell_nt_rev
Definition dwin.c:95
int stderr_fd
Definition dwin.c:164
int border_ysplit(UiSurface *sfc, uint y)
Draw a box with a separator line around the specified window.
Definition dwin.c:617
int border_ysplit_text(UiSurface *sfc, char *text, uint separator_line)
Draw a box with a separator line and text around the specified window.
Definition dwin.c:637
int cm_surface_destroy(UiSurface *sfc)
Destroy the most recently created surface.
Definition dwin.c:576
int border_title(UiSurface *sfc, char *title)
Draw a box with a title around the specified window.
Definition dwin.c:676
void destroy_curses()
Gracefully shut down NCurses and restore terminal settings.
Definition dwin.c:384
bool action_disposition(char *title, char *action_str)
Display a simple action disposition message window or print to stderr.
Definition dwin.c:895
int answer_yn(char *msg0, char *msg1, char *msg2, char *msg3)
Accept a single letter answer.
Definition dwin.c:715
int Perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition dwin.c:841
void abend(int ec, char *s)
Abnormal program termination.
Definition dwin.c:1204
int display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
Definition dwin.c:778
void set_chyron_key_cb(Chyron *chyron, uint k, char *s, uint kc, UiCell cell_base)
Set chyron key with color pair (cp).
Definition dwin.c:1021
Chyron * destroy_chyron(Chyron *chyron)
Destroy Chyron structure.
Definition dwin.c:984
void compile_chyron(Chyron *chyron)
construct the chyron string from the chyron structure
Definition dwin.c:1110
int get_chyron_key(Chyron *chyron, uint x)
Get keycode from chyron.
Definition dwin.c:1186
void activate_all_chyron_keys(Chyron *chyron)
Deactivate chyron key.
Definition dwin.c:1078
void unset_chyron_key(Chyron *chyron, uint k)
Unset chyron key.
Definition dwin.c:1060
void activate_chyron_key(Chyron *chyron, uint k)
Activate chyron key.
Definition dwin.c:1069
uint mbstr_to_cellstr(UiCell *cmplx_buf, const char *str, const UiCell *cell_base, uint *pos, const uint atmost)
Convert multibyte string to complex character array.
Definition dwin.c:480
void deactivate_all_chyron_keys(Chyron *chyron)
Deactivate all chyron keys.
Definition dwin.c:1096
Chyron * new_chyron()
Create and initialize Chyron structure.
Definition dwin.c:947
bool is_set_chyron_key(Chyron *chyron, uint k)
Check if function key label is set.
Definition dwin.c:1005
void display_chyron(UiSurface *sfc, uint w, Chyron *chyron, uint line, uint col)
Display chyron on the specified line and column of the surface.
Definition dwin.c:1163
void deactivate_chyron_key(Chyron *chyron, uint k)
Deactivate chyron key.
Definition dwin.c:1088
void set_chyron_key(Chyron *chyron, uint k, char *s, uint kc)
Set chyron key with default color pair (cp_nt_rev).
Definition dwin.c:1045
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition futil.c:537
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
Definition futil.c:608
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Definition futil.c:413
int a_toi(char *, bool *)
a safer alternative to atoi() for converting ASCII strings to integers.
Definition futil.c:762
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:42
uint8_t g
Definition ui_backend.h:261
uint8_t r
Definition ui_backend.h:260
uint8_t b
Definition ui_backend.h:262
char text[CHYRON_KEY_MAXLEN]
Definition cm.h:379
uint keycode
Definition cm.h:381
bool active
Definition cm.h:378
UiCell cell_base
Definition cm.h:383
uint end_pos
Definition cm.h:382
uint y
Definition cm.h:394
UiSurface * sfc
Definition cm.h:392
UiCell cmplx_buf[MAXLEN]
Definition cm.h:389
uint win
Definition cm.h:393
ChyronKey * key[CHYRON_KEYS]
Definition cm.h:387
uint l
Definition cm.h:391
uint32_t ran_bg
Definition cm.h:737
double green_gamma
Definition cm.h:690
uint32_t ln_bg
Definition cm.h:723
double blue_gamma
Definition cm.h:691
char brackets[3]
Definition cm.h:750
uint32_t magenta
Definition cm.h:698
uint32_t cmdln_bg
Definition cm.h:725
uint32_t cmdln_fg
Definition cm.h:724
uint32_t nt_hl_rev_fg
Definition cm.h:732
uint32_t ran_fg
Definition cm.h:736
uint32_t bgreen
Definition cm.h:704
double red_gamma
Definition cm.h:689
uint32_t green
Definition cm.h:695
uint32_t nt_fg
Definition cm.h:726
uint32_t yellow
Definition cm.h:696
uint32_t fill_char_fg
Definition cm.h:720
uint32_t box_fg
Definition cm.h:714
uint32_t ln_fg
Definition cm.h:722
uint32_t ind_bg
Definition cm.h:717
uint32_t bmagenta
Definition cm.h:707
uint32_t ind_fg
Definition cm.h:716
uint32_t byellow
Definition cm.h:705
uint32_t bblue
Definition cm.h:706
uint32_t borange
Definition cm.h:710
uint32_t title_bg
Definition cm.h:735
uint32_t fg
Definition cm.h:712
uint32_t cyan
Definition cm.h:699
uint32_t bblack
Definition cm.h:702
uint32_t red
Definition cm.h:694
uint32_t nt_hl_rev_bg
Definition cm.h:733
uint32_t title_fg
Definition cm.h:734
uint32_t bred
Definition cm.h:703
uint32_t fill_char_bg
Definition cm.h:721
uint32_t black
Definition cm.h:693
uint32_t nt_rev_bg
Definition cm.h:729
uint32_t brackets_bg
Definition cm.h:719
uint32_t bcyan
Definition cm.h:708
uint32_t nt_bg
Definition cm.h:727
uint32_t blue
Definition cm.h:697
uint32_t brackets_fg
Definition cm.h:718
uint32_t white
Definition cm.h:700
uint32_t box_bg
Definition cm.h:715
uint32_t nt_hl_fg
Definition cm.h:730
uint32_t bwhite
Definition cm.h:709
uint32_t nt_rev_fg
Definition cm.h:728
double gray_gamma
Definition cm.h:692
uint32_t nt_hl_bg
Definition cm.h:731
uint32_t bg
Definition cm.h:713