C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
menu.c
Go to the documentation of this file.
1/** @file menu.c
2 @brief Command line start-up for C-Menu components
3 @author Bill Waller
4 Copyright (c) 2025
5 MIT License
6 billxwaller@gmail.com
7 @date 2026-02-09
8 */
9#define _GNU_SOURCE
10#include "ui/ui_ncurses_internal.h"
11#include "ui_backend.h"
12#include <common.h>
13#include <string.h>
14
15/** @brief This function is responsible for cleaning up the terminal state and
16 exiting the program.
17 @details This function is typically registered to be called when the program
18 exits, ensuring that the terminal is properly restored to its original state,
19 even if the program encounters an error or is terminated unexpectedly. The
20 end_pgm function performs the following actions:
21 1. It calls win_del() to delete any windows that may have been created
22 during the program's execution.
23 2. It calls destroy_curses() to clean up the ncurses library and restore the
24 terminal to its normal state.
25 3. It calls restore_shell_tioctl() to restore the terminal's input/output
26 settings to their original state.
27 4. Finally, it calls exit(EXIT_FAILURE) to terminate the program with a
28 failure status, indicating that the program has encountered an error or is
29 exiting due to an unexpected condition. By defining this function and
30 registering it to be called on program exit, you can help ensure that the
31 terminal is properly cleaned up and restored, preventing any issues with the
32 terminal state after the program has exited. */
33static void end_pgm(void) {
34 curs_set(1);
35 close(cmenu_log_fd);
36 if (f_curses_open)
37 endwin();
38 exit(EXIT_SUCCESS);
39}
40
41int main(int argc, char **argv) {
42 int rc;
43 char pgm_name[MAXLEN];
45 Init *init = new_init(argc, argv);
46 SIO *sio = init->sio;
47 mapp_initialization(init, argc, argv);
48 rc = atexit(end_pgm);
49 if (rc != 0) {
50 fprintf(stderr, "\nCannot set exit function\n");
51 exit(EXIT_FAILURE);
52 }
53#ifdef UAL_UI
54 UiConfig *ui_config = calloc(1, sizeof(UiConfig));
55 ui_config->enable_mouse = true;
56 ui_config->enable_alt_screen = false;
57 ui_config->cursor_visible = true;
58 ui_runtime = ui_init(ui_config);
59#else
61#endif
65 base_name(pgm_name, argv[0]);
66 if (!strcmp(pgm_name, "menu")) {
67 new_menu(init, init->argc, init->argv, LINES / 14, COLS / 14);
68 menu_engine(init);
69 } else if (!strcmp(pgm_name, "form")) {
70 init_form(init, init->argc, init->argv, LINES / 14, COLS / 14);
71 } else if (!strcmp(pgm_name, "pick")) {
72 init_pick(init, init->argc, init->argv, 0, 0);
73 } else if (!strcmp(pgm_name, "view")) {
74 View *view = new_view(init);
75 if (init->lines > 0 || init->cols > 0) {
76 if (init->h_shift == 0)
77 init->h_shift = view->cols / 3;
78 if (!init_view_boxwin(init)) {
79 view_file(init);
80 }
81 } else if (!init_view_full_screen(init)) {
82 view_file(init);
83 }
84 } else if (!strcmp(pgm_name, "ckeys"))
89 exit(EXIT_SUCCESS);
90}
int popup_ckeys()
Display Curses Keys Responds to curses keys and mouse events, displaying the key code and description...
Definition curskeys.c:23
int cmenu_log_fd
Definition futil.c:54
bool f_curses_open
Definition sig.c:33
#define MAXLEN
Definition curskeys.c:15
int main(int argc, char **argv)
Definition amort.c:30
bool open_curses(SIO *)
Initialize NCurses and color settings.
Definition dwin.c:244
void destroy_curses()
Gracefully shut down NCurses and restore terminal settings.
Definition dwin.c:670
void initialize_local_colors(SIO *)
Initialize local color variables and color pairs based on SIO settings.
Definition dwin.c:320
int init_form(Init *, int, char **, int, int)
Initialize form data structure and parse description file.
Definition form_engine.c:61
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:1123
void mapp_initialization(Init *, int, char **)
Main initialization function for MAPP - Menu Application.
Definition init.c:441
int init_view_full_screen(Init *)
Initialize C-Menu View in full screen mode.
Definition init_view.c:49
int init_view_boxwin(Init *)
Initialize the C-Menu View in box window mode.
Definition init_view.c:194
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:356
Init * new_init(int, char **)
Create and initialize Init structure.
Definition mem.c:71
Menu * new_menu(Init *, int, char **, int, int)
Create and initialize Menu structure.
Definition mem.c:145
View * new_view(Init *)
Create and initialize View structure.
Definition mem.c:310
Init * destroy_init(Init *init)
Destroy Init structure.
Definition mem.c:106
unsigned int menu_engine(Init *)
The main loop of the menu system.
Definition menu_engine.c:38
int init_pick(Init *, int, char **, int, int)
Initializes pick structure and opens pick input file or pipe.
Definition pick_engine.c:66
bool capture_shell_tioctl()
capture_shell_tioctl() - capture shell terminal settings
Definition scriou.c:43
bool capture_curses_tioctl()
capture_curses_tioctl() - capture curses terminal settings
Definition scriou.c:68
void sig_prog_mode()
Set up signal handlers for interrupt signals.
Definition sig.c:62
int view_file(Init *)
Start view.
SIO * sio
Definition common.h:114
int argc
Definition common.h:130
int cols
Definition common.h:116
int h_shift
Definition common.h:181
char ** argv
Definition common.h:131
int lines
Definition common.h:115
int cols
Definition view.h:54