|
C-Menu 0.2.9
A User Interface Toolkit
|
Navigate, Select, and Perform Action on Objects. More...
Functions | |
| void | deselect_object (Pick *pick) |
| Deselects the currently selected object in pick window. | |
| void | destroy_pick_view (Init *init) |
| Destroys pick view, unmaps file buffer, and cleans up resources. | |
| void | display_pick_help (Init *init) |
| Displays the help screen for the pick interface using view. | |
| void | display_pick_page (Pick *pick) |
| Displays current page of objects in pick window. | |
| int | exec_objects (Init *init) |
| Executes specified command with selected objects as arguments. | |
| int | init_pick (Init *init, int argc, char **argv, int by, int bx) |
| Initializes pick structure and opens pick input file or pipe. | |
| int | match_objects (Pick *pick, char *s) |
| Displays current page of objects in pick window. | |
| int | new_pick_view (Init *init) |
| Initializes a new view for displaying file contents in the pick interface. | |
| void | new_view_file (Init *init, char *file) |
| Initializes a new view for displaying the contents of a specified file in the pick interface. | |
| int | open_pick_win (Init *init) |
| Initializes the pick window based on the parameters specified in the Pick structure. | |
| int | output_objects (Pick *pick) |
| Outputs selected objects to specified output file. | |
| int | pick_engine (Init *init) |
| Initializes pick interface, calculates window size and position, and enters picker loop. | |
| void | pick_std_chyron (Pick *pick) |
| Sets standard chyron key states based on pick structure. | |
| int | picker (Init *init, char *field) |
| Main loop for handling user input and interactions in the pick interface. | |
| int | read_pick_input (Init *init) |
| Reads pick input from file pointer and saves objects into pick structure. | |
| void | reverse_object (Pick *pick) |
| Reverses the display of the currently selected object in pick window. | |
| void | save_object (Pick *pick, char *s) |
| Saves a string as an object in the pick structure. | |
| void | toggle_object (Pick *pick) |
| Toggles the selection state of the currently selected object in pick window. | |
| void | unreverse_object (Pick *pick) |
| Unreverses the display of the currently selected object in pick window. | |
Navigate, Select, and Perform Action on Objects.
| void deselect_object | ( | Pick * | pick | ) |
Deselects the currently selected object in pick window.
like toggle, but only deselects object
Definition at line 579 of file pick_engine.c.
References Pick::d_idx, Pick::f_selected, Pick::select_cnt, sp, Pick::tbl_col, Pick::tbl_col_width, Pick::win, Pick::x, and Pick::y.
Referenced by pick_engine(), and picker().
| void destroy_pick_view | ( | Init * | init | ) |
Destroys pick view, unmaps file buffer, and cleans up resources.
| init | Pointer to Init structure containing pick information |
If pick->p_view_files is true and view->buf is not nullptr, destroys line table, unmaps the file buffer, and sets view->buf to nullptr. Destroys view window and view structure to free associated resources.
Definition at line 206 of file pick_engine.c.
References View::buf, destroy_line_table(), destroy_view(), destroy_view_win(), View::file_size, Pick::p_view_files, Init::pick, stdio_fdnames(), stdio_names_str, and Init::view.
Referenced by init_pick().
| void display_pick_help | ( | Init * | init | ) |
Displays the help screen for the pick interface using view.
| init | Pointer to Init structure containing pick information |
Initializes the help_spec field in the Pick structure with the path to the pick help file. Then, constructs the argument list for executing popup_view with the help file as an argument. Finally, calls popup_view function to display the help screen within the pick interface.
Definition at line 844 of file pick_engine.c.
References Init::begx, Pick::begx, Init::begy, Pick::begy, Init::cols, destroy_argv(), Pick::f_help_spec, Pick::help_spec, Init::lines, Init::mapp_help, Init::pick, popup_view(), strnz__cat(), strnz__cpy(), and Init::title.
Referenced by picker().
| void display_pick_page | ( | Pick * | pick | ) |
Displays current page of objects in pick window.
| pick | Pointer to Pick structure containing objects and display information |
Clears the pick window and displays the current page of objects based on the current table page, line, and column. Marks selected objects with an asterisk. Updates the chyron with page information at the bottom of the pick window.
Definition at line 435 of file pick_engine.c.
References Pick::d_cnt, Pick::d_idx, Pick::d_object, Pick::f_selected, Pick::lines, mvwaddstr_fill(), Pick::tbl_col_width, Pick::tbl_cols, Pick::tbl_lines, Pick::tbl_page, Pick::tbl_pages, Pick::win, Pick::x, Pick::y, and Pick::y_offset.
Referenced by pick_engine(), and picker().
| int exec_objects | ( | Init * | init | ) |
Executes specified command with selected objects as arguments.
| init | Pointer to Init structure |
Parses command string and appends selected objects as arguments to the command. If command contains "%%", it is replaced with a space- separated list of selected objects. Executes the command using execvp in a child process and waits for it to finish. If the command is a pager or editor, it is executed within the pick interface using popup_view instead of execvp. If f_append_objects is true, the argument containing %% is replaced with the concatenated selected objects. If f_append_objects is false, selected objects are added as separate arguments and the original command arguments remain unchanged. eargv should be null-terminated to indicate the end of arguments for execvp Memory allocated for arguments is freed after execution to prevent memory leaks. If execvp fails, an error message is printed and the child process exits with failure status The parent process waits for the child process to finish before proceeding and restores terminal settings If the command is a pager or editor, it is executed within the pick interface using popup_view instead of execvp The base name of the command is extracted to check if it is a pager or editor If the command is a pager or editor, the pick interface is used to display the command output instead of executing it in a separate terminal This allows the user to view the command output without leaving the pick interface and provides a more seamless user experience. If the command is not a pager or editor, it is executed in a separate terminal and the pick interface is restored after execution If the command to be executed is view, an external command is not needed, instead the popup_view function can be used to display the output within the pick interface
This is the line that gets the selected objects
append arguments onto tmp_str
initialize popup_view arguments and execute popup_view to display command output within pick interface
fork failed, free eargv and return error
Prevent child process from writing to terminal
Definition at line 661 of file pick_engine.c.
References base_name(), Init::begx, Pick::begx, Init::begy, Pick::begy, Pick::cmd, Init::cols, Pick::d_cnt, Pick::d_object, destroy_argv(), Pick::f_multiple_cmd_args, Pick::f_selected, Init::lines, Perror(), Init::pick, popup_view(), rep_substring(), restore_wins(), str_to_args(), strnz__cat(), strnz__cpy(), and Init::title.
Referenced by pick_engine().
| int init_pick | ( | Init * | init, |
| int | argc, | ||
| char ** | argv, | ||
| int | by, | ||
| int | bx ) |
Initializes pick structure and opens pick input file or pipe.
| init | Pointer to Init structure |
| argc | Argument count |
| argv | Argument vector |
| by | Beginning y coordinate for pick window |
| bx | Beginning x coordinate for pick window |
If provider_cmd is specified, it takes precedence over in_spec and input file arguments. provider_cmd is executed and its output is read as pick input If provider_cmd is not specified, in_spec is used to read pick input from a file or stdin If provider_cmd is specified, it is executed and its output is read as pick input
Prevent child process from writing to terminal
Close read end of pipe as Child only needs to write to pipe
Connect CHILD STDOUT to write end of pipe
STDOUT attached to write end of pipe, so close pipe fd
Return to Parent Close write end of pipe as Parent only needs to read from pipe
Open a file pointer on read end of pipe
No provider_cmd specified, so read pick input from file or stdin
Enter pick_engine
Definition at line 66 of file pick_engine.c.
References abend(), Pick::chyron, compile_chyron(), Pick::d_cnt, Pick::d_idx, Pick::d_object, destroy_argv(), destroy_pick_view(), Pick::f_in_pipe, Pick::in_fp, Pick::in_spec, Pick::m_cnt, Pick::m_idx, Pick::m_object, new_chyron(), new_pick(), Pick::p_view_files, Perror(), Init::pick, pick_engine(), pick_std_chyron(), pipe_fd, Pick::provider_cmd, read_pick_input(), restore_curses_tioctl(), set_chyron_key(), sig_prog_mode(), str_to_args(), strnz__cat(), strnz__cpy(), Pick::win, and win_del().
Referenced by main(), and popup_pick().
| int match_objects | ( | Pick * | pick, |
| char * | s ) |
Displays current page of objects in pick window.
| pick | Pointer to Pick structure containing objects and display information |
| s | String to filter objects by |
Clears the pick window and displays the current page of objects based on the current table page, line, and column. Marks selected objects with an asterisk. Updates the chyron with page information at the bottom of the pick window.
pick->m_idx Master (as read from input)
pick->d_idx Display (to display)
Definition at line 470 of file pick_engine.c.
References Pick::d_cnt, Pick::d_idx, Pick::d_object, Pick::m_cnt, Pick::m_idx, and Pick::m_object.
Referenced by picker().
| int new_pick_view | ( | Init * | init | ) |
Initializes a new view for displaying file contents in the pick interface.
| init | Pointer to Init structure containing pick information |
Allocates memory for a new View structure and initializes its fields based on the parameters specified in the Init structure. Sets up the help_spec field for the view, and calls init_view_boxwin to create the view's window. Returns 0 on success, or 1 if window creation fails.
Definition at line 1452 of file pick_engine.c.
References Init::argc, Init::argv, Init::begx, View::begx, Init::begy, View::begy, Init::cols, View::cols, destroy_argv(), Init::f_at_end_remove, View::f_at_end_remove, View::f_help_spec, Init::f_ignore_case, View::f_ignore_case, Init::f_ln, View::f_ln, Init::f_squeeze, View::f_squeeze, Init::h_shift, View::h_shift, View::help_spec, init_view_boxwin(), Init::lines, View::lines, Init::mapp_help, Init::mapp_home, new_view(), View::receiver_cmd, strnz__cat(), strnz__cpy(), Init::tab_stop, View::tab_stop, verify_spec_arg(), and Init::view.
Referenced by open_pick_win().
| void new_view_file | ( | Init * | init, |
| char * | file ) |
Initializes a new view for displaying the contents of a specified file in the pick interface.
| init | Pointer to Init structure containing pick information |
| file | Name of the file to be displayed in the view |
If a view is already initialized, it destroys the existing line table and unmaps the buffer. Then, it sets up the provider command for highlighting the specified file, initializes the view input, and if successful, resets various view parameters, initializes the line table, and displays the first page of the file contents along with the prompt.
Definition at line 1497 of file pick_engine.c.
References border_title(), View::box_win, View::buf, build_prompt(), destroy_line_table(), display_prompt(), View::f_bod, View::f_eod, View::file_pos, View::file_size, initialize_line_table(), View::ln, View::ln_max_pos, View::maxcol, next_page(), pad_refresh(), View::page_bot_ln, View::page_bot_pos, View::page_top_ln, View::page_top_pos, View::prompt_str, View::provider_cmd, strnz__cat(), strnz__cpy(), View::title, Init::view, and view_init_input().
Referenced by picker().
| int open_pick_win | ( | Init * | init | ) |
Initializes the pick window based on the parameters specified in the Pick structure.
| init | Pointer to Init structure containing pick information |
Creates a new window for the pick interface using win_new function with the specified parameters from the Pick structure. If window creation fails, an error message is printed and the function returns 1. Otherwise, initializes the window and box pointers in the Pick structure, sets scrollok and keypad options for the window, and returns 0 on success.
Definition at line 815 of file pick_engine.c.
References Pick::begx, Pick::begy, Pick::box, box_hsplit_new(), Pick::lines, new_pick_view(), Pick::p_view_files, Perror(), Init::pick, Pick::separator_line, ssnprintf(), Pick::title, Pick::width, Pick::win, Pick::win2, win_box, win_ptr, win_win, and win_win2.
Referenced by pick_engine().
| int output_objects | ( | Pick * | pick | ) |
Outputs selected objects to specified output file.
| pick | Pointer to Pick structure containing selected objects and output file information |
If output file cannot be opened, an error message is printed and the function returns 1. Otherwise, selected objects are written to the output file, one per line, and the file is closed before returning 0.
Definition at line 609 of file pick_engine.c.
References Pick::d_cnt, Pick::d_idx, Pick::d_object, Pick::f_selected, Pick::in_spec, Pick::out_fp, Pick::out_spec, strnz__cat(), and strnz__cpy().
Referenced by pick_engine().
| int pick_engine | ( | Init * | init | ) |
Initializes pick interface, calculates window size and position, and enters picker loop.
| init | Pointer to Init structure containing pick information |
Initializes key command strings for chyron display and calculates pick window size and position based on terminal size and pick parameters. Opens pick window and displays first page of objects. Enters picker loop to handle user input and interactions. If user cancels selection, returns -1. If user accepts selection, returns count of selected objects.
Enter picker loop to handle user input and interactions
< Buffer for user input in the field
Definition at line 260 of file pick_engine.c.
References ChyronKey::active, Init::begx, Pick::begx, Init::begy, Pick::begy, Pick::chyron, Pick::cmd, Init::cols, compile_chyron(), Pick::d_cnt, Pick::d_idx, deselect_object(), destroy_chyron(), display_pick_page(), exec_objects(), Pick::f_cmd, Pick::f_out_spec, Pick::f_read_theme, Chyron::key, Chyron::l, Init::lines, Pick::lines, open_pick_win(), Pick::out_spec, output_objects(), Pick::p_view_files, Perror(), Init::pick, pick_std_chyron(), picker(), read_theme(), Pick::select_cnt, Pick::tbl_col_width, Pick::tbl_cols, Pick::tbl_lines, Pick::tbl_page, Pick::tbl_pages, Pick::width, Pick::win2, and Pick::x.
Referenced by init_pick().
| void pick_std_chyron | ( | Pick * | pick | ) |
Sets standard chyron key states based on pick structure.
| pick | Pointer to Pick structure containing chyron and selection information |
Updates the active state of chyron keys based on the current state of the pick structure. Enables or disables keys for help, cancel, accept, view, quit view, process, toggle, search, select, page up, page down, and insert based on selection count, view mode, and table pages.
Definition at line 377 of file pick_engine.c.
References ChyronKey::active, Pick::chyron, Chyron::key, Pick::p_view_files, Pick::select_max, Pick::tbl_page, and Pick::tbl_pages.
Referenced by init_pick(), pick_engine(), and picker().
| int picker | ( | Init * | init, |
| char * | field ) |
Main loop for handling user input and interactions in the pick interface.
| init | Pointer to Init structure containing pick information |
| field | Buffer for user input in the field |
The first loop handles navigation through the pick table. The second loop handles user input for selecting/deselecting objects, accepting the selection, or canceling the selection. Depending on the key pressed, the appropriate action is taken, such as toggling selection, moving to the next/previous object, or displaying the help screen. If the user accepts the selection, the count of selected objects is returned. If the user cancels the selection, -1 is returned.
===========================================================
box display_pick_page_info
'q', or KEY_F(9) cancel selection and exit picker
Enter or KEY_F(10) Accepts current selection and exits picker, returning count of selected objects
KEY_END Moves selection to last object in list
'h' or KEY_LEFT or Backspace Moves selection to previous object in list
'j' or KEY_DOWN Moves selection to next object in list
'k' or KEY_UP Moves selection to previous object in list
'l' or KEY_RIGHT Moves selection to next object in list
pick->obj_idx += pick->tbl_lines -> next column
KEY_NPAGE or 'Ctrl+f' Moves selection to next page of objects
KEY_PPAGE or 'Ctrl+b' Moves selection to previous page of objects
KEY_HOME Moves selection to first object in list
KEY_LL (lower left of numeric pad) Moves selection to last object in list
KEY_MOUSE Handles mouse events for selection and chyron key activation
toggle selection on mouse click
===============================================================
display_field_content
KEY_F(9) Cancels the current operation
KEY_F(10) is the default key for accepting the field
KEY_DC deletes character at cursor
KEY_HOME moves cursor to start of field
KEY_BACKSPACE deletes character before cursor
KEY_LEFT moves cursor left one character
KEY_RIGHT moves cursor right one character
Handles mouse events for field editing
Definition at line 885 of file pick_engine.c.
References ChyronKey::active, border_hsplit_text(), Pick::box, bw_sp, chk, Pick::chyron, click_x, click_y, compile_chyron(), cp_box, cp_nt_hl_rev, cp_nt_rev, Pick::d_cnt, Pick::d_idx, Pick::d_object, deselect_object(), display_chyron(), display_pick_help(), display_pick_page(), dxwgetch(), Pick::f_selected, Chyron::key, Chyron::l, Pick::lines, match_objects(), mouse_win, mvwaddstr_fill(), new_view_file(), Pick::p_view_files, Pick::pg_line, Init::pick, pick_std_chyron(), ran, remove_right_angle(), reverse_object(), rtrim(), Pick::select_cnt, Pick::select_max, Pick::separator_line, set_chyron_key_cp(), sp, ssnprintf(), strnz__cat(), strnz__cpy(), Pick::tbl_col, Pick::tbl_col_width, Pick::tbl_cols, Pick::tbl_line, Pick::tbl_lines, Pick::tbl_page, Pick::tbl_pages, toggle_object(), unreverse_object(), view_cmd_processor(), Pick::width, Pick::win, Pick::win2, Pick::x, Pick::y, and Pick::y_offset.
Referenced by pick_engine().
| int read_pick_input | ( | Init * | init | ) |
Reads pick input from file pointer and saves objects into pick structure.
| init | Pointer to Init structure containing pick information |
Reads lines from pick->in_fp and saves them as objects in the pick structure using save_object function. If no objects are read, returns -1. Otherwise, sets obj_cnt to the number of objects read and resets obj_idx to 0 before returning 0.
Definition at line 229 of file pick_engine.c.
References Pick::argc, Pick::argv, Pick::in_buf, Pick::in_fp, Pick::m_cnt, Pick::m_idx, Init::pick, save_object(), Pick::select_cnt, and Pick::tbl_pages.
Referenced by init_pick().
| void reverse_object | ( | Pick * | pick | ) |
Reverses the display of the currently selected object in pick window.
| pick | Pointer to Pick structure containing object and display information |
Calculates the x coordinate for the currently selected object based on the current table column and column width. Moves the cursor to the object's position in the pick window, turns on reverse video attribute, and displays the object's text. Turns off reverse video attribute and refreshes the pick window to show the updated display. Moves the cursor back to the position before the object text for potential further interactions.
Definition at line 494 of file pick_engine.c.
References CC_NT, CC_NT_REV, chk, Pick::d_cnt, Pick::d_idx, Pick::d_object, Pick::f_selected, Pick::lines, mvwaddstr_fill(), ran, Pick::tbl_col, Pick::tbl_col_width, Pick::tbl_cols, Pick::tbl_line, Pick::tbl_page, Pick::win, Pick::x, Pick::y, and Pick::y_offset.
Referenced by picker().
| void save_object | ( | Pick * | pick, |
| char * | s ) |
Saves a string as an object in the pick structure.
If the current object index is less than the maximum allowed, saves the string as an object in the pick structure. Updates the column width if necessary and marks the object as not selected. Increments the object index for the next object to be saved.
Definition at line 411 of file pick_engine.c.
References Pick::f_selected, Pick::m_idx, Pick::m_object, strnz__cpy(), and Pick::tbl_col_width.
Referenced by read_pick_input().
| void toggle_object | ( | Pick * | pick | ) |
Toggles the selection state of the currently selected object in pick window.
| pick | Pointer to Pick structure containing object and selection information |
Calculates the x coordinate for the currently selected object based on the current table column and column width. If the object is currently selected, it is deselected by updating the selection count, marking it as not selected, and displaying a space before the object text. If the object is not currently selected, it is selected by updating the selection count, marking it as selected, and displaying an asterisk before the object text. Refreshes the pick window to show the updated display. Moves the cursor back to the position before the object text for potential further interactions.
Definition at line 564 of file pick_engine.c.
References chk, Pick::d_idx, Pick::f_selected, Pick::select_cnt, sp, Pick::tbl_col, Pick::tbl_col_width, Pick::win, Pick::x, and Pick::y.
Referenced by picker().
| void unreverse_object | ( | Pick * | pick | ) |
Unreverses the display of the currently selected object in pick window.
| pick | Pointer to Pick structure containing object and display information |
Calculates the x coordinate for the currently selected object based on the current table column and column width. Moves the cursor to the object's position in the pick window and displays the object's text without reverse video attribute. Refreshes the pick window to show the updated display. Moves the cursor back to the position before the object text for potential further interactions.
Definition at line 523 of file pick_engine.c.
References CC_NT, chk, Pick::d_cnt, Pick::d_idx, Pick::d_object, Pick::f_selected, Pick::lines, mvwaddstr_fill(), sp, Pick::tbl_col, Pick::tbl_col_width, Pick::tbl_cols, Pick::tbl_line, Pick::tbl_page, Pick::win, Pick::x, Pick::y, and Pick::y_offset.
Referenced by picker().