C-Menu 0.2.9
A User Interface Toolkit
Loading...
Searching...
No Matches
pick_engine.c File Reference

pick from a list of choices More...

#include "common.h"
#include <fcntl.h>
#include <stdbool.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
Include dependency graph for pick_engine.c:

Go to the source code of this file.

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.
void end_pick_view (Init *)
int exec_objects (Init *init)
 Executes specified command with selected objects as arguments.
int init_pick (Init *init, int argc, char **argv, uint by, uint 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.
int read_theme (Init *)
void remove_right_angle (Pick *)
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.

Variables

int calculated_idx
int obj_idx
char const pagers_editors [12][10]
int pg_lines
int pipe_fd [2]
int tbl_col
int tbl_cols
int tbl_line
int tbl_page
int tbl_pages

Detailed Description

pick from a list of choices

Author
Bill Waller Copyright (c) 2025 MIT License billx.nosp@m.wall.nosp@m.er@gm.nosp@m.ail..nosp@m.com
Date
2026-02-09

Definition in file pick_engine.c.

Function Documentation

◆ end_pick_view()

void end_pick_view ( Init * )

◆ read_theme()

int read_theme ( Init * init)

Definition at line 581 of file pick_engine.c.

581 {
582 int rc;
583 expand_tilde(init->mapp_theme, MAXLEN - 1);
584 rc = process_config_file(init->mapp_theme, init);
585 if (rc)
586 return rc;
587 SIO *sio = init->sio;
588 initialize_cells(sio);
589 ui_render();
590 return 0;
591}
void ui_render()
Definition ui_ncurses.c:800
#define MAXLEN
Definition curskeys.c:15
int process_config_file(char *, Init *)
Definition init.c:663
void initialize_cells(SIO *sio)
Initialize local color variables and color pairs based on SIO settings.
Definition dwin.c:177
bool expand_tilde(char *, uint)
Replaces "~/" in string with the user's home directory.
Definition futil.c:963
The SIO structure encapsulates various aspects of the terminal's state and configuration,...
Definition cm.h:688
SIO * sio
Definition common.h:114
char mapp_theme[MAXLEN]
Definition common.h:152

References expand_tilde(), initialize_cells(), Init::mapp_theme, process_config_file(), Init::sio, and ui_render().

Referenced by pick_engine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_right_angle()

void remove_right_angle ( Pick * pick)

Definition at line 530 of file pick_engine.c.

530 {
531 UiSurface *sfc = pick->surface;
532 if (pick->d_idx >= pick->d_cnt)
533 pick->d_idx = pick->d_cnt - 1;
534 pick->tbl_line = (pick->d_idx / pick->tbl_cols) % pick->lines;
535 pick->y = pick->tbl_line + pick->y_offset;
536 pick->d_idx = pick->tbl_page * pick->lines * pick->tbl_cols + pick->tbl_col * pick->lines + pick->tbl_line;
537 if (pick->f_selected[pick->d_idx])
538 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_chk, 1);
539 else
540 ui_mvwadd_wchnstr(sfc, WIN, pick->y, 0, &cell_sp, 1);
541 ui_cursor_move(sfc, WIN, pick->y, 0);
542}
int ui_cursor_move(UiSurface *s, uint w, uint y, uint x)
Definition ui_ncurses.c:727
int ui_mvwadd_wchnstr(UiSurface *s, uint w, uint y, uint x, const UiCell *cell, uint m)
Pick * pick
Definition mem.c:36
UiCell cell_sp
Definition dwin.c:120
UiCell cell_chk
Definition dwin.c:104
A drawable surface in the NotCurses backend.

References cell_chk, cell_sp, Pick::d_cnt, Pick::d_idx, Pick::f_selected, Pick::lines, Pick::surface, Pick::tbl_col, Pick::tbl_cols, Pick::tbl_line, Pick::tbl_page, ui_cursor_move(), ui_mvwadd_wchnstr(), WIN, Pick::y, and Pick::y_offset.

Referenced by picker().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ calculated_idx

int calculated_idx

Definition at line 24 of file pick_engine.c.

◆ obj_idx

int obj_idx

Definition at line 24 of file pick_engine.c.

◆ pagers_editors

char const pagers_editors
Initial value:
= {"view", "view", "less", "more",
"vi", "vim", "nano", "nvim",
"pico", "emacs", "edit", ""}

Definition at line 48 of file pick_engine.c.

48 {"view", "view", "less", "more",
49 "vi", "vim", "nano", "nvim",
50 "pico", "emacs", "edit", ""};

◆ pg_lines

int pg_lines

Definition at line 23 of file pick_engine.c.

◆ pipe_fd

int pipe_fd

Definition at line 46 of file pick_engine.c.

Referenced by init_pick().

◆ tbl_col

int tbl_col

Definition at line 23 of file pick_engine.c.

◆ tbl_cols

int tbl_cols

Definition at line 23 of file pick_engine.c.

◆ tbl_line

int tbl_line

Definition at line 23 of file pick_engine.c.

◆ tbl_page

int tbl_page

Definition at line 23 of file pick_engine.c.

◆ tbl_pages

int tbl_pages

Definition at line 23 of file pick_engine.c.