Fix typos and add comments
[smenu.git] / usage.c
blob6403da9bc5e7356f65aa11728df58a353d5be9b7
1 /* ################################################################### */
2 /* Copyright 2015, Pierre Gentile (p.gen.progs@gmail.com) */
3 /* */
4 /* This Source Code Form is subject to the terms of the Mozilla Public */
5 /* License, v. 2.0. If a copy of the MPL was not distributed with this */
6 /* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 /* ################################################################### */
9 /* **************** */
10 /* Usage functions. */
11 /* **************** */
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
17 #include "usage.h"
18 #include "ctxopt.h"
20 static void
21 common_help(void);
23 /* ======================= */
24 /* Usage display and exit. */
25 /* ======================= */
26 static void
27 common_help(void)
29 printf("-h|-help\n");
30 printf(" displays this help.\n");
31 printf("-u|-usage\n");
32 printf(" displays the synopsis of the current context.\n");
33 printf("-i|-in|-inc|-incl|-include\n");
34 printf(" sets the regex input filter to match the selectable words.\n");
35 printf("-e|-ex|-exc|-excl|-exclude\n");
36 printf(" sets the regex input filter to match the non-selectable "
37 "words.\n");
38 printf("-m|-msg|-message|-title\n");
39 printf(" displays a one-line message/title above the window.\n");
40 printf("-!|-int|-int_string\n");
41 printf(" outputs an optional string when ^C is typed.\n");
42 printf("-a|-attr|-attributes\n");
43 printf(" sets the attributes for the various displayed elements.\n");
44 printf("-1|-l1|-level1,-2|-l2|-level2,...,-9|-l9|-level9\n");
45 printf(" gives specific colors to up to 9 classes of "
46 "selectable words.\n");
47 printf("-z|-zap|-zap_glyphs bytes\n");
48 printf(" defines a set of glyphs that should be ignored in the input "
49 "stream.\n");
50 printf("-n|-lines|-height\n");
51 printf(" sets the maximum number of lines in the selection window.\n");
52 printf(" This number is autodetected when no number is given.\n");
53 printf("-b|-blank\n");
54 printf(" displays non printable characters as space.\n");
55 printf("-.|-dot|-invalid\n");
56 printf(" defines the substitution character for a non-printable "
57 "character.\n");
58 printf("-M|-middle|-center\n");
59 printf(" centers the display if possible.\n");
60 printf("-d|-restore|-delete|-clean|-delete_window|-clean_window\n");
61 printf(" clears the lines used by the selection window on exit.\n");
62 printf("-k|-ks|-keep_spaces\n");
63 printf(" does not trim spaces surrounding the output string if any.\n");
64 printf("-W|-ws|-wd|-word_delimiters|-word_separators\n");
65 printf(" defines word separators in the input stream.\n");
66 printf("-L|-ls|-ld|-line-delimiters|-line_separators\n");
67 printf(" defines line separators in the input stream.\n");
68 printf("-q|-no_bar|-no_scroll_bar\n");
69 printf(" prevents the scroll bar from being displayed.\n");
70 printf("-no_hbar|-no_hor_scroll_bar\n");
71 printf(" prevents the horizontal scroll bar from being displayed.\n");
72 printf("-hbar|-hor_scroll_bar\n");
73 printf(" always displays the horizontal scroll bar when certain lines are "
74 "truncated.\n");
75 printf("-S|-subst\n");
76 printf(" defines the post-substitution action to apply to all words.\n");
77 printf("-I|-si|-subst_included\n");
78 printf(" defines the post-substitution action to apply to selectable "
79 "words only.\n");
80 printf("-E|-se|-subst_excluded\n");
81 printf(" defines the post-substitution action to apply to non-selectable "
82 "words only.\n");
83 printf("-ES|-early_subst\n");
84 printf(" defines the early substitution action to apply to all words.\n");
85 printf("-/|-search_method\n");
86 printf(" changes the affectation of the / key (default: fuzzy search).\n");
87 printf("-s|-sp|-start|-start_pattern\n");
88 printf(" sets the initial cursor position (refer to the manual for "
89 "more details).\n");
90 printf("-x|-tmout|-timeout/-X|-htmout|-hidden_timeout\n");
91 printf(" defines a timeout and specifies what to do when it expires.\n");
92 printf("-r|-auto_validate\n");
93 printf(" enables ENTER to validate the selection even in search mode.\n");
94 printf("-is|-incremental_search\n");
95 printf(" prevents the search buffer from being reset when starting a new "
96 "search\n");
97 printf(" session.\n");
98 printf("-v|-vb|-visual_bell\n");
99 printf(" makes the bell visual (fuzzy search with error).\n");
100 printf("-Q|-ignore_quotes\n");
101 printf(" treats single and double quotes as normal characters.\n");
102 printf("-lim|-limits\n");
103 printf(" overload the words number/max. word length/max columns limits.\n");
104 printf("-al|-align\n");
105 printf(" sets alignments for words selected by regular expressions.\n");
106 printf("-f|-forgotten_timeout|-global_timeout\n");
107 printf(" defines a global inactivity timeout, defaults to 15 min.\n");
108 printf("-nm|-no_mouse\n");
109 printf(" disable a possibly auto-detected mouse tracking support.\n");
110 printf("-br|-buttons|-button_remapping\n");
111 printf(" Remaps the left and right mouse buttons, default is 1 and 3.\n");
112 printf("-dc|-dcd|-double_click|-double_click_delay\n");
113 printf(" Change the mouse double-click delay which is 150 ms by default.\n");
114 printf("-sb|-sbw|-show_blank_words\n");
115 printf(" Make blank words visible and usable even in non column mode.\n");
118 void
119 main_help(void)
121 ctxopt_ctx_disp_usage("Main", continue_after);
123 printf("\n----------------------------------------");
124 printf("----------------------------------------\n");
126 printf("\nThis is a filter that gets words from stdin or from a file and ");
127 printf("outputs\n");
128 printf("the selected words (or nothing) on stdout in a nice selection ");
129 printf("window\n\n");
130 printf("The selection window appears on /dev/tty ");
131 printf("just below the current line\n");
132 printf("(no clear screen!).\n\n");
134 printf("Short description of allowed parameters:\n\n");
135 common_help();
137 printf("-V|-version\n");
138 printf(" displays the current version and quits.\n");
139 printf("-H|-long_help\n");
140 printf(" displays a full help and the options available in all "
141 "contexts.\n");
142 printf("-N|-number/-U|-unnumber\n");
143 printf(" creates or deletes direct access entries for words matching "
144 "(or not) a\n");
145 printf(" specific regex.\n");
146 printf("-F|-en|-embedded_number\n");
147 printf(" creates direct access entries by extracting the numbers from the "
148 "input words.\n");
149 printf("-c|-col|-col_mode|-column\n");
150 printf(" is like -tab without argument but respects end of lines.\n");
151 printf("-l|-line|-line_mode\n");
152 printf(" is like -col without column alignments.\n");
153 printf("-t|-tab|-tab_mode|-tabulate_mode\n");
154 printf(" tabulates the items. The number of columns can be limited "
155 "with\n");
156 printf(" an optional number.\n");
157 printf("-T|-tm|-tag|-tag_mode/-P|-pm|-pin|-pin_mode\n");
158 printf(" enables the tagging mode (multi-selections). ");
159 printf("An optional parameter\n");
160 printf(" defines the separator string between the selected words ");
161 printf("on the output.\n");
162 printf(" A single space is the default separator.\n");
164 printf("\nNavigation keys are:\n");
165 printf(" - Left/Down/Up/Right arrows or h/j/k/l, H/J/K/L.\n");
166 printf(" - Home/End, SHIFT|CTRL+Home/End CTRK+J/CTRL+K.\n");
167 printf(" - Numbers if some words are numbered (-N/-U/-F).\n");
168 printf(" - SPACE to search for the next match of a previously\n");
169 printf(" entered search prefix if any, see below.\n\n");
170 printf("Other useful keys are:\n");
171 printf(" - Help key (temporary display of a short help line): "
172 "?\n");
173 printf(" - Exit key without output (do nothing) : "
174 "q\n");
175 printf(" - Tagging keys: Select/Deselect/Toggle : "
176 "INS/DEL/t\n");
177 printf(" - Selection key : "
178 "ENTER\n");
179 printf(" - Cancel key : "
180 "ESC\n");
181 printf(" - Search key : "
182 "/ or CTRL-F\n\n");
183 printf("The search key activates a timed search mode in which\n");
184 printf("you can enter the first letters of the searched word.\n");
185 printf("When entering this mode you have 10s to start typing\n");
186 printf("and each entered letter restarts this timer.\n");
187 printf("After this time, the normal navigation mode is restored.\n\n");
188 printf("Notes:\n");
189 printf("- the search timer can be cancelled by pressing ESC.\n");
190 printf("- a bad search letter can be removed with ");
191 printf("CTRL-H or Backspace.\n\n");
192 printf("(C) Pierre Gentile.\n\n");
194 exit(EXIT_FAILURE);
197 void
198 columns_help(void)
200 ctxopt_ctx_disp_usage("Columns", continue_after);
202 printf("\n----------------------------------------");
203 printf("----------------------------------------\n");
205 printf("Short description of allowed parameters:\n\n");
206 common_help();
208 printf("-C|-cs|-cols|-cols_select\n");
209 printf(" sets alignments and columns restrictions for selections.\n");
210 printf("-R|-rs|-rows|-rows_select\n");
211 printf(" sets rows restrictions for selections.\n");
212 printf("-w|-wide|-wide_mode\n");
213 printf(" uses all the terminal width for the columns if their numbers "
214 "is given.\n");
215 printf("-g|-gutter\n");
216 printf(" separates columns with a character in column or tabulate "
217 "mode.\n");
218 printf("-N|-number/-U|-unnumber\n");
219 printf(" numbers/un-numbers and provides a direct access to words "
220 "matching\n");
221 printf(" (or not) a specific regex.\n");
222 printf("-F|-en|-embedded_number\n");
223 printf(" numbers and provides a direct access to words by extracting the "
224 "number\n");
225 printf("-T|-tm|-tag|-tag_mode/-P|-pm|-pin|-pin_mode\n");
226 printf(" enables the tagging (multi-selections) mode. ");
227 printf("An optional parameter\n");
228 printf(" sets the separator string between the selected words ");
229 printf("on the output.\n");
230 printf(" A single space is the default separator.\n");
231 printf("-A|-fc|-first_column\n");
232 printf(" forces the specified word pattern to start a line.\n");
233 printf("-Z|-lc|-last_column\n");
234 printf(" forces the specified word pattern to end a line.\n");
237 void
238 lines_help(void)
240 ctxopt_ctx_disp_usage("Lines", continue_after);
242 printf("\n----------------------------------------");
243 printf("----------------------------------------\n");
245 printf("Short description of allowed parameters:\n\n");
246 common_help();
248 printf("-R|-rs|-rows|-row_select\n");
249 printf(" sets alignments and rows restrictions for selections.\n");
250 printf("-N|-number/-U|-unnumber\n");
251 printf(" numbers/un-numbers and provides a direct access to words "
252 "matching\n");
253 printf(" (or not) a specific regex.\n");
254 printf("-F|-en|-embedded_number\n");
255 printf(" numbers and provides a direct access to words by extracting the "
256 "number\n");
257 printf("-T|-tm|-tag|-tag_mode/-P|-pm|-pin|-pin_mode\n");
258 printf(" enables the tagging (multi-selections) mode. ");
259 printf("An optional parameter\n");
260 printf(" sets the separator string between the selected words ");
261 printf("on the output.\n");
262 printf(" A single space is the default separator.\n");
263 printf("-A|-fc|-first_column\n");
264 printf(" forces the specified word pattern to start a line.\n");
265 printf("-Z|-lc|-last_column\n");
266 printf(" forces the specified word pattern to end a line.\n");
269 void
270 tabulations_help(void)
272 ctxopt_ctx_disp_usage("Tabulations", continue_after);
274 printf("\n----------------------------------------");
275 printf("----------------------------------------\n");
277 printf("Short description of allowed parameters:\n\n");
278 common_help();
280 printf("-w|-wide|-wide_mode\n");
281 printf(" uses all the terminal width for the columns if their numbers "
282 "is given.\n");
283 printf("-g|-gutter\n");
284 printf(" separates columns with a character in column or tabulate "
285 "mode.\n");
286 printf("-N|-number/-U|-unnumber\n");
287 printf(" numbers/un-numbers and provides a direct access to words "
288 "matching\n");
289 printf(" (or not) a specific regex.\n");
290 printf("-F|-en|-embedded_number\n");
291 printf(" numbers and provides a direct access to words by extracting the "
292 "number\n");
293 printf("-T|-tm|-tag|-tag_mode/-P|-pm|-pin|-pin_mode\n");
294 printf(" enables the tagging (multi-selections) mode. ");
295 printf("An optional parameter\n");
296 printf(" sets the separator string between the selected words ");
297 printf("on the output.\n");
298 printf(" A single space is the default separator.\n");
299 printf("-A|-fc|-first_column\n");
300 printf(" forces the specified word pattern to start a line.\n");
301 printf("-Z|-lc|-last_column\n");
302 printf(" forces the specified word pattern to end a line.\n");
305 void
306 tagging_help(void)
308 ctxopt_ctx_disp_usage("Tagging", continue_after);
310 printf("\n----------------------------------------");
311 printf("----------------------------------------\n");
313 printf("The following parameters are available in this context:\n\n");
314 common_help();
316 printf("-p|-at|-auto_tag\n");
317 printf(" activates the auto-tagging.\n");
318 printf("-0|-noat|-no_auto_tag\n");
319 printf(" do not auto-tag the word under the cursor when in tagged mode\n");
320 printf(" and no other word is selected.\n");
322 exit(EXIT_FAILURE);