C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
pick_engine.c
Go to the documentation of this file.
1/** @file pick_engine.c
2 @brief pick from a list of choices
3 @author Bill Waller
4 Copyright (c) 2025
5 MIT License
6 billxwaller@gmail.com
7 @date 2026-02-09
8 */
9
10/** @defgroup pick_engine Object Selection
11 @brief Navigate, Select, and Perform Action on Objects
12 */
13
14#include "common.h"
15#include <fcntl.h>
16#include <stdbool.h>
17#include <string.h>
18#include <sys/mman.h>
19#include <sys/stat.h>
20#include <sys/wait.h>
21#include <termios.h>
22#include <unistd.h>
25int pick_engine(Init *);
26void save_object(Pick *, char *);
27int picker(Init *, char *field);
28void display_pick_page(Pick *);
29void reverse_object(Pick *);
30void unreverse_object(Pick *);
31void toggle_object(Pick *);
32int output_objects(Pick *);
33int exec_objects(Init *);
34int open_pick_win(Init *);
35void display_pick_help(Init *);
36int read_pick_input(Init *);
37void deselect_object(Pick *);
38int read_theme(Init *);
39int new_pick_view(Init *);
40void new_view_file(Init *, char *);
41void end_pick_view(Init *);
42void destroy_pick_view(Init *);
43int match_objects(Pick *pick, char *s);
44void remove_right_angle(Pick *);
45void pick_std_chyron(Pick *);
46int pipe_fd[2];
47
48UiMultiMedia ui_mm;
49
50char const pagers_editors[12][10] = {"view", "view", "less", "more",
51 "vi", "vim", "nano", "nvim",
52 "pico", "emacs", "edit", ""};
53
54/** @brief Initializes pick structure and opens pick input file or pipe
55 * @ingroup pick_engine
56 @param init Pointer to Init structure
57 @param argc Argument count
58 @param argv Argument vector
59 @param by Beginning y coordinate for pick window
60 @param bx Beginning x coordinate for pick window
61 @details If provider_cmd is specified, it takes precedence over in_spec and
62 input file arguments.
63 provider_cmd is executed and its output is read as pick input
64 If provider_cmd is not specified, in_spec is used to read pick
65 input from a file or stdin
66 If provider_cmd is specified, it is executed and its output is
67 read as pick input */
68int init_pick(Init *init, int argc, char **argv, uint by, uint bx) {
69 struct stat sb;
70 char *s_argv[MAXARGS];
71 int s_argc;
72 char tmp_str[MAXLEN];
73 pid_t pid = 0;
74
75 Pick *pick = new_pick(init, argc, argv, by, bx);
76 if (init->pick != pick)
77 ui_abend(-1, "init->pick != pick\n");
78 // SIO *sio = init->sio;
79 if (pick->provider_cmd[0] != '\0') {
80 s_argc = str_to_args(s_argv, pick->provider_cmd, MAXARGS - 1);
81 if (pipe(pipe_fd) == -1) {
82 ui_perror(_("pipe(pipe_fd) failed in init_pick"));
83 return (1);
84 }
85
86 if ((pid = fork()) == -1) {
87 ui_perror(_("fork() failed in init_pick"));
88 return (1);
89 }
90 if (pid == 0) {
91 /** Prevent child process from writing to terminal */
92 int dev_null = open("/dev/null", O_WRONLY);
93 if (dev_null == -1) {
94 ui_perror(_("open(/dev/null) failed in init_pick child process"));
95 exit(EXIT_FAILURE);
96 }
97 dup2(dev_null, STDERR_FILENO);
98 /** Close read end of pipe as Child only needs to write to pipe */
99 close(dev_null);
100 close(pipe_fd[P_READ]);
101 /** Connect CHILD STDOUT to write end of pipe */
102 dup2(pipe_fd[P_WRITE], STDOUT_FILENO);
103 /** STDOUT attached to write end of pipe, so close pipe fd */
104 close(pipe_fd[P_WRITE]);
105 execvp(s_argv[0], s_argv);
106 strnz__cpy(tmp_str, _("Can't exec pick start cmd: "), MAXLEN - 1);
107 strnz__cat(tmp_str, s_argv[0], MAXLEN - 1);
108 ui_perror(tmp_str);
109 exit(EXIT_FAILURE);
110 }
111 /** Return to Parent
112 Close write end of pipe as Parent only needs to read from pipe */
113 /** Open a file pointer on read end of pipe */
114 close(pipe_fd[P_WRITE]);
115 pick->in_fp = fdopen(pipe_fd[P_READ], "rb");
116 pick->f_in_pipe = true;
117 destroy_argv(s_argc, s_argv);
118 } else {
119 if ((pick->in_spec[0] == '\0') || strcmp(pick->in_spec, "-") == 0 || strcmp(pick->in_spec, "/dev/stdin") == 0) {
120 strnz__cpy(pick->in_spec, "/dev/stdin", MAXLEN - 1);
121 pick->in_fp = fdopen(STDIN_FILENO, "rb");
122 pick->f_in_pipe = true;
123 }
124 }
125 stdio_fdnames(stdio_names_str, "pick_engine.c 122");
126 if (!pick->f_in_pipe) {
127 /** No provider_cmd specified, so read pick input from file or stdin */
128 if (lstat(pick->in_spec, &sb) == -1) {
129 strnz__cpy(tmp_str, _("Can\'t stat pick input file: "), MAXLEN - 1);
130 strnz__cat(tmp_str, pick->in_spec, MAXLEN - 1);
131 ui_perror(tmp_str);
132 return (1);
133 }
134 if (sb.st_size == 0) {
135 strnz__cpy(tmp_str, _("Pick input file empty: "), MAXLEN - 1);
136 strnz__cat(tmp_str, pick->in_spec, MAXLEN - 1);
137 ui_perror(tmp_str);
138 return (1);
139 }
140 if ((pick->in_fp = fopen(pick->in_spec, "rb")) == nullptr) {
141 strnz__cpy(tmp_str, _("Can't open pick input file: "), MAXLEN - 1);
142 strnz__cat(tmp_str, pick->in_spec, MAXLEN - 1);
143 ui_perror(tmp_str);
144 return (1);
145 }
146 }
147 /*------------------------------------------------------------*/
148 if (pick->in_fp == nullptr) {
149 ui_perror(_("No pick input available"));
150 return (1);
151 }
152 /*------------------------------------------------------------*/
154 if (pick->f_in_pipe && pid > 0) {
155 waitpid(pid, nullptr, 0);
156 // restore_program_tioctl();
157 // sig_prog_mode();
158 }
159 close(pipe_fd[P_READ]);
160 ui_log(INFO, "pick->m_cnt = %d", pick->m_cnt);
161 stdio_fdnames(stdio_names_str, "pick_engine.c 160");
162 if (pick->m_cnt == 0) {
163 ui_perror(_("No pick objects available"));
164 return (1);
165 }
166 // Open Pick Window so we can build chyron
167 if (open_pick_win(init)) {
168 ui_perror(_("Failed to open pick window"));
169 exit(EXIT_FAILURE);
170 }
171 init->view = nullptr;
172
173 pick_engine(init);
175 if (pick->p_view_files) {
176 if (init->view) {
178 init->view = nullptr;
179 }
180#ifdef NOTCURSES_UI
181 if (ui_mm.ncv != nullptr) {
182 ncvisual_destroy(ui_mm.ncv);
183 ui_mm.ncv = nullptr;
184 }
185 if (ui_mm.sfc != nullptr) {
186 ui_surface_destroy(ui_mm.sfc);
187 ui_mm.sfc = nullptr;
188 }
189#endif
191 }
192 return 0;
193}
194
195/** @brief Destroys pick view, unmaps file buffer, and cleans up resources
196 * @ingroup pick_engine
197 @param init Pointer to Init structure containing pick information
198 @details If pick->p_view_files is true and view->buf is not nullptr, destroys
199 line table, unmaps the file buffer, and sets view->buf to nullptr. Destroys
200 view window and view structure to free associated resources.
201 */
202void destroy_pick_view(Init *init) {
203 if (!init->view)
204 return;
205 View *view = init->view;
206 Pick *pick = init->pick;
208 if (pick->p_view_files) {
209 if (view->buf != nullptr) {
211 munmap(view->buf, view->file_size);
212 view->buf = nullptr;
213 }
214 }
215 destroy_view(init);
216}
217/** @brief Reads pick input from file pointer and saves objects into pick
218 structure
219 * @ingroup pick_engine
220 @param init Pointer to Init structure containing pick information
221 @return 0 on success, -1 if no objects were read
222 @details Reads lines from pick->in_fp and saves them as objects in the pick
223 structure using save_object function. If no objects are read, returns -1.
224 Otherwise, sets obj_cnt to the number of objects read and resets obj_idx to 0
225 before returning 0. */
226int read_pick_input(Init *init) {
227 int i;
228
229 Pick *pick = init->pick;
230 pick->select_cnt = 0;
231 pick->tbl_pages = 1;
232
233 if (pick->in_fp) {
234 while (fgets(pick->in_buf, sizeof(pick->in_buf), pick->in_fp) != nullptr)
235 save_object(pick, pick->in_buf);
236
237 } else
238 for (i = 1; i < pick->argc; i++)
239 save_object(pick, pick->argv[i]);
240 if (pick->in_fp != nullptr)
241 fclose(pick->in_fp);
242 if (!pick->m_idx)
243 return (-1);
244 pick->m_cnt = pick->m_idx;
245 return 0;
246}
247int open_pick_win(Init *init) {
248 uint maxy, maxx;
249 uint whitespace_ratio = 15;
250 uint usable_lines;
251 uint pick_ratio = 50;
252 uint tbl_max_cols, pg_max_objs;
253
254 Pick *pick = init->pick;
255 ui_get_screen_size(&maxy, &maxx);
256 // Screen Geometry
257 // Calculate pick window size and position based on terminal size and pick
258 // parameters
259 //
260 // Calculate line usage:
261 if (pick->begy == 0)
262 pick->begy = (maxy * whitespace_ratio) / 200;
263 usable_lines = maxy - (maxy * whitespace_ratio) / 100;
264 usable_lines -= pick->begy;
265 usable_lines -= 5; // Pick overhead lines
266 if (pick->p_view_files) {
267 if (pick->lines == 0) {
268 pick->lines = usable_lines * pick_ratio / 100;
269 usable_lines -= pick->lines;
270 }
271 init->begy = pick->begy + 5 + pick->lines;
272 init->begx = 0;
273 usable_lines -= 3; // View overhead lines
274 init->lines = usable_lines;
275 init->cols = maxx - 2;
276 } else if (pick->lines == 0)
277 pick->lines = usable_lines;
278
279 pick->tbl_col_width = max(pick->tbl_col_width, 4);
280 pick->tbl_col_width = min(pick->tbl_col_width, (maxx - (2 + pick->begx)));
281 pick->m_idx = 0; // master index
282 pick->d_idx = 0; // display index
283 while (pick->m_idx < pick->m_cnt)
284 pick->d_object[pick->d_idx++] = pick->m_object[pick->m_idx++];
285 pick->d_cnt = pick->d_idx;
286 if (pick->d_cnt <= pick->lines) {
287 pick->tbl_lines = pick->d_cnt;
288 pick->lines = pick->d_cnt;
289 pick->tbl_cols = 1;
290 } else {
291 tbl_max_cols = ((maxx - (2 + pick->begx)) / (pick->tbl_col_width + 1));
292 pg_max_objs = pick->lines * tbl_max_cols;
293 if (pick->d_cnt > pg_max_objs)
294 pick->tbl_cols = tbl_max_cols;
295 else
296 pick->tbl_cols = pick->d_cnt / pick->lines;
297 pick->tbl_lines = pick->d_cnt / tbl_max_cols;
298 }
299 pick->tbl_pages = (pick->tbl_lines / (pick->lines - 1)) + 1;
300 // pick->lines = (pick->tbl_lines + pick->tbl_pages - 1) / pick->tbl_pages;
301 pick->tbl_page = 0;
302 // if (pick->begy == 0)
303 // pick->begy = (LINES - pick->lines) / 5;
304 // else if (pick->begy + pick->lines > LINES - 4)
305 // pick->begy = LINES - pick->lines - 2;
306 pick->width = (pick->tbl_col_width + 1) * pick->tbl_cols;
307
308 pick->width = max(pick->width, 60);
309 char tmp_str[MAXLEN];
310
311 int ui_split_win_lines = 2;
312 if (ui_tracked_sfc_split_box(pick->lines, pick->width, ui_split_win_lines, 0, pick->begy, pick->begx, pick->title)) {
313 ssnprintf(tmp_str, MAXLEN - 1, "ui_tracked_sfc_split_box(%d, %d, %d, %d, %d, %d, %s) failed",
314 pick->lines, pick->width, ui_split_win_lines, 0, pick->begy, pick->begx, pick->title);
315 ui_perror(tmp_str);
316 return (1);
317 }
319 UiSurface *sfc = pick->surface;
320 ui_setscrreg(sfc, WIN, 0, pick->lines - 1);
321 ui_scrollok(sfc, WIN, true);
322 ui_keypad(sfc, WIN, true);
323 pick->separator_line = pick->lines + 1;
324
325 pick->x = 1;
326
327 pick->chyron = ui_new_chyron(pick->surface, WIN2);
329 ui_set_chyron_key(pick->chyron, 2, _("F9 Cancel"),
331 ui_set_chyron_key(pick->chyron, 3, _("F10 Accept"),
333 ui_set_chyron_key(pick->chyron, 4, _("F11 View"),
335 ui_set_chyron_key(pick->chyron, 5, _("<q> Quit View"),
336 'q');
337 ui_set_chyron_key(pick->chyron, 6, _("<Sp> Process"), ' ');
338 ui_set_chyron_key(pick->chyron, 7, _("<Sp> Edit"), ' ');
339 ui_set_chyron_key(pick->chyron, 9, _("<Tab> Search"),
340 '\t');
341 ui_set_chyron_key(pick->chyron, 10, _("<Tab> Select"),
342 '\t');
350 return 0;
351}
352
353int pick_engine(Init *init) {
354 int rc = 0;
355 bool f_processed = false;
356 Pick *pick = init->pick;
357 /** Enter picker loop to handle user input and
358 * interactions */
359 char field[MAXLEN]; /**< Buffer for user input in the field */
360 field[0] = '\0';
362 do {
363 rc = picker(init, field);
364 if (rc == UIKEY_F09)
365 break;
366 if (rc == -1)
367 break;
368 else {
369 if (pick->select_cnt > 0) {
370 if (pick->f_out_spec && pick->out_spec[0]) {
372 f_processed = true;
373 }
374 if (pick->f_cmd && pick->cmd[0]) {
375 exec_objects(init);
376 f_processed = true;
377 }
378 if (pick->f_read_theme) {
379 read_theme(init);
380 f_processed = true;
381 }
382 if (f_processed) {
383 ui_mvwaddstr(pick->surface, WIN2, 0, 0, _("Selection Processed"));
385 }
386 }
387 }
389 } while (1);
391 return (rc);
392}
393/** @brief Sets standard chyron key states based on pick structure
394 * @ingroup pick_engine
395 @param pick Pointer to Pick structure containing chyron and selection
396 information
397 @details Updates the active state of chyron keys based on the current state
398 of the pick structure. Enables or disables keys for help, cancel, accept,
399 view, quit view, process, toggle, search, select, page up, page down, and
400 insert based on selection count, view mode, and table pages.
401 */
402void pick_std_chyron(Pick *pick) {
403 // * 1 F1 Help UIKEY_F01);
404 // * 2 F9 Cancel UIKEY_F09);
405 // * 3 F10 Accept UIKEY_F10);
406 // ? 4 <v> View <v>
407 // ? 5 <q> Quit View <q>
408 // ? 6 <Sp> Toggle <Sp>
409 // ? 7 <Sp> Edit <Sp>
410 // ? 9 <Tab> Search <Tab>
411 // ? 10 <Tab> Select" <Tab>
412 // ? 11 PgUp UIKEY_PPAGE
413 // ? 12 PgDn UIKEY_NPAGE
414 // ? 13 INS UIKEY_IC
415 pick->chyron->key[1]->active = true; // F1 Help
416 pick->chyron->key[2]->active = true; // F9 Cancel
417 pick->chyron->key[3]->active = pick->select_max != 1 ? true : false; // F10 Accept
418 pick->chyron->key[4]->active = pick->p_view_files; // <v> View
419 pick->chyron->key[5]->active = false; // <q> Quit View
420 pick->chyron->key[6]->active = pick->select_max == 1 ? false : true; // <Sp> Toggle
421 pick->chyron->key[7]->active = pick->select_max == 1 ? true : false; // <Sp> Process
422 pick->chyron->key[9]->active = true; // <Tab> Search;
423 pick->chyron->key[10]->active = false; // <Tab> Select;
424 pick->chyron->key[11]->active = pick->tbl_page > 0 ? true : false; // PgUp
425 pick->chyron->key[12]->active = pick->tbl_page < pick->tbl_pages - 1 ? true : false; // PgDn
426 pick->chyron->key[13]->active = false; // INS
427}
428/** @brief Saves a string as an object in the pick structure
429 * @ingroup pick_engine
430 @param pick Pointer to Pick structure
431 @param s String to save as an object
432 @details If the current object index is less than the maximum allowed, saves
433 the string as an object in the pick structure. Updates the column width if
434 necessary and marks the object as not selected. Increments the object index
435 for the next object to be saved. */
436void save_object(Pick *pick, char *s) {
437 uint l;
438
439 if (pick->m_idx < OBJ_MAXCNT - 1) {
440 l = strlen(s);
441 if (l > OBJ_MAXLEN - 1)
442 s[OBJ_MAXLEN - 1] = '\0';
443 pick->tbl_col_width = max(pick->tbl_col_width, l);
444 l = max(l, 1);
445 pick->m_object[pick->m_idx] = (char *)calloc(l + 1, sizeof(char));
447 pick->f_selected[pick->m_idx] = false;
448 pick->m_idx++;
449 }
450}
451
452/** @brief Displays current page of objects in pick window
453 * @ingroup pick_engine
454 @param pick Pointer to Pick structure containing objects and display
455 information
456 @details Clears the pick window and displays the current page of objects
457 based on the current table page, line, and column. Marks selected objects with
458 an asterisk. Updates the chyron with page information at the bottom of the pick
459 window. */
460void display_pick_page(Pick *pick) {
461 UiSurface *sfc = pick->surface;
462 uint col;
463 ui_bkgdset(sfc, WIN, &cell_nt);
465 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols;
466 for (col = 0; col < pick->tbl_cols; col++) {
467 pick->x = col * (pick->tbl_col_width + 1) + 1;
468 pick->y = 0;
469 while (pick->d_idx < pick->d_cnt && pick->y < pick->lines) {
470 if (pick->f_selected[pick->d_idx])
471 ui_mvwaddstr(sfc, WIN, pick->y, pick->x - 1, "*");
472 ui_mvwaddstr_fill(sfc, 1, pick->y++, pick->x,
473 pick->d_object[pick->d_idx++], pick->tbl_col_width - 1);
475 }
476 }
477 pick->d_idx -= 1;
478 pick->tbl_lines = pick->d_cnt;
479 pick->tbl_pages = ((pick->tbl_lines + pick->lines - 1) / pick->lines);
480 if (pick->y < pick->lines) {
481 pick->y_offset = pick->lines - pick->y;
482 ui_wscrl(sfc, WIN, -pick->y_offset);
483 } else
484 pick->y_offset = 0;
485}
486/** @brief Displays current page of objects in pick window
487 @ingroup pick_engine
488 @param pick Pointer to Pick structure containing objects and display
489 information
490 @param s String to filter objects by
491 @details Clears the pick window and displays the current page of objects
492 based on the current table page, line, and column. Marks selected objects
493 with an asterisk. Updates the chyron with page information at the bottom of
494 the pick window. */
495int match_objects(Pick *pick, char *s) {
496 /** pick->m_idx Master (as read from input) */
497 /** pick->d_idx Display (to display) */
498 pick->m_idx = 0;
499 pick->d_idx = 0;
500 while (pick->m_idx < pick->m_cnt) {
501 if (s == nullptr || s[0] == '\0' || strstr(pick->m_object[pick->m_idx], s) != nullptr) {
502 pick->d_object[pick->d_idx++] = pick->m_object[pick->m_idx];
503 }
504 pick->m_idx++;
505 }
506 pick->d_cnt = pick->d_idx;
507 return pick->d_cnt;
508}
509/** @brief Reverses the display of the currently selected object in pick window
510 * @ingroup pick_engine
511 @param pick Pointer to Pick structure containing object and display
512 information
513 @details Calculates the x coordinate for the currently selected object based
514 on the current table column and column width. Moves the cursor to the object's
515 position in the pick window, turns on reverse video attribute, and displays
516 the object's text. Turns off reverse video attribute and refreshes the pick
517 window to show the updated display. Moves the cursor back to the position
518 before the object text for potential further interactions. */
519void reverse_object(Pick *pick) {
520 UiSurface *sfc = pick->surface;
521 if (pick->d_idx >= pick->d_cnt)
522 pick->d_idx = pick->d_cnt - 1;
523 pick->x = pick->tbl_col * (pick->tbl_col_width + 1) + 1;
524 pick->tbl_line = (pick->d_idx / pick->tbl_cols) % pick->lines;
525 pick->y = pick->tbl_line + pick->y_offset;
526 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->tbl_line;
528 ui_mvwaddstr_fill(sfc, WIN, pick->y, pick->x, pick->d_object[pick->d_idx],
529 pick->tbl_col_width - 1);
530 if (pick->f_selected[pick->d_idx])
531 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_chk, 1);
532 else
533 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_sp, 1);
534 ui_bkgdset(sfc, WIN, &cell_nt);
535}
536/** @brief Unreverses the display of the currently selected object in pick
537 window
538 @ingroup pick_engine
539 @param pick Pointer to Pick structure containing object and display
540 information
541 @details Calculates the x coordinate for the currently selected object based
542 on the current table column and column width. Moves the cursor to the
543 object's position in the pick window and displays the object's text without
544 reverse video attribute. Refreshes the pick window to show the updated
545 display. Moves the cursor back to the position before the object text for
546 potential further interactions. */
547void unreverse_object(Pick *pick) {
548 UiSurface *sfc = pick->surface;
549 if (pick->d_idx >= pick->d_cnt)
550 pick->d_idx = pick->d_cnt - 1;
551 pick->x = pick->tbl_col * (pick->tbl_col_width + 1) + 1;
552 pick->tbl_line = (pick->d_idx / pick->tbl_cols) % pick->lines;
553 pick->y = pick->tbl_line + pick->y_offset;
554 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->tbl_line;
555 ui_bkgdset(sfc, WIN, &cell_nt);
556 ui_mvwaddstr_fill(sfc, WIN, pick->y, pick->x, pick->d_object[pick->d_idx],
557 pick->tbl_col_width - 1);
558 if (pick->f_selected[pick->d_idx])
559 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_chk, 1);
560 else
561 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_sp, 1);
562 ui_cursor_move(sfc, WIN, pick->y, 0);
563}
564void remove_right_angle(Pick *pick) {
565 UiSurface *sfc = pick->surface;
566 if (pick->d_idx >= pick->d_cnt)
567 pick->d_idx = pick->d_cnt - 1;
568 pick->tbl_line = (pick->d_idx / pick->tbl_cols) % pick->lines;
569 pick->y = pick->tbl_line + pick->y_offset;
570 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->tbl_line;
571 if (pick->f_selected[pick->d_idx])
572 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_chk, 1);
573 else
574 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_sp, 1);
575 ui_cursor_move(sfc, WIN, pick->y, 0);
576}
577/** @brief Toggles the selection state of the currently selected object in pick
578 window
579 @ingroup pick_engine
580 @param pick Pointer to Pick structure containing object and selection
581 information
582 @details Calculates the x coordinate for the currently selected object based
583 on the current table column and column width. If the object is currently
584 selected, it is deselected by updating the selection count, marking it as not
585 selected, and displaying a space before the object text. If the object is not
586 currently selected, it is selected by updating the selection count, marking
587 it as selected, and displaying an asterisk before the object text. Refreshes
588 the pick window to show the updated display. Moves the cursor back to the
589 position before the object text for potential further interactions. */
590void toggle_object(Pick *pick) {
591 UiSurface *sfc = pick->surface;
592 pick->x = pick->tbl_col * (pick->tbl_col_width + 1) + 1;
593 if (pick->f_selected[pick->d_idx]) {
594 pick->select_cnt--;
595 pick->f_selected[pick->d_idx] = false;
596 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_sp, 1);
597 } else {
598 pick->select_cnt++;
599 pick->f_selected[pick->d_idx] = true;
600 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_chk, 1);
601 }
602}
603/** @brief Deselects the currently selected object in pick window
604 @ingroup pick_engine
605 @details like toggle, but only deselects object */
606void deselect_object(Pick *pick) {
607 UiSurface *sfc = pick->surface;
608 pick->x = pick->tbl_col * (pick->tbl_col_width + 1) + 1;
609 if (pick->f_selected[pick->d_idx]) {
610 pick->select_cnt--;
611 pick->f_selected[pick->d_idx] = false;
612 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_sp, 1);
613 }
614}
615int read_theme(Init *init) {
616 int rc;
619 if (rc)
620 return rc;
621 SIO *sio = init->sio;
624 return 0;
625}
626
627/** @brief Outputs selected objects to specified output file
628 @ingroup pick_engine
629 @param pick Pointer to Pick structure containing selected objects and
630 output file information
631 @return 0 on success, 1 on failure
632 @details If output file cannot be opened, an error message is printed and
633 the function returns 1. Otherwise, selected objects are written to the
634 output file, one per line, and the file is closed before returning 0.
635*/
636int output_objects(Pick *pick) {
637 char tmp_str[MAXLEN];
638 int m;
639 if ((pick->out_fp = fopen(pick->out_spec, "w")) == nullptr) {
640 m = MAXLEN - 30;
641 strnz__cpy(tmp_str, _("Can't open pick output file: "), m);
642 m -= strlen(pick->in_spec);
643 strnz__cat(tmp_str, pick->out_spec, m);
644 }
645 for (pick->d_idx = 0; pick->d_idx < pick->d_cnt; pick->d_idx++) {
646 if (pick->f_selected[pick->d_idx])
647 fprintf(stdout, "%s\n", pick->d_object[pick->d_idx]);
648 }
649 fflush(stdout);
650 if (pick->out_fp != nullptr)
651 fclose(pick->out_fp);
652 return (0);
653}
654/** @brief Executes specified command with selected objects as arguments
655 @ingroup pick_engine
656 @param init Pointer to Init structure
657 @return 0 on success, 1 on failure
658 @details Parses command string and appends selected objects as arguments to
659 the command. If command contains "%%", it is replaced with a space- separated
660 list of selected objects. Executes the command using execvp in a child
661 process and waits for it to finish. If the command is a pager or editor, it
662 is executed within the pick interface using popup_view instead of execvp.
663 If f_append_objects is true, the argument containing %% is replaced with
664 the concatenated selected objects. If f_append_objects is false, selected
665 objects are added as separate arguments and the original command arguments
666 remain unchanged.
667 eargv should be null-terminated to indicate the end of arguments for
668 execvp
669 Memory allocated for arguments is freed after execution to prevent
670 memory leaks.
671 If execvp fails, an error message is printed and the child process
672 exits with failure status
673 The parent process waits for the child process to finish before
674 proceeding and restores terminal settings
675 If the command is a pager or editor, it is executed within the pick
676 interface using popup_view instead of execvp
677 The base name of the command is extracted to check if it is a pager or
678 editor
679 If the command is a pager or editor, the pick interface is used to
680 display the command output instead of executing it in a separate terminal
681 This allows the user to view the command output without leaving the pick
682 interface and provides a more seamless user experience.
683 If the command is not a pager or editor, it is executed in a separate
684 terminal and the pick interface is restored after execution
685 If the command to be executed is view, an external command is not
686 needed, instead the popup_view function can be used to display the output
687 within the pick interface */
688int exec_objects(Init *init) {
689 int rc = -1;
690 uint eargc;
691 char *eargv[MAXARGS];
692 char tmp_str[MAXLEN] = {'\0'};
693 char title[MAXLEN];
694 char sav_arg[MAXLEN];
695 char *out_s;
696 int eargx = 0;
697 uint i = 0;
698 pid_t pid = 0;
699 bool f_append_objects = false;
700
701 Pick *pick = init->pick;
702 title[0] = '\0';
703 if (pick->cmd[0] == '\0')
704 return -1;
705 if (pick->cmd[0] == '\\' || pick->cmd[0] == '\"') {
706 size_t len = strlen(pick->cmd);
707 if (len > 1 && pick->cmd[len - 1] == '\"') {
708 memmove(pick->cmd, pick->cmd + 1, len - 2);
709 pick->cmd[len - 2] = '\0';
710 }
711 }
712 eargc = str_to_args(eargv, pick->cmd, MAXARGS - 1);
713 tmp_str[0] = '\0';
714 if (pick->f_multiple_cmd_args) {
715 for (i = 0; i < pick->d_cnt; i++) {
716 if (pick->f_selected[i] && eargc < MAXARGS) {
717 if (tmp_str[0] != '\0')
718 strnz__cat(tmp_str, " ", MAXLEN - 1);
719 strnz__cat(tmp_str, pick->d_object[i], MAXLEN - 1);
720 }
721 }
722 eargv[eargc++] = strdup(tmp_str);
723 } else {
724 f_append_objects = false;
725 i = 0;
726 while (i < eargc) {
727 /** This is the line that gets the selected objects */
728 if (strstr(eargv[i], "%%") != nullptr) {
729 tmp_str[0] = '\0';
730 f_append_objects = true;
731 strnz__cpy(sav_arg, eargv[i], MAXLEN - 1);
732 eargx = i;
733 break;
734 }
735 i++;
736 }
737 for (i = 0; i < pick->d_cnt; i++) {
738 /** append arguments onto tmp_str */
739 if (pick->f_selected[i] && eargc < MAXARGS - 1) {
740 if (f_append_objects == true) {
741 if (tmp_str[0] != '\0')
742 strnz__cat(tmp_str, " ", MAXLEN - 1);
743 strnz__cat(tmp_str, pick->d_object[i], MAXLEN - 1);
744 continue;
745 }
746 eargv[eargc++] = strdup(pick->d_object[i]);
747 }
748 }
749 if (f_append_objects == true) {
750 if (eargv[eargx] != nullptr) {
751 free(eargv[eargx]);
752 eargv[eargx] = nullptr;
753 }
754 out_s = rep_substring(sav_arg, "%%", tmp_str);
755 if (out_s == nullptr || out_s[0] == '\0') {
756 i = 0;
757 while (i < eargc) {
758 if (eargv[i] != nullptr)
759 free(eargv[i]);
760 i++;
761 }
762 ui_perror(_("rep_substring() failed in exec_objects"));
763 return 1;
764 }
765 strnz__cpy(title, out_s, MAXLEN - 1);
766 eargv[eargx] = strdup(out_s);
767 if (out_s != nullptr) {
768 free(out_s);
769 out_s = nullptr;
770 }
771 }
772 }
773 strnz__cpy(tmp_str, eargv[0], MAXLEN - 1);
774 eargv[eargc] = nullptr;
775 char *sav_ptr;
776 char *tok;
777 tok = strtok_r(tmp_str, " ", &sav_ptr);
778 strnz__cpy(sav_arg, tok, MAXLEN - 1);
779 base_name(tmp_str, sav_arg);
780 if (tmp_str[0] != '\0' && (strcmp(tmp_str, "view") == 0 || strcmp(tmp_str, "view") == 0)) {
781 /** initialize popup_view arguments and execute popup_view to display
782 command output within pick interface */
783 init->lines = 60;
784 init->cols = 80;
785 init->begy = pick->begy + 1;
786 init->begx = pick->begx + 1;
787 if (title[0] != '\0')
788 strnz__cpy(init->title, title, MAXLEN - 1);
789 else
790 strnz__cpy(init->title, eargv[eargc], MAXLEN - 1);
791 popup_view(init, eargc, eargv, init->lines, init->cols, init->begy,
792 init->begx);
793 i = 0;
794 while (i < eargc) {
795 if (eargv[i] != nullptr)
796 free(eargv[i]);
797 i++;
798 }
799 return 0;
800 } else {
803 if ((pid = fork()) == -1) {
804 /** fork failed, free eargv and return error */
805 i = 0;
806 while (i < eargc) {
807 if (eargv[i] != nullptr)
808 free(eargv[i]);
809 i++;
810 }
811 ui_perror(_("fork() failed in exec_objects"));
812 return (1);
813 } else if (pid == 0) {
814 /** Prevent child process from writing to terminal */
815 // int dev_null = open("/dev/null", O_WRONLY);
816 // if (dev_null == -1) {
817 // ui_perror(_("open(/dev/null) failed in init_pick child
818 // process"));
819 // exit(EXIT_FAILURE);
820 // }
821 // dup2(dev_null, STDERR_FILENO);
822 // close(dev_null);
823 execvp(eargv[0], eargv);
824 exit(EXIT_FAILURE);
825 }
826 }
827 waitpid(pid, nullptr, 0);
828 destroy_argv(eargc, eargv);
829 // sig_prog_mode();
831 return rc;
832}
833/** @brief Displays the help screen for the pick interface using view
834 @ingroup pick_engine
835 @param init Pointer to Init structure containing pick information
836 @details Initializes the help_spec field in the Pick structure with the
837 path to the pick help file. Then, constructs the argument list for
838 executing popup_view with the help file as an argument. Finally, calls
839 popup_view function to display the help screen within the pick interface. */
840void display_pick_help(Init *init) {
841 int eargc;
842 char *eargv[MAXARGS];
843 char tmp_str[MAXLEN];
844 Pick *pick = init->pick;
845 if (pick->f_help_spec && pick->help_spec[0] != '\0')
846 strnz__cpy(tmp_str, pick->help_spec, MAXLEN - 1);
847 else {
848 strnz__cpy(tmp_str, init->mapp_help, MAXLEN - 1);
849 strnz__cat(tmp_str, "/", MAXLEN - 1);
851 }
852 eargc = 0;
853 eargv[eargc++] = strdup("view");
854 eargv[eargc++] = strdup("-Nf");
855 eargv[eargc++] = strdup(tmp_str);
856 eargv[eargc] = nullptr;
857 init->lines = 30;
858 init->cols = 76;
859 init->begy = pick->begy + 1;
860 init->begx = pick->begx + 1;
861 strnz__cpy(init->title, _("Pick Help"), MAXLEN - 1);
862 popup_view(init, eargc, eargv, init->lines, init->cols, init->begy,
863 init->begx);
864 destroy_argv(eargc, eargv);
865 return;
866}
867/** @brief Main loop for handling user input and interactions in the pick
868 interface
869 @ingroup pick_engine
870 @param init Pointer to Init structure containing pick information
871 @param field Buffer for user input in the field
872 @return Count of selected objects on success, -1 if user cancels
873 @details The first loop handles navigation through the pick table.
874 The second loop handles user input for selecting/deselecting objects,
875 accepting the selection, or canceling the selection. Depending on the key
876 pressed, the appropriate action is taken, such as toggling selection, moving
877 to the next/previous object, or displaying the help screen. If the user
878 accepts the selection, the count of selected objects is returned. If the user
879 cancels the selection, -1 is returned.
880 */
881int picker(Init *init, char *field) {
882 bool f_insert = false; /* Flag to indicate if insert mode is active */
883 Pick *pick = init->pick;
884 uint col = 0;
885 uint flen = pick->width - 4;
886 char *accept_s = field; /* pointer to start of field buffer */
887 char *ptr = field; /* pointer to current cursor position in field buffer */
888 char *s = field; /* source pointer for editing operations */
889 char *d = field; /* destination pointer for editing operations */
890 char *fend = field + flen;
891 char *str_end = field + strlen(field); /* End of field content */
892 uint pos = 0;
893 uint prev_pos = 0;
894 char prev_field[MAXLEN];
895 char *prev_ptr = prev_field;
896 char view_file[MAXLEN] = {'\0'};
897 pick = init->pick;
898 UiSurface *sfc = pick->surface;
899 UiEvent event;
900 uint maxy, maxx;
901 ptr = accept_s;
902 ptr = str_end;
903 char tmp_str[MAXLEN];
904
905#ifdef UAL_UI
906 ui_mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION);
907#else
908 ui_mice_enable(0);
909#endif
910 f_insert = false;
911
912 ui_keypad(sfc, WIN, true);
913
914 int in_key = 0;
915 while (1) {
916 while (1) {
917 /** ===========================================================
918 Pick Objects Loop
919 =========================================================== */
920 if (in_key == 0) {
922 pick->tbl_line = (pick->d_idx / pick->tbl_cols) % pick->lines;
923 pick->y = pick->tbl_line + pick->y_offset;
924
925 ssnprintf(tmp_str, MAXLEN - 1, _("Line %d, Page %d/%d"),
926 pick->tbl_line + 1, pick->tbl_page + 1,
927 pick->tbl_pages);
929 if (pick->p_view_files)
930 if (strcmp(pick->d_object[pick->d_idx], view_file) != 0) {
931 strnz__cpy(view_file, pick->d_object[pick->d_idx], MAXLEN - 1);
932 new_view_file(init, view_file);
933 }
936 ui_display_chyron(sfc, WIN2, pick->chyron, 1, pick->chyron->l);
937 ui_mvwadd_wchnstr(sfc, WIN2, 0, 0, &cell_ran, 1);
939 ui_top_surface(sfc, WIN);
940 ui_cursor_enable_yx(sfc, WIN, pick->y, pick->x, true);
942 in_key = ui_get_event(sfc, WIN, pick->chyron, &event, -1);
943 ui_cursor_enable_yx(sfc, WIN, pick->y, pick->x, false);
944 if (event.mouse_action != UI_MOUSE_NONE) {
945 ui_getmaxyx(sfc, WIN2, &maxy, &maxx);
946 if (event.in_win == pick->chyron->w &&
947 event.y == pick->chyron->y)
948 in_key = ui_get_chyron_key(pick->chyron, event.x);
949 } else {
950 if (pick->f_selected[pick->d_idx])
951 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0,
952 &cell_chk, 1);
953 else
954 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0,
955 &cell_sp, 1);
956 }
957 }
958 switch (in_key) {
959 case UIKEY_F01:
962 f_insert = false;
963 ui_mvwadd_wchnstr(sfc, WIN2, 0, 0, &cell_ran, 1);
964 in_key = 0;
965 continue;
966
967 case UIKEY_F11:
968 if (!pick->p_view_files) {
969 in_key = 0;
970 continue;
971 }
972 pick->chyron->key[1]->active = true; // F1 Help
973 pick->chyron->key[2]->active = true; // F9 Cancel
974 pick->chyron->key[4]->active = false; // F11 View
975 pick->chyron->key[5]->active = true; // <q> Quit View
976 pick->chyron->key[6]->active = false; // <Sp> Toggle
977 pick->chyron->key[7]->active = false; // <Sp> Edit
978 pick->chyron->key[9]->active = false; // <Tab> Search;
979 pick->chyron->key[10]->active = false; // <Tab> Select;
980 pick->chyron->key[11]->active = true; // PgUp
981 pick->chyron->key[12]->active = true; // PgDn
982 pick->chyron->key[13]->active = false; // INS
985 ui_display_chyron(sfc, WIN2, pick->chyron, 1, pick->chyron->l);
987 if (pick->p_view_files)
991 ui_display_chyron(sfc, WIN2, pick->chyron, 1, pick->chyron->l);
992 in_key = 0;
993 continue;
994
995 case 't':
996 case ' ':
998 toggle_object(pick);
999 if (pick->select_max > 0 && pick->select_cnt == pick->select_max)
1000 return pick->select_cnt;
1001 in_key = 0;
1002 continue;
1003
1004 /** 'q', or UIKEY_F09 cancel selection and exit picker */
1005 case 'q':
1006 case UIKEY_F09:
1008 return -1;
1009
1010 /** Enter or UIKEY_F10 Accepts current selection and exits
1011 picker, returning count of selected objects */
1012 case UIKEY_F10:
1013 case '\n':
1014 case UIKEY_ENTER:
1015 reverse_object(pick);
1016 return pick->select_cnt;
1017
1018 /** UIKEY_END Moves selection to last object in list */
1019 case UIKEY_END:
1020 ui_mvwaddstr_fill(sfc, WIN, pick->y, pick->x,
1021 pick->d_object[pick->d_idx],
1022 pick->tbl_col_width - 1);
1023 uint display_tbl_page = pick->tbl_page;
1024 pick->d_idx = pick->d_cnt - 1;
1025 pick->tbl_page = pick->d_idx / (pick->lines * pick->tbl_cols);
1026 pick->tbl_line = (pick->d_idx / pick->tbl_cols) % pick->lines;
1027 pick->tbl_col = pick->d_idx % pick->tbl_cols;
1028 pick->y = pick->tbl_line;
1029 if (display_tbl_page != pick->tbl_page)
1031 in_key = 0;
1032 continue;
1033 case '\t':
1035 // ui_wnoutrefresh(sfc, WIN);
1036 in_key = 0;
1037 break;
1038
1039 /** 'h' or UIKEY_LEFT or Backspace Moves selection to previous
1040 object in list */
1041 case 'h':
1042 case UIKEY_LEFT:
1043 case UIKEY_BACKSPACE:
1044 if (pick->tbl_col == 0) {
1045 in_key = 0;
1046 continue;
1047 }
1049 ui_mvwaddstr_fill(sfc, WIN, pick->y, pick->x,
1050 pick->d_object[pick->d_idx],
1051 pick->tbl_col_width - 1);
1052 if (pick->tbl_col > 0)
1053 pick->tbl_col--;
1054 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->tbl_line;
1055 in_key = 0;
1056 reverse_object(pick);
1057 continue;
1058
1059 /** 'j' or UIKEY_DOWN Moves selection to next object in list */
1060 case 'j':
1061 case UIKEY_DOWN:
1062 if (pick->tbl_line == pick->tbl_lines - 1)
1063 break;
1064 ui_mvwaddstr_fill(sfc, WIN, pick->y, pick->x,
1065 pick->d_object[pick->d_idx],
1066 pick->tbl_col_width - 1);
1068 if (pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->tbl_line < pick->d_cnt - 1 && pick->tbl_line < pick->lines - 1)
1069 pick->tbl_line++;
1070 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->tbl_line;
1071 in_key = 0;
1072 reverse_object(pick);
1073 continue;
1074
1075 /** 'k' or UIKEY_UP Moves selection to previous object in list */
1076 case 'k':
1077 case UIKEY_UP:
1078 ui_mvwaddstr_fill(sfc, WIN, pick->y, pick->x,
1079 pick->d_object[pick->d_idx],
1080 pick->tbl_col_width - 1);
1082 if (pick->tbl_line > 0)
1083 pick->tbl_line--;
1084 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->tbl_line;
1085 in_key = 0;
1086 reverse_object(pick);
1087 continue;
1088
1089 /** 'l' or UIKEY_RIGHT Moves selection to next object in list */
1090 case 'l':
1091 case UIKEY_RIGHT:
1092 if (pick->tbl_col == pick->tbl_cols - 1) {
1093 in_key = 0;
1094 continue;
1095 }
1096 ui_mvwaddstr_fill(sfc, WIN, pick->y, pick->x,
1097 pick->d_object[pick->d_idx],
1098 pick->tbl_col_width - 1);
1100 /** pick->obj_idx += pick->tbl_lines -> next column */
1101 if (pick->tbl_page * pick->lines * pick->tbl_cols + (pick->tbl_col + 1) * pick->lines + pick->tbl_line < pick->d_cnt - 1 && pick->tbl_col < pick->tbl_cols - 1)
1102 pick->tbl_col++;
1103 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->tbl_line;
1104 in_key = 0;
1105 reverse_object(pick);
1106 continue;
1107
1108 /** UIKEY_NPAGE or 'Ctrl+f' Moves selection to next page of
1109 objects */
1110 case UIKEY_NPAGE:
1111 case '\06':
1112 if (pick->tbl_pages == 1) {
1113 in_key = 0;
1114 continue;
1115 }
1116 if (pick->tbl_page < pick->tbl_pages - 1) {
1117 pick->tbl_page++;
1118 pick->pg_line = 0;
1119 pick->tbl_col = 0;
1120 }
1121 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_cols * pick->pg_line + pick->tbl_col;
1123 in_key = 0;
1124 continue;
1125
1126 /** UIKEY_PPAGE or 'Ctrl+b' Moves selection to previous page of
1127 objects */
1128 case UIKEY_PPAGE:
1129 case '\02':
1130 if (pick->tbl_pages == 1) {
1131 in_key = 0;
1132 continue;
1133 }
1134 if (pick->tbl_page > 0)
1135 pick->tbl_page--;
1136 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_cols * pick->pg_line + pick->tbl_col;
1138 in_key = 0;
1139 continue;
1140
1141 /** UIKEY_HOME Moves selection to first object in list */
1142 case UIKEY_HOME:
1143 pick->tbl_page = 0;
1144 pick->tbl_line = 0;
1145 pick->tbl_col = 0;
1146 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_cols * pick->pg_line + pick->tbl_col;
1148 in_key = 0;
1149 continue;
1150
1151 /** UIKEY_LL (lower left of numeric pad) Moves selection to last
1152 object in list */
1153 // case UIKEY_END:
1154 // pick->tbl_page = pick->tbl_pages - 1;
1155 // pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols +
1156 // // pick->tbl_cols * pick->pg_line +
1157 // // pick->tbl_col;
1158 // display_pick_page(pick);
1159 // in_key = 0;
1160 // continue;
1161
1162 /** UIKEY_MOUSE Handles mouse events for selection and chyron
1163 * key activation */
1164
1165 case UIKEY_BUTTON1:
1166 if (event.y < pick->y_offset) {
1167 in_key = 0;
1168 continue;
1169 }
1171 pick->y = event.y;
1172 pick->tbl_col = (event.x - 1) / (pick->tbl_col_width + 1);
1173 if (pick->tbl_col >= pick->tbl_cols)
1174 continue;
1175 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->y;
1176 in_key = UIKEY_F12; /** toggle selection on mouse click */
1177 event.y = event.x = -1;
1178 continue;
1179
1180 default:
1181 in_key = 0;
1182 continue;
1183 }
1184 in_key = 0;
1185 break;
1186 }
1187 /** ===============================================================
1188 Line editor loop
1189 =============================================================== */
1190 pick->chyron->key[1]->active = true; // F1 Help
1191 pick->chyron->key[2]->active = true; // F9 Cancel
1192 pick->chyron->key[3]->active = false; // F10 Accept
1193 pick->chyron->key[4]->active = true; // F11 View
1194 pick->chyron->key[5]->active = false; // <q> Quit View
1195 pick->chyron->key[6]->active = false; // <Sp> Toggle
1196 pick->chyron->key[7]->active = false; // <Sp> Edit
1197 pick->chyron->key[9]->active = false; // <Tab> Search
1198 pick->chyron->key[10]->active = true; // <Tab> Select
1199 pick->chyron->key[11]->active = false; // PgDn
1200 pick->chyron->key[12]->active = false; // PgUp
1201 pick->chyron->key[13]->active = true; // INS
1202
1203 while (1) {
1204
1205 if (in_key == 0) {
1206 // mouse_win = nullptr;
1207 if (accept_s != nullptr && accept_s[0] != '\0') {
1208 if (match_objects(pick, accept_s) == 0) {
1209 strnz__cpy(field, prev_field, MAXLEN - 1);
1210 pos = prev_pos;
1211 ptr = prev_ptr;
1212 } else {
1214 ssnprintf(tmp_str, MAXLEN - 1, _("Line %d, Page %d/%d"),
1215 pick->tbl_line + 1, pick->tbl_page + 1,
1216 pick->tbl_pages);
1217 strnz__cat(tmp_str, " ", MAXLEN - 1);
1218 tmp_str[21] = '\0';
1219 ui_mvwaddstr(sfc, BOX, pick->separator_line, 3, tmp_str);
1220 }
1221 }
1223 ui_display_chyron(sfc, WIN2, pick->chyron, 1, pick->chyron->l);
1224 ui_cursor_move(sfc, WIN2, 0, 1);
1225 /** display_field_content */
1226 rtrim(accept_s);
1227 col = 1;
1228 ui_mvwaddstr(sfc, WIN2, 0, col, accept_s);
1229 ui_wclrtoeol(sfc, WIN2);
1230 if (pick->p_view_files)
1231 if (strcmp(pick->d_object[pick->d_idx], view_file) != 0) {
1232 strnz__cpy(view_file, pick->d_object[pick->d_idx], MAXLEN - 1);
1233 new_view_file(init, view_file);
1234 }
1235 // mouse_win = nullptr;
1236 pos = col + strlen(accept_s);
1237 ui_mvwadd_wchnstr(sfc, WIN2, 0, 0, &cell_ran, 1);
1238 ui_top_surface(sfc, WIN2);
1239 ui_cursor_enable_yx(sfc, WIN2, 0, pos, true);
1241 in_key = ui_get_event(sfc, WIN2, pick->chyron, &event, -1);
1242 ui_cursor_enable_yx(sfc, WIN2, 0, pos, false);
1243 ui_getmaxyx(sfc, WIN2, &maxy, &maxx);
1244 if (event.mouse_action != UI_MOUSE_NONE) {
1245 if (event.in_win == WIN2 && event.y == maxy - 1)
1246 in_key = ui_get_chyron_key(pick->chyron, event.x);
1247 if (event.in_win == WIN)
1248 break;
1249 }
1250 if (in_key == UIKEY_F12) {
1251 in_key = 0;
1252 continue;
1253 }
1254 }
1255 strnz__cpy(prev_field, accept_s, MAXLEN - 1);
1256 prev_pos = pos;
1257 prev_ptr = ptr;
1258 switch (in_key) {
1259 case '\n':
1260 case UIKEY_ENTER:
1261 in_key = 0;
1262 break;
1263
1264 case UIKEY_UP:
1265 case '\t':
1266 in_key = 0;
1267 break;
1268
1269 case UIKEY_F01:
1270 return (in_key);
1271
1272 case UIKEY_F02:
1273 if (pick->p_view_files)
1275 in_key = 0;
1276 continue;
1277
1278 /** UIKEY_F09 Cancels the current operation */
1279 case UIKEY_F09:
1280 in_key = UIKEY_F09;
1281 return (in_key);
1282
1283 /** UIKEY_F10 is the default key for accepting the field */
1284 case UIKEY_F10:
1285 return (in_key);
1286 case UIKEY_F11:
1287 if (!pick->p_view_files) {
1288 in_key = 0;
1289 continue;
1290 }
1291 pick->chyron->key[1]->active = true; // F1 Help
1292 pick->chyron->key[2]->active = true; // F9 Cancel
1293 pick->chyron->key[4]->active = false; // F11 View
1294 pick->chyron->key[5]->active = true; // <q> Quit View
1295 pick->chyron->key[6]->active = false; // <Sp> Toggle
1296 pick->chyron->key[7]->active = false; // <Sp> Edit
1297 pick->chyron->key[9]->active = false; // <Tab> Search;
1298 pick->chyron->key[10]->active = false; // <Tab> Select;
1299 pick->chyron->key[11]->active = true; // PgUp
1300 pick->chyron->key[12]->active = true; // PgDn
1301 pick->chyron->key[13]->active = false; // INS
1304 ui_display_chyron(sfc, WIN2, pick->chyron, 1, pick->chyron->l);
1306 if (pick->p_view_files)
1310 ui_display_chyron(sfc, WIN2, pick->chyron, 1, pick->chyron->l);
1311 in_key = 0;
1312 continue;
1313
1314 case UIKEY_END:
1315 case Ctrl('e'):
1316 while (*ptr != '\0')
1317 ptr++;
1318 pos = col + (ptr - accept_s);
1319 in_key = 0;
1320 continue;
1321
1322 case UIKEY_IC:
1323 if (f_insert) {
1324 f_insert = false;
1327 } else {
1328 f_insert = TRUE;
1331 }
1333 ui_display_chyron(sfc, WIN2, pick->chyron, 1, pick->chyron->l);
1334 in_key = 0;
1335 continue;
1336
1337 /** UIKEY_DC deletes character at cursor */
1338 case UIKEY_DC:
1339 s = ptr + 1;
1340 d = ptr;
1341 while (*s != '\0')
1342 *d++ = *s++;
1343 *d = '\0';
1344 str_end = d;
1345 f_insert = false;
1346 in_key = 0;
1347 continue;
1348
1349 /** UIKEY_HOME moves cursor to start of field */
1350 case UIKEY_HOME:
1351 case Ctrl('a'):
1352 ptr = accept_s;
1353 pos = col;
1354 in_key = 0;
1355 continue;
1356
1357 /** UIKEY_BACKSPACE deletes character before cursor */
1358 case UIKEY_BACKSPACE:
1359 if (ptr > accept_s) {
1360 ptr--;
1361 pos--;
1362 } else {
1363 in_key = 0;
1364 continue;
1365 }
1366 s = ptr + 1;
1367 d = ptr;
1368 while (*s != '\0')
1369 *d++ = *s++;
1370 *d = '\0';
1371 str_end = d;
1372 if (ptr == accept_s) {
1373 match_objects(pick, accept_s);
1375 ssnprintf(tmp_str, MAXLEN - 1, _("Line %d, Page %d/%d"),
1376 pick->tbl_line + 1, pick->tbl_page + 1,
1377 pick->tbl_pages);
1378 strnz__cat(tmp_str, " ", MAXLEN - 1);
1379 tmp_str[21] = '\0';
1380 ui_mvwaddstr(sfc, BOX, pick->separator_line, 3, tmp_str);
1381 }
1382 in_key = 0;
1383 continue;
1384
1385 /** UIKEY_LEFT moves cursor left one character */
1386 case UIKEY_LEFT:
1387 if (ptr > accept_s) {
1388 ptr--;
1389 pos--;
1390 }
1391 in_key = 0;
1392 continue;
1393
1394 /** UIKEY_RIGHT moves cursor right one character */
1395 case UIKEY_RIGHT:
1396 if (ptr < fend && ptr <= str_end) {
1397 ptr++;
1398 pos++;
1399 }
1400 in_key = 0;
1401 continue;
1402
1403 /** Handles mouse events for field editing */
1404 case UIKEY_BUTTON1:
1405 if (event.x < col || event.x >= col + flen) {
1406 in_key = 0;
1407 continue;
1408 }
1409 pos = event.x;
1410 fend = accept_s + flen;
1411 str_end = accept_s + strlen(accept_s);
1412 ptr = accept_s + (pos - col);
1413 ptr = min(ptr, str_end);
1414 pos = col + (ptr - accept_s);
1415 event.x = -1;
1416 in_key = 0;
1417 continue;
1418
1419 default:
1420 if (in_key < ' ' || in_key > '~') {
1421 in_key = 0;
1422 continue;
1423 }
1424 if (ptr >= fend) {
1425 in_key = 0;
1426 continue;
1427 }
1428 if (f_insert) {
1429 if (str_end < fend) {
1430 s = str_end - 1;
1431 d = str_end;
1432 while (s >= ptr)
1433 *d-- = *s--;
1434 *ptr++ = in_key;
1435 str_end++;
1436 pos++;
1437 }
1438 } else {
1439 if (ptr < fend) {
1440 if (ptr < str_end) {
1441 *ptr++ = in_key;
1442 pos++;
1443 } else if (ptr == str_end) {
1444 *ptr++ = in_key;
1445 *ptr = '\0';
1446 str_end = ptr;
1447 pos++;
1448 }
1449 }
1450 }
1451 in_key = 0;
1452 continue;
1453 }
1454 break;
1455 }
1457 }
1458}
1459/** @brief Initializes a new view for displaying file contents in the pick
1460 interface
1461 @ingroup pick_engine
1462 @param init Pointer to Init structure containing pick information
1463 @return 0 on success, 1 on failure
1464 @details Allocates memory for a new View structure and initializes its
1465 fields based on the parameters specified in the Init structure. Sets up the
1466 help_spec field for the view, and calls init_view_boxwin to create the view's
1467 window. Returns 0 on success, or 1 if window creation fails.
1468 */
1469int new_pick_view(Init *init) {
1470 char *e;
1471 // if (init->view != nullptr)
1472 // view_stack_push(&view_stack, *init->view);
1473 init->view = nullptr;
1475 View *view = init->view;
1476 view = new_view(init); // View struct allocation
1477 view->lines = init->lines;
1478 view->cols = init->cols;
1479 view->begy = init->begy;
1480 view->begx = init->begx;
1481 view->receiver_cmd[0] = '\0';
1484 view->f_squeeze = init->f_squeeze;
1485 view->tab_stop = init->tab_stop;
1486 view->f_ln = init->f_ln;
1487 view->h_shift = init->h_shift;
1488 e = getenv("VIEW_HELP_FILE");
1489 if (e && e[0] != '\0') {
1491 }
1492 view->f_help_spec =
1494 "~/menuapp/help", R_OK);
1495 if (!view->f_help_spec) {
1497 strnz__cat(view->help_spec, "/help/", MAXLEN - 1);
1499 }
1500 int rc = init_view_boxwin(init);
1501 return rc;
1502}
1503/** @brief Initializes a new view for displaying the contents of a specified
1504 file in the pick interface
1505 @ingroup pick_engine
1506 @param init Pointer to Init structure containing pick information
1507 @param file Name of the file to be displayed in the view
1508 @details If a view is already initialized, it destroys the existing line
1509 table and unmaps the buffer. Then, it sets up the provider command for
1510 highlighting the specified file, initializes the view input, and if successful,
1511 resets various view parameters, initializes the line table, and displays the
1512 first page of the file contents along with the prompt.
1513 */
1514void new_view_file(Init *init, char *file) {
1515 View *view = init->view;
1516 Pick *pick = init->pick;
1517 if (pick->p_view_files && init->view != nullptr) {
1519 munmap(view->buf, view->file_size);
1520 view->buf = nullptr;
1521 }
1522#ifdef NOTCURSES_UI
1523 if (ui_mm.ncv != nullptr) {
1524 ncvisual_destroy(ui_mm.ncv);
1525 ui_mm.ncv = nullptr;
1526 ui_surface_destroy(ui_mm.sfc);
1527 ui_mm.sfc = nullptr;
1528 ui_render();
1529 }
1530#endif
1531 FileType ft = file_type(file);
1532 switch (ft) {
1533 case FT_IMAGE:
1534#ifdef NOTCURSES_UI
1535 if (init->view != nullptr) {
1536 destroy_pick_view(init);
1537 init->view = nullptr;
1538 destroy_line_table(view);
1539 munmap(view->buf, view->file_size);
1540 view->buf = nullptr;
1541 }
1542 ui_display_image(ui->nc, &ui_mm, file, -1, -1, 35, 0);
1543 if (ui_mm.sfc == nullptr) {
1544 ui_log(ERROR, _("ui_display_image() failed in new_view_file"));
1545 return;
1546 }
1547 if (ui_mm.ncv == nullptr) {
1548 ui_log(ERROR, _("ui_display_image() failed in new_view_file"));
1549 return;
1550 }
1551#endif
1552 break;
1553 case FT_VIDEO:
1554#ifdef NOTCURSES_UI
1555 if (init->view != nullptr) {
1556 destroy_pick_view(init);
1557 init->view = nullptr;
1558 destroy_line_table(view);
1559 munmap(view->buf, view->file_size);
1560 view->buf = nullptr;
1561 }
1562 ui_display_image(ui->nc, &ui_mm, file, -1, -1, 35, 0);
1563 if (ui_mm.sfc == nullptr) {
1564 ui_log(ERROR, _("ui_display_image() failed in new_view_file"));
1565 return;
1566 }
1567 if (ui_mm.ncv == nullptr) {
1568 ui_log(ERROR, _("ui_display_image() failed in new_view_file"));
1569 return;
1570 }
1571#endif
1572 break;
1573 case FT_AUDIO:
1574 break;
1575 case FT_TEXT:
1576 if (!pick->p_view_files)
1577 return;
1578 if (init->view == nullptr) {
1579 new_pick_view(init);
1580 view = init->view;
1581 } else {
1582 view = init->view;
1584 munmap(view->buf, view->file_size);
1585 view->buf = nullptr;
1586 }
1587 strnz__cpy(view->provider_cmd, _("tree-sitter highlight "), MAXLEN - 1);
1589 strnz__cpy(view->title, file, MAXLEN - 1);
1590 if (view_init_input(init, file) == 0) {
1591 if (view->buf) {
1592 view->f_eod = 0;
1593 view->f_bod = 0;
1594 view->maxcol = 0;
1595 view->page_top_pos = 0;
1596 view->page_top_ln_no = 0;
1597 view->page_bot_ln_no = 0;
1598 view->ln_pos_max = 0;
1599 view->ln_no = 0;
1600 view->page_bot_pos = 0;
1601 view->file_pos = 0;
1604 page_next(view);
1605 build_prompt(view);
1607 pad_refresh(view);
1608 }
1609 }
1610 break;
1611 default:
1612 break;
1613 }
1614}
int open_pick_win(Init *)
#define P_READ
Definition common.h:53
#define PICK_HELP_FILE
Definition common.h:37
int popup_view(Init *, int, char **, uint, uint, uint, uint)
instantiate a view popup window
Definition popups.c:145
int pick_engine(Init *)
#define VIEW_HELP_FILE
Definition common.h:38
#define P_WRITE
Definition common.h:54
#define OBJ_MAXLEN
Definition pick.h:20
#define OBJ_MAXCNT
Definition pick.h:21
size_t rtrim(char *)
Trims trailing spaces from string s in place.
Definition futil.c:307
char stdio_names_str[4096]
Definition futil.c:121
#define MAXARGS
Definition cm.h:67
char * stdio_fdnames(char *, char *)
Definition futil.c:1130
#define Ctrl(c)
Definition cm.h:70
char * rep_substring(const char *, const char *, const char *) __attribute__((nonnull(1
Replace all occurrences of "tgt_s" in "org_s" with "rep_s".
Definition futil.c:1471
void ui_render()
Render the UI by updating panels and refreshing the display.
Definition ui_ncurses.c:931
int ui_setscrreg(UiSurface *s, ss_t w, uint top, uint bottom)
Set the scrolling region for a UiSurface.
Definition ui_ncurses.c:861
void ui_getmaxyx(UiSurface *s, ss_t w, uint *lines, uint *cols)
Get the maximum dimensions of a UiSurface.
Definition ui_ncurses.c:722
int ui_cursor_enable_yx(UiSurface *s, ss_t w, uint y, uint x, bool visible)
Enable or disable the cursor at a specific position within a UiSurface.
Definition ui_ncurses.c:896
int ui_wscrl(UiSurface *s, ss_t w, int rows)
Scroll the contents of a UiSurface by a specified number of lines.
Definition ui_ncurses.c:770
int ui_cursor_move(UiSurface *s, ss_t w, uint y, uint x)
Move the cursor to a specified position within a UiSurface.
Definition ui_ncurses.c:698
void ui_surface_destroy(UiSurface *s)
Destroy a UiSurface, cleaning up its windows and panels.
Definition ui_ncurses.c:499
void ui_restore_wins()
Restore the state of all windows in the UI. This function refreshes the standard screen and all surfa...
void ui_get_screen_size(uint *lines, uint *cols)
Get the current screen size (number of lines and columns).
Definition ui_ncurses.c:754
int ui_mousemask(int mask)
Enable or disable mouse support.
UiSurface * stdsfc
Definition ui_ncurses.c:46
int sfc_ptr
Definition ui_ncurses.c:42
int ui_top_surface(UiSurface *s, ss_t w)
Hide a UiSurface, making it invisible on the screen.
Definition ui_ncurses.c:655
void ui_endwin()
End the UI application, cleaning up resources and shutting down the UI runtime.
Definition ui_ncurses.c:443
int ui_scrollok(UiSurface *s, ss_t w, bool enable)
Enable or disable scrolling for a UiSurface.
Definition ui_ncurses.c:796
int ui_wclrtoeol(UiSurface *s, ss_t w)
Clear to the end of the line in a surface window.
int ui_bkgdset(UiSurface *s, ss_t w, const UiCell *cell)
Set the background for new content to be written to a specific window within a UiSurface.
Definition ui_ncurses.c:988
int ui_werase(UiSurface *s, ss_t w)
Erase the contents of a UiSurface or all surfaces.
Definition ui_ncurses.c:582
int ui_keypad(UiSurface *s, ss_t w, bool enable)
Enable or disable the keypad for a UiSurface.
Definition ui_ncurses.c:812
#define UIKEY_F02
#define UIKEY_DC
#define UIKEY_BACKSPACE
#define UIKEY_F12
#define UIKEY_LEFT
#define UIKEY_F09
#define UIKEY_IC
#define UIKEY_PPAGE
#define UIKEY_END
#define UIKEY_F01
#define UIKEY_BUTTON1
#define UIKEY_RIGHT
#define UIKEY_UP
#define UIKEY_F10
#define UIKEY_HOME
#define UIKEY_ENTER
#define UIKEY_F11
#define UIKEY_DOWN
#define UIKEY_NPAGE
int ui_get_event(UiSurface *s, ss_t w, UiChyron *chyron, UiEvent *ev, int timeout_ms)
Read input events.
UiCell cell_sp
Definition ui_common.c:149
void ui_set_chyron_key(UiChyron *chyron, uint k, char *s, uint kc)
Set chyron key with default color pair (cp_nt_rev).
Definition ui_common.c:778
UiCell cell_nt
Definition ui_common.c:123
int ui_tracked_sfc_split_box(uint wlines, uint wcols, uint split_y, uint split_x, uint wbegy, uint wbegx, const char *wtitle)
Create a new surface with a split box window.
Definition ui_common.c:467
UiCell cell_nt_hl_rev
Definition ui_common.c:126
UiChyron * ui_new_chyron(UiSurface *sfc, ss_t w)
Create new chyron structure.
Definition ui_common.c:662
int ui_cm_surface_destroy(UiSurface *sfc)
Destroy the most recently created surface.
Definition ui_common.c:515
void ui_display_chyron(UiSurface *sfc, ss_t w, UiChyron *chyron, uint line, uint col)
Display chyron on the specified line and column of the surface.
Definition ui_common.c:898
void ui_set_chyron_key_cb(UiChyron *chyron, uint k, char *s, uint kc, UiCell cell_base)
Set chyron key with color pair (cp).
Definition ui_common.c:754
int ui_border_ysplit_text(UiSurface *sfc, char *text_in, uint separator_line)
Draw a box with a separator line and text around the specified window.
Definition ui_common.c:579
void ui_abend(int ec, char *s)
Convert multibyte string to complex character array.
Definition ui_common.c:404
void ui_initialize_sio(SIO *sio)
Definition ui_common.c:211
int ui_border_title(UiSurface *sfc, ss_t w, const char *title)
Draw a box with a title around the specified window.
Definition ui_common.c:621
UiChyron * ui_destroy_chyron(UiChyron *chyron)
Destroy UiChyron structure.
Definition ui_common.c:717
int ui_get_chyron_key(UiChyron *chyron, uint x)
Get keycode from chyron.
Definition ui_common.c:922
UiCell cell_ran
Definition ui_common.c:132
void ui_compile_chyron(UiChyron *chyron)
construct the chyron string from the chyron structure
Definition ui_common.c:843
UiCell cell_chk
Definition ui_common.c:133
UiCell cell_nt_rev
Definition ui_common.c:124
UiSurface * ui_surface[UI_SFC_MAX]
Definition ui_ncurses.c:40
int ui_mvwadd_wchnstr(UiSurface *s, ss_t w, uint y, uint x, const UiCell *cmplx_buf, uint n)
Draw a complex character string at a specific position in a surface window, with a maximum length.
int ui_mvwaddstr(UiSurface *s, ss_t w, uint y, uint x, const char *text)
Draw a text string at a specific position in a surface window.
int ui_mvwaddstr_fill(UiSurface *s, ss_t w, uint y, uint x, const char *str, int m)
Draw a text string at a specific position in a surface window, filling the remaining space with space...
#define TRUE
Definition iloan.c:31
void end_pick_view(Init *)
int tbl_line
Definition pick_engine.c:23
int obj_idx
Definition pick_engine.c:24
char const pagers_editors[12][10]
Definition pick_engine.c:50
int tbl_cols
Definition pick_engine.c:23
int read_theme(Init *)
int tbl_col
Definition pick_engine.c:23
int tbl_pages
Definition pick_engine.c:23
int calculated_idx
Definition pick_engine.c:24
int pg_lines
Definition pick_engine.c:23
UiMultiMedia ui_mm
Definition pick_engine.c:48
int tbl_page
Definition pick_engine.c:23
void remove_right_angle(Pick *)
int pipe_fd[2]
Definition pick_engine.c:46
#define min(x, y)
Definition lf.h:158
#define MAXLEN
Definition lf.h:38
#define max(a, b)
Definition lf.h:152
int process_config_file(char *, Init *)
Definition init.c:690
#define _(String)
Definition amort.c:23
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
Definition lf.c:2299
size_t ssnprintf(char *, size_t, const char *,...)
Custom safe string formatting utility (Variadic version).
Definition futil.c:398
int str_to_args(char **, char *, uint)
Converts a string into an array of argument strings.
Definition futil.c:418
bool expand_tilde(char *, uint)
Expand a tilde (~) in a file path to the user's home directory.
Definition lf.c:2089
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
Definition lf.c:2330
int destroy_argv(uint argc, char **argv)
Deallocates memory allocated for argument strings in argv.
Definition futil.c:474
bool base_name(char *, char *)
Returns the base name of a file specification.
Definition futil.c:1154
int init_view_boxwin(Init *init)
Initialize the C-Menu View in box window mode.
Definition init_view.c:145
int view_init_input(Init *init, char *file_name)
Initialize the input for the C-Menu View.
Definition init_view.c:331
bool verify_spec_arg(char *, char *, char *, char *, uint)
Verify file specification argument.
Definition mem.c:361
Pick * new_pick(Init *init, int argc, char **argv, uint begy, uint begx)
Create and initialize Pick structure.
Definition mem.c:178
View * destroy_view(Init *init)
Destroy View structure.
Definition mem.c:337
View * new_view(Init *init)
Create and initialize View structure.
Definition mem.c:291
void save_object(Pick *, char *)
Saves a string as an object in the pick structure.
void toggle_object(Pick *)
Toggles the selection state of the currently selected object in pick window.
int picker(Init *, char *field)
Main loop for handling user input and interactions in the pick interface.
int new_pick_view(Init *)
Initializes a new view for displaying file contents in the pick interface.
void unreverse_object(Pick *)
Unreverses the display of the currently selected object in pick window.
void destroy_pick_view(Init *)
Destroys pick view, unmaps file buffer, and cleans up resources.
void pick_std_chyron(Pick *)
Sets standard chyron key states based on pick structure.
int output_objects(Pick *)
Outputs selected objects to specified output file.
int match_objects(Pick *pick, char *s)
Displays current page of objects in pick window.
void deselect_object(Pick *)
Deselects the currently selected object in pick window.
int init_pick(Init *, int, char **, uint, uint)
Initializes pick structure and opens pick input file or pipe.
Definition pick_engine.c:68
int read_pick_input(Init *)
Reads pick input from file pointer and saves objects into pick structure.
void reverse_object(Pick *)
Reverses the display of the currently selected object in pick window.
void display_pick_page(Pick *)
Displays current page of objects in pick window.
void new_view_file(Init *, char *)
Initializes a new view for displaying the contents of a specified file in the pick interface.
void display_pick_help(Init *)
Displays the help screen for the pick interface using view.
int exec_objects(Init *)
Executes specified command with selected objects as arguments.
int view_cmd_processor(Init *)
Main Command Processing Loop for View.
void build_prompt(View *)
Build Prompt String.
void initialize_line_table(View *)
Initialize Line Table.
void destroy_line_table(View *)
Destroy Line Table.
void page_next(View *)
Advance to Next Page.
int pad_refresh(View *)
Refresh Pad and Line Number Window.
int display_prompt(View *, char *)
Display Command Line Prompt.
int ui_perror(char *emsg_str)
Display a simple error message window or print to stderr.
Definition ui_common.c:1323
char title[MAXLEN]
Definition common.h:132
char mapp_help[MAXLEN]
Definition common.h:152
int begx
Definition common.h:121
SIO * sio
Definition common.h:117
int argc
Definition common.h:133
int cols
Definition common.h:119
int tab_stop
Definition common.h:185
char mapp_home[MAXLEN]
Definition common.h:150
bool f_squeeze
Definition common.h:140
int begy
Definition common.h:120
int h_shift
Definition common.h:186
bool f_ln
Definition common.h:146
View * view
Definition common.h:193
bool f_at_end_remove
Definition common.h:138
bool f_ignore_case
Definition common.h:136
char ** argv
Definition common.h:134
int lines
Definition common.h:118
char mapp_theme[MAXLEN]
Definition common.h:155
Pick * pick
Definition common.h:191
char provider_cmd[MAXLEN]
Definition view.h:74
off_t page_top_ln_no
Definition view.h:158
char * buf
Definition view.h:173
uint maxcol
Definition view.h:126
off_t page_top_pos
Definition view.h:153
off_t file_pos
Definition view.h:151
uint lines
Definition view.h:70
off_t ln_no
Definition view.h:184
char prompt_str[MAXLEN]
Definition view.h:78
uint begx
Definition view.h:73
bool f_bod
Definition view.h:99
char help_spec[MAXLEN]
Definition view.h:143
off_t ln_pos_max
Definition view.h:189
bool f_ignore_case
Definition view.h:83
bool f_help_spec
Definition view.h:146
char receiver_cmd[MAXLEN]
Definition view.h:75
bool f_ln
Definition view.h:183
bool f_eod
Definition view.h:100
bool f_at_end_remove
Definition view.h:84
off_t file_size
Definition view.h:150
bool f_squeeze
Definition view.h:85
int tab_stop
Definition view.h:95
char title[MAXLEN]
Definition view.h:79
uint cols
Definition view.h:71
off_t page_bot_pos
Definition view.h:154
off_t page_bot_ln_no
Definition view.h:159
uint begy
Definition view.h:72
int h_shift
Definition view.h:96
UiSurface * sfc
Definition view.h:89
char ** m_object
Definition pick.h:71
UiChyron * chyron
Definition pick.h:94
uint separator_line
Definition pick.h:92
uint tbl_line
Definition pick.h:87
bool f_cmd
Definition pick.h:69
uint y
Definition pick.h:33
uint select_max
Definition pick.h:74
bool p_view_files
Definition pick.h:64
uint m_idx
Definition pick.h:77
uint tbl_cols
Definition pick.h:89
uint tbl_page
Definition pick.h:86
char ** d_object
Definition pick.h:79
char cmd[MAXLEN]
Definition pick.h:54
bool f_help_spec
Definition pick.h:61
FILE * in_fp
Definition pick.h:44
bool f_out_spec
Definition pick.h:58
int argc
Definition pick.h:42
bool f_multiple_cmd_args
Definition pick.h:63
uint d_cnt
Definition pick.h:76
bool f_in_pipe
Definition pick.h:59
bool f_selected[OBJ_MAXCNT]
Definition pick.h:65
uint m_cnt
Definition pick.h:75
char title[MAXLEN]
Definition pick.h:41
char help_spec[MAXLEN]
Definition pick.h:51
char in_buf[BUFSIZ]
Definition pick.h:70
uint tbl_pages
Definition pick.h:85
UiSurface * surface
Definition pick.h:40
char ** argv
Definition pick.h:43
uint tbl_col_width
Definition pick.h:91
bool f_read_theme
Definition pick.h:62
char in_spec[MAXLEN]
Definition pick.h:49
FILE * out_fp
Definition pick.h:45
uint lines
Definition pick.h:29
uint x
Definition pick.h:34
uint select_cnt
Definition pick.h:73
uint d_idx
Definition pick.h:78
uint tbl_lines
Definition pick.h:88
uint begy
Definition pick.h:31
uint tbl_col
Definition pick.h:90
uint y_offset
Definition pick.h:80
uint begx
Definition pick.h:32
uint pg_line
Definition pick.h:81
uint width
Definition pick.h:30
char provider_cmd[MAXLEN]
Definition pick.h:52
char out_spec[MAXLEN]
Definition pick.h:50
UiMouseAction mouse_action
Definition ui_backend.h:140
ss_t in_win
Definition ui_backend.h:138