2
3
4
5
6
7
8
11
12
28int picker(Init *,
char *field);
43 "vi",
"vim",
"nano",
"nvim",
44 "pico",
"emacs",
"edit",
""};
47
48
49
50
51
52
53
54
55
56
57
58
59
60int init_pick(Init *init,
int argc,
char **argv,
int begy,
int begx) {
74 Perror("pipe(pipe_fd) failed in init_pick");
77 if ((pid = fork()) == -1) {
78 Perror("fork() failed in init_pick");
83 int dev_null = open(
"/dev/null", O_WRONLY);
85 Perror("open(/dev/null) failed in init_pick child process");
88 dup2(dev_null, STDERR_FILENO);
97 execvp(s_argv[0], s_argv);
104
112 strcmp(pick
->in_spec,
"/dev/stdin") == 0) {
114 pick
->in_fp = fdopen(STDIN_FILENO,
"rb");
126 if (sb.st_size == 0) {
143 struct timeval timeout;
151 int in_fd = fileno(pick
->in_fp);
153 FD_SET(in_fd, &read_fds);
164 while (ready == 0 && remaining > 0 && in_key != KEY_F(9)) {
166 if (in_key == KEY_F(9))
169 FD_SET(in_fd, &read_fds);
179 if (in_key == KEY_F(9)) {
182
192 Perror("Error waiting for pick input");
195
203 Perror("Timeout waiting for pick input");
206
213 if (ready == 1 && !FD_ISSET(in_fd, &read_fds)) {
214 Perror("Unexpected error waiting for pick input");
217
234 keypad(pick
->win, true);
237 Perror("No pick objects available");
251
252
253
254
255
256
257
258
271 for (i = 1; i < pick
->argc; i++)
281
282
283
284
285
286
287
288
289
292 int maxy, maxx, win_maxy, win_maxx;
293 int tbl_max_cols, pg_max_objs;
295 getmaxyx(stdscr, maxy, maxx);
297
307 pg_max_objs = win_maxy * tbl_max_cols;
374
375
376
377
378
379
380
398
399
400
401
402
403
404
409 wclrtoeol(pick
->win);
433
434
435
436
437
438
439
440
447 if (s ==
nullptr || s[0] ==
'\0' ||
457
458
459
460
461
462
463
464
465
475 wattron(pick
->win, WA_REVERSE);
478 wattroff(pick
->win, WA_REVERSE);
482
483
484
485
486
487
488
489
490
491
506
507
508
509
510
511
512
513
514
515
516
517
531
532
542
543
544
545
546
547
548
549
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
606 char tmp_str[
MAXLEN] = {
'\0'};
613 bool f_append_objects = false;
620 if (len > 1 &&
pick->cmd[len - 1] ==
'\"') {
630 if (tmp_str[0] !=
'\0')
635 eargv[eargc++] = strdup(tmp_str);
637 f_append_objects = false;
641 if (strstr(eargv[i],
"%%") !=
nullptr) {
643 f_append_objects = true;
653 if (f_append_objects == true) {
654 if (tmp_str[0] !=
'\0')
662 if (f_append_objects == true) {
668 if (out_s ==
nullptr || out_s[0] ==
'\0') {
675 Perror("rep_substring() failed in exec_objects");
679 eargv[eargx] = strdup(out_s);
690 tok = strtok_r(tmp_str,
" ", &sp);
693 if (tmp_str[0] !=
'\0' &&
694 (strcmp(tmp_str,
"view") == 0 || strcmp(tmp_str,
"view") == 0)) {
696
701 if (title[0] !=
'\0')
715 if ((pid = fork()) == -1) {
723 Perror("fork() failed in exec_objects");
728 int dev_null = open(
"/dev/null", O_WRONLY);
729 if (dev_null == -1) {
730 Perror("open(/dev/null) failed in init_pick child process");
733 dup2(dev_null, STDERR_FILENO);
736 execvp(eargv[0], eargv);
738
755
756
757
758
759
760
761
762
763
783
784
785
786
787
788
801 eargv[eargc++] = strdup(
"view");
802 eargv[eargc++] = strdup(
"-Nf");
803 eargv[eargc++] = strdup(tmp_str);
816
817
818
819
820
821
822
823
824
825
826
827
828
830 bool f_insert = false;
853 fend = fstart + flen;
854 str_end = fstart + strlen(fstart);
861 mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED,
nullptr);
869 wchar_t wstr[2] = {
BW_RAN, L'\0'};
880
881
908 mvwaddstr(win2, line, col, filler_s);
909 mvwaddstr(win2, line, col, accept_s);
910 pos = col + strlen(accept_s);
913 wmove(win2, line, pos);
937 wchar_t wstr[2] = {
BW_RAN, L'\0'};
963
993
1066
1085
1112
1122
1151
1152
1159 if (accept_s !=
nullptr && accept_s[0] !=
'\0') {
1183 mvwaddstr(win2, line, col, filler_s);
1184 mvwaddstr(win2, line, col, accept_s);
1186 wmove(win2, line, pos);
1193 if (in_key == KEY_F(13)) {
1232 while (*ptr !=
'\0')
1234 pos = col + (ptr - fstart);
1288 if (ptr == fstart) {
1313 if (ptr < fend && ptr <= str_end) {
1328 fend = fstart + flen;
1329 str_end = fstart + strlen(fstart);
1330 ptr = fstart + (pos - col);
1331 ptr =
min(ptr, str_end);
1332 pos = col + (ptr - fstart);
1338 if (in_key <
' ' || in_key >
'~') {
1347 if (str_end < fend) {
1358 if (ptr < str_end) {
1361 }
else if (ptr == str_end) {
int popup_view(Init *, int, char **, int, int, int, int)
instantiate a view popup window
size_t rtrim(char *)
Trims trailing spaces from string s in place.
#define min(x, y)
min macro evaluates two expressions, returning least result
#define max(a, b)
max macro evaluates two expressions, returning greatest result.
char const pagers_editors[12][10]
WINDOW * win_win2[MAXWIN]
int dxwgetch(WINDOW *win, WINDOW *win2, Chyron *chyron, int n)
int box2_new(int, int, int, int, char *, bool)
Create a new window with optional box and title.
void restore_wins()
Restore all windows after a screen resize.
WINDOW * win_del()
Delete the current window and its associated box window.
void mvwaddstr_fill(WINDOW *, int, int, char *, int)
For lines shorter than their display area, fill the rest with spaces.
bool wait_destroy(Chyron *)
Destroy the waiting message window and chyron.
bool waitpid_with_timeout(pid_t pid, int timeout)
Wait for a process to finish with a timeout and optional user cancellation.
int wait_continue(WINDOW *, Chyron *, int)
Update the waiting message with remaining time and check for user input.
WINDOW * wait_mk_win(Chyron *, char *)
Display a popup waiting message.
int Perror(char *)
Display a simple error message window or print to stderr.
void abend(int, char *)
Abnormal program termination.
Chyron * wait_mk_chyron()
Create a Chyron struct for the waiting message.
void set_chyron_key(Chyron *, int, char *, int)
Set chyron key with default color pair (cp_nt_rev).
void display_chyron(WINDOW *win, Chyron *chyron, int line, int col)
Display chyron on window.
Chyron * destroy_chyron(Chyron *chyron)
Destroy Chyron structure.
void set_chyron_key_cp(Chyron *, int, char *, int, int)
Set chyron key with color pair (cp).
void compile_chyron(Chyron *)
construct the chyron string from the chyron structure
Chyron * new_chyron()
Create and initialize Chyron structure.
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
int destroy_argv(int argc, char **argv)
Deallocates memory allocated for argument strings in argv.
size_t strnz(char *, size_t)
terminates string at New Line, Carriage Return, or max_len
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
size_t strnz__cat(char *, const char *, size_t)
safer alternative to strncat
char * rep_substring(const char *, const char *, const char *)
Replace all occurrences of "tgt_s" in "org_s" with "rep_s".
bool base_name(char *, char *)
Returns the base name of a file specification.
int str_to_args(char **, char *, int)
Converts a string into an array of argument strings.
Pick * new_pick(Init *, int, char **, int, int)
Create and initialize Pick structure.
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 init_pick(Init *, int, char **, int, int)
Initializes pick structure and opens pick input file or pipe.
void unreverse_object(Pick *)
Unreverses the display of the currently selected object in pick window.
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 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.
int pick_engine(Init *)
Initializes pick interface, calculates window size and position, and enters picker loop.
void display_page(Pick *)
Displays current page of objects in pick window.
void display_pick_help(Init *)
Displays the help screen for the pick interface using view.
int open_pick_win(Init *)
Initializes the pick window based on the parameters specified in the Pick structure.
int exec_objects(Init *)
Executes specified command with selected objects as arguments.
bool restore_curses_tioctl()
restore_curses_tioctl() - restore curses terminal settings
void sig_prog_mode()
Set up signal handlers for interrupt signals.
bool f_selected[OBJ_MAXCNT]
char provider_cmd[MAXLEN]