xref: /freebsd/contrib/bsddialog/lib/bsddialog.3 (revision 55224280e2f20474f83001cbc402b21fba8f1c4b)
1.\"
2.\" Copyright (c) 2021 Alfonso Sabato Siciliano
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd December 16, 2021
26.Dt BSDDIALOG 3
27.Os
28.Sh NAME
29.Nm bsddialog_backtitle ,
30.Nm bsddialog_clearterminal ,
31.Nm bsddialog_color ,
32.Nm bsddialog_buildlist ,
33.Nm bsddialog_checklist ,
34.Nm bsddialog_datebox ,
35.Nm bsddialog_end ,
36.Nm bsddialog_form ,
37.Nm bsddialog_gauge ,
38.Nm bsddialog_geterror ,
39.Nm bsddialog_get_theme
40.Nm bsddialog_infobox ,
41.Nm bsddialog_init ,
42.Nm bsddialog_initconf ,
43.Nm bsddialog_menu ,
44.Nm bsddialog_mixedgauge ,
45.Nm bsddialog_mixedlist ,
46.Nm bsddialog_msgbox ,
47.Nm bsddialog_pause ,
48.Nm bsddialog_radiolist ,
49.Nm bsddialog_rangebox ,
50.Nm bsddialog_set_theme ,
51.Nm bsddialog_set_default_theme ,
52.Nm bsddialog_textbox ,
53.Nm bsddialog_timebox ,
54.Nm bsddialog_yesno
55.Nd terminal dialogs and widgets
56.Sh LIBRARY
57.Lb libbsddialog
58.Sh SYNOPSIS
59.In bsddialog.h
60
61.Fd #define LIBBSDDIALOG_VERSION
62
63.Fd #define BSDDIALOG_ERROR
64.Fd #define BSDDIALOG_OK
65.Fd #define BSDDIALOG_YES
66.Fd #define BSDDIALOG_CANCEL
67.Fd #define BSDDIALOG_NO
68.Fd #define BSDDIALOG_HELP
69.Fd #define BSDDIALOG_EXTRA
70.Fd #define BSDDIALOG_ITEM_HELP
71.Fd #define BSDDIALOG_TIMEOUT
72.Fd #define BSDDIALOG_ESC
73.Fd #define BSDDIALOG_GENERIC1
74.Fd #define BSDDIALOG_GENERIC2
75
76.Fd #define BSDDIALOG_FULLSCREEN
77.Fd #define BSDDIALOG_AUTOSIZE
78.Fd #define BSDDIALOG_CENTER
79
80.Fd struct bsddialog_conf
81.Fd struct bsddialog_menuitem
82.Fd enum bsddialog_grouptype
83.Fd struct bsddialog_menugroup
84.Fd struct bsddialog_formitem
85
86.Ft int
87.Fn bsddialog_backtitle "struct bsddialog_conf *conf" "char *backtitle"
88.Ft int
89.Fo bsddialog_buildlist
90.Fa "struct bsddialog_conf *conf"
91.Fa "char* text"
92.Fa "int rows"
93.Fa "int cols"
94.Fa "unsigned int menurows"
95.Fa "int nitems"
96.Fa "struct bsddialog_menuitem *items"
97.Fa "int *focusitem"
98.Fc
99.Ft int
100.Fo bsddialog_checklist
101.Fa "struct bsddialog_conf *conf"
102.Fa "char* text"
103.Fa "int rows"
104.Fa "int cols"
105.Fa "unsigned int menurows"
106.Fa "int nitems"
107.Fa "struct bsddialog_menuitem *items"
108.Fa "int *focusitem"
109.Fc
110.Ft int
111.Fn bsddialog_clearterminal "void"
112.Ft int
113.Fo bsddialog_datebox"
114.Fa "struct bsddialog_conf *conf"
115.Fa "char* text"
116.Fa "int rows"
117.Fa "int cols"
118.Fa "unsigned int *yy"
119.Fa "unsigned int *mm"
120.Fa "unsigned int *dd"
121.Fc
122.Ft int
123.Fn bsddialog_end "void"
124.Ft int
125.Fo bsddialog_form
126.Fa "struct bsddialog_conf *conf"
127.Fa "char* text"
128.Fa "int rows"
129.Fa "int cols"
130.Fa "unsigned int formheight"
131.Fa "unsigned int nitems"
132.Fa "struct bsddialog_formitem *items"
133.Fc
134.Ft int
135.Fo bsddialog_gauge
136.Fa "struct bsddialog_conf *conf"
137.Fa "char* text"
138.Fa "int rows"
139.Fa "int cols"
140.Fa "unsigned int perc"
141.Fc
142.Ft const char *
143.Fn bsddialog_geterror "void"
144.Ft int
145.Fo bsddialog_infobox
146.Fa "struct bsddialog_conf *conf"
147.Fa "char* text"
148.Fa "int rows"
149.Fa "int cols"
150.Fc
151.Ft int
152.Fn bsddialog_init "void"
153.Ft int
154.Fn bsddialog_initconf "struct bsddialog_conf *conf"
155.Ft int
156.Fo bsddialog_menu
157.Fa "struct bsddialog_conf *conf"
158.Fa "char* text"
159.Fa "int rows"
160.Fa "int cols"
161.Fa "unsigned int menurows"
162.Fa "int nitems"
163.Fa "struct bsddialog_menuitem *items"
164.Fa "int *focusitem"
165.Fc
166.Ft int
167.Fo bsddialog_mixedgauge
168.Fa "struct bsddialog_conf *conf"
169.Fa "char* text"
170.Fa "int rows"
171.Fa "int cols"
172.Fa "unsigned int mainperc"
173.Fa "unsigned int nminibars"
174.Fa "char **minilabels"
175.Fa "int *minipercs"
176.Fc
177.Ft int
178.Fo bsddialog_mixedlist
179.Fa "struct bsddialog_conf *conf"
180.Fa "char* text"
181.Fa "int rows"
182.Fa "int cols"
183.Fa "unsigned int menurows"
184.Fa "int ngroups"
185.Fa "struct bsddialog_menugroup *groups"
186.Fa "int *focuslist"
187.Fa "int *focusitem"
188.Fc
189.Ft int
190.Fo bsddialog_msgbox
191.Fa "struct bsddialog_conf *conf"
192.Fa "char* text"
193.Fa "int rows"
194.Fa "int cols"
195.Fc
196.Ft int
197.Fo bsddialog_pause
198.Fa "struct bsddialog_conf *conf"
199.Fa "char* text"
200.Fa "int rows"
201.Fa "int cols"
202.Fa "unsigned int sec"
203.Fc
204.Ft int
205.Fo bsddialog_radiolist
206.Fa "struct bsddialog_conf *conf"
207.Fa "char* text"
208.Fa "int rows"
209.Fa "int cols"
210.Fa "unsigned int menurows"
211.Fa "int nitems"
212.Fa "struct bsddialog_menuitem *items"
213.Fa "int *focusitem"
214.Fc
215.Ft int
216.Fo bsddialog_rangebox
217.Fa "struct bsddialog_conf *conf"
218.Fa "char* text"
219.Fa "int rows"
220.Fa "int cols"
221.Fa "int min"
222.Fa "int max"
223.Fa "int *value"
224.Fc
225.Ft int
226.Fo bsddialog_textbox
227.Fa "struct bsddialog_conf *conf"
228.Fa "char* file"
229.Fa "int rows"
230.Fa "int cols"
231.Fc
232.Ft int
233.Fo bsddialog_timebox
234.Fa "struct bsddialog_conf *conf"
235.Fa "char* text"
236.Fa "int rows"
237.Fa "int cols"
238.Fa "unsigned int *hh"
239.Fa "unsigned int *mm"
240.Fa "unsigned int *ss"
241.Fc
242.Ft int
243.Fo bsddialog_yesno
244.Fa "struct bsddialog_conf *conf"
245.Fa "char* text"
246.Fa "int rows"
247.Fa "int cols"
248.Fc
249
250.In bsddialog_theme.h
251
252.Fd #define BSDDIALOG_BOLD
253.Fd #define BSDDIALOG_REVERSE
254.Fd #define BSDDIALOG_UNDERLINE
255
256.Fd enum bsddialog_color
257.Fd enum bsddialog_default_theme
258.Fd struct bsddialog_theme
259
260.Ft int
261.Fo bsddialog_color
262.Fa "enum bsddialog_color background"
263.Fa "enum bsddialog_color foreground"
264.Fa "unsigned int flags"
265.Fc
266.Ft int
267.Fn bsddialog_get_theme "struct bsddialog_theme *theme"
268.Ft int
269.Fn bsddialog_set_default_theme "enum bsddialog_default_theme theme"
270.Ft int
271.Fn bsddialog_set_theme "struct bsddialog_theme *theme"
272.Sh DESCRIPTION
273The
274.Nm BSDDialog
275library is an API to write a tools with a Text User Interface. It can build
276dialogs and widgets: to show messages, to get input and to inform about a
277computation status.
278.Pp
279.Bd -literal -offset indent -compact
280/* size and position */
281#define BSDDIALOG_FULLSCREEN	-1
282#define BSDDIALOG_AUTOSIZE	 0
283#define BSDDIALOG_CENTER	-1
284
285struct bsddialog_conf {
286	bool ascii_lines;
287	unsigned int aspect_ratio;
288	unsigned int auto_minheight;
289	unsigned int auto_minwidth;
290	char *bottomtitle;
291	bool clear;
292	char *f1_file;
293	char *f1_message;
294	int  *get_height;
295	int  *get_width;
296	bool no_lines;
297	bool shadow;
298	unsigned int sleep;
299	char *title;
300	int  y;
301	int  x;
302	struct {
303		bool colors;
304	} text;
305	struct {
306		bool align_left;
307		char *default_item;
308		bool no_desc;
309		bool no_name;
310		bool shortcut_buttons;
311	} menu;
312	struct {
313		int  securech;
314		bool value_withcancel;
315		bool value_withextra;
316		bool value_withhelp;
317	} form;
318	struct {
319		bool without_ok;
320		char *ok_label;
321		bool with_extra;
322		char *extra_label;
323		bool without_cancel;
324		char *cancel_label;
325		bool default_cancel;
326		bool with_help;
327		char *help_label;
328		char *exit_label;
329		char *generic1_label;
330		char *generic2_label;
331		char *default_label;
332	} button;
333};
334.Ed
335.Pp
336
337.Ss Dialogs
338.Pp
339.Bd -literal -offset indent -compact
340struct bsddialog_menuitem {
341	char *prefix;
342	bool on;
343	unsigned int depth;
344	char *name;
345	char *desc;
346	char *bottomdesc;
347};
348
349enum bsddialog_grouptype {
350	BSDDIALOG_CHECKLIST,
351	BSDDIALOG_RADIOLIST,
352	BSDDIALOG_SEPARATOR,
353};
354
355struct bsddialog_menugroup {
356	enum bsddialog_grouptype type;
357	unsigned int nitems;
358	struct bsddialog_menuitem *items;
359};
360
361struct bsddialog_formitem {
362	char *label;
363	unsigned int ylabel;
364	unsigned int xlabel;
365
366	char *init;
367	unsigned int yfield;
368	unsigned int xfield;
369	unsigned int fieldlen;
370	unsigned int maxvaluelen;
371	char *value; /* allocated memory */
372#define BSDDIALOG_FIELDHIDDEN    1U
373#define BSDDIALOG_FIELDREADONLY  2U
374	unsigned int flags;
375
376	char *bottomdesc;
377};
378.Ed
379.Pp
380
381.Ss Theme
382.Pp
383.Bd -literal -offset indent -compact
384/* f_ focus/active element */
385struct bsddialog_theme {
386	struct {
387		int color;
388	} terminal;
389	struct {
390		int color;
391		unsigned int h;
392		unsigned int w;
393	} shadow;
394	struct {
395		int  color;
396		bool delimtitle;
397		int  titlecolor;
398		int  lineraisecolor;
399		int  linelowercolor;
400		int  bottomtitlecolor;
401	} dialog;
402	struct {
403		unsigned int hmargin;
404	} text;
405	struct {
406		int arrowcolor;
407		int selectorcolor;
408		int f_namecolor;
409		int namecolor;
410		int f_desccolor;
411		int desccolor;
412		int namesepcolor;
413		int descsepcolor;
414		int f_shortcutcolor;
415		int shortcutcolor;
416	} menu;
417	struct {
418		int f_fieldcolor;
419		int fieldcolor;
420		int readonlycolor;
421	} form;
422	struct {
423		int f_color;
424		int color;
425	} bar;
426	struct {
427		unsigned int space;
428		int leftch;
429		int rightch;
430		int delimcolor;
431		int f_delimcolor;
432		int color;
433		int f_color;
434		int shortcutcolor;
435		int f_shortcutcolor;
436	} button;
437};
438
439enum bsddialog_default_theme {
440	BSDDIALOG_THEME_BLACKWHITE,
441	BSDDIALOG_THEME_BSDDIALOG,
442	BSDDIALOG_THEME_DEFAULT,
443	BSDDIALOG_THEME_DIALOG,
444};
445
446enum bsddialog_color {
447	BSDDIALOG_BLACK = 0,
448	BSDDIALOG_RED,
449	BSDDIALOG_GREEN,
450	BSDDIALOG_YELLOW,
451	BSDDIALOG_BLUE,
452	BSDDIALOG_MAGENTA,
453	BSDDIALOG_CYAN,
454	BSDDIALOG_WHITE,
455};
456
457#define BSDDIALOG_BOLD         1U
458#define BSDDIALOG_REVERSE      2U
459#define BSDDIALOG_UNDERLINE    4U
460.Ed
461.Pp
462
463.Sh RETURN VALUES
464The sysctlmif_oidbyname(),	sysctlmif_oidextendedbyname(),
465     sysctlmif_name(), sysctlmif_desc(), sysctlmif_descbyname(),
466     sysctlmif_label(),	sysctlmif_labelbyname(), sysctlmif_fmt(),
467     sysctlmif_fmtbyname(), sysctlmif_oidbyname0(), sysctlmif_oidbyname1(),
468     sysctlmif_oidbyname2(), sysctlmif_oidbyname3(), sysctlmif_oidbyname4(),
469     sysctlmif_oidbyname5(), sysctlmif_oidbyname6(), and
470     sysctlmif_oidbyname7() functions return the value 0 if successful;	other-
471     wise the value -1 is returned and the global variable errno is set	to in-
472     dicate the	error.
473
474
475functions return NULL upon	error or a pointer to allo-
476     cated memory for success.
477
478.Sh EXAMPLES
479Complete set of examples:
480.Lk https://gitlab.com/alfix/bsddialog/-/blob/main/examples_library/
481.Pp
482If installed:
483.Dl /usr/local/share/examples/libbsddialog
484.Pp
485"Yes-No Question" Example:
486.Pp
487.Bd -literal -offset indent -compact
488int output;
489struct bsddialog_conf conf;
490
491bsddialog_initconf(&conf);
492conf.title = "yesno";
493if (bsddialog_init() == BSDDIALOG_ERROR)
494	return (1);
495
496output = bsddialog_yesno(&conf, "Example", 7, 25);
497
498bsddialog_end();
499
500switch (output) {
501case BSDDIALOG_YES:
502	printf("OK\\n");
503	break;
504case BSDDIALOG_NO
505	printf("NO\\n");
506	break;
507case BSDDIALOG_ESC;
508	printf("ESC\\n");
509	break;
510case BSDDIALOG_ERROR:
511	printf("Error: %s\\n", bsddialog_geterror());
512}
513.Ed
514.Sh SEE ALSO
515.Xr bsddialog 1
516.Sh HISTORY
517The
518.Nm bsddialog
519library first appeared in
520.Fx 14.0 .
521.Sh AUTHORS
522.Nm bsddialog
523was written by
524.An Alfonso Sabato Siciliano Aq Mt alf.siciliano@gmail.com .
525.Sh CAVEATS
526See
527.Xr bsddialog
528.Sh BUGS
529See
530.Xr bsddialog 1
531