xref: /freebsd/contrib/bsddialog/lib/bsddialog.3 (revision d4eeb02986980bf33dd56c41ceb9fc5f180c0d47)
1.\"
2.\" Copyright (c) 2021-2022 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 February 9, 2022
26.Dt BSDDIALOG 3
27.Os
28.Sh NAME
29.Nm bsddialog_backtitle ,
30.Nm bsddialog_clearterminal ,
31.Nm bsddialog_color ,
32.Nm bsddialog_checklist ,
33.Nm bsddialog_datebox ,
34.Nm bsddialog_end ,
35.Nm bsddialog_form ,
36.Nm bsddialog_gauge ,
37.Nm bsddialog_geterror ,
38.Nm bsddialog_get_theme ,
39.Nm bsddialog_infobox ,
40.Nm bsddialog_init ,
41.Nm bsddialog_initconf ,
42.Nm bsddialog_menu ,
43.Nm bsddialog_mixedgauge ,
44.Nm bsddialog_mixedlist ,
45.Nm bsddialog_msgbox ,
46.Nm bsddialog_pause ,
47.Nm bsddialog_radiolist ,
48.Nm bsddialog_rangebox ,
49.Nm bsddialog_set_theme ,
50.Nm bsddialog_set_default_theme ,
51.Nm bsddialog_textbox ,
52.Nm bsddialog_timebox ,
53.Nm bsddialog_yesno
54.Nd TUI dialogs
55.Sh LIBRARY
56.Lb libbsddialog
57.Sh SYNOPSIS
58.In bsddialog.h
59.Ft int
60.Fn bsddialog_backtitle "struct bsddialog_conf *conf" "const char *backtitle"
61.Ft int
62.Fo bsddialog_checklist
63.Fa "struct bsddialog_conf *conf"
64.Fa "const char *text"
65.Fa "int rows"
66.Fa "int cols"
67.Fa "unsigned int menurows"
68.Fa "unsigned int nitems"
69.Fa "struct bsddialog_menuitem *items"
70.Fa "int *focusitem"
71.Fc
72.Ft int
73.Fn bsddialog_clearterminal "void"
74.Ft int
75.Fo bsddialog_datebox"
76.Fa "struct bsddialog_conf *conf"
77.Fa "const char *text"
78.Fa "int rows"
79.Fa "int cols"
80.Fa "unsigned int *yy"
81.Fa "unsigned int *mm"
82.Fa "unsigned int *dd"
83.Fc
84.Ft int
85.Fn bsddialog_end "void"
86.Ft int
87.Fo bsddialog_form
88.Fa "struct bsddialog_conf *conf"
89.Fa "const char *text"
90.Fa "int rows"
91.Fa "int cols"
92.Fa "unsigned int formrows"
93.Fa "unsigned int nitems"
94.Fa "struct bsddialog_formitem *items"
95.Fc
96.Ft int
97.Fo bsddialog_gauge
98.Fa "struct bsddialog_conf *conf"
99.Fa "const char *text"
100.Fa "int rows"
101.Fa "int cols"
102.Fa "unsigned int perc"
103.Fa "int fd"
104.Fa "const char *sep"
105.Fc
106.Ft const char *
107.Fn bsddialog_geterror "void"
108.Ft int
109.Fo bsddialog_infobox
110.Fa "struct bsddialog_conf *conf"
111.Fa "const char *text"
112.Fa "int rows"
113.Fa "int cols"
114.Fc
115.Ft int
116.Fn bsddialog_init "void"
117.Ft int
118.Fn bsddialog_initconf "struct bsddialog_conf *conf"
119.Ft int
120.Fo bsddialog_menu
121.Fa "struct bsddialog_conf *conf"
122.Fa "const char *text"
123.Fa "int rows"
124.Fa "int cols"
125.Fa "unsigned int menurows"
126.Fa "unsigned int nitems"
127.Fa "struct bsddialog_menuitem *items"
128.Fa "int *focusitem"
129.Fc
130.Ft int
131.Fo bsddialog_mixedgauge
132.Fa "struct bsddialog_conf *conf"
133.Fa "const char *text"
134.Fa "int rows"
135.Fa "int cols"
136.Fa "unsigned int mainperc"
137.Fa "unsigned int nminibars"
138.Fa "char **minilabels"
139.Fa "int *minipercs"
140.Fc
141.Ft int
142.Fo bsddialog_mixedlist
143.Fa "struct bsddialog_conf *conf"
144.Fa "const char *text"
145.Fa "int rows"
146.Fa "int cols"
147.Fa "unsigned int menurows"
148.Fa "unsigned int ngroups"
149.Fa "struct bsddialog_menugroup *groups"
150.Fa "int *focuslist"
151.Fa "int *focusitem"
152.Fc
153.Ft int
154.Fo bsddialog_msgbox
155.Fa "struct bsddialog_conf *conf"
156.Fa "const char *text"
157.Fa "int rows"
158.Fa "int cols"
159.Fc
160.Ft int
161.Fo bsddialog_pause
162.Fa "struct bsddialog_conf *conf"
163.Fa "const char *text"
164.Fa "int rows"
165.Fa "int cols"
166.Fa "unsigned int seconds"
167.Fc
168.Ft int
169.Fo bsddialog_radiolist
170.Fa "struct bsddialog_conf *conf"
171.Fa "const char *text"
172.Fa "int rows"
173.Fa "int cols"
174.Fa "unsigned int menurows"
175.Fa "unsigned int nitems"
176.Fa "struct bsddialog_menuitem *items"
177.Fa "int *focusitem"
178.Fc
179.Ft int
180.Fo bsddialog_rangebox
181.Fa "struct bsddialog_conf *conf"
182.Fa "const char *text"
183.Fa "int rows"
184.Fa "int cols"
185.Fa "int min"
186.Fa "int max"
187.Fa "int *value"
188.Fc
189.Ft int
190.Fo bsddialog_textbox
191.Fa "struct bsddialog_conf *conf"
192.Fa "const char *file"
193.Fa "int rows"
194.Fa "int cols"
195.Fc
196.Ft int
197.Fo bsddialog_timebox
198.Fa "struct bsddialog_conf *conf"
199.Fa "const char *text"
200.Fa "int rows"
201.Fa "int cols"
202.Fa "unsigned int *hh"
203.Fa "unsigned int *mm"
204.Fa "unsigned int *ss"
205.Fc
206.Ft int
207.Fo bsddialog_yesno
208.Fa "struct bsddialog_conf *conf"
209.Fa "const char *text"
210.Fa "int rows"
211.Fa "int cols"
212.Fc
213.In bsddialog_theme.h
214.Ft int
215.Fo bsddialog_color
216.Fa "enum bsddialog_color foreground"
217.Fa "enum bsddialog_color background"
218.Fa "unsigned int flags"
219.Fc
220.Ft int
221.Fn bsddialog_get_theme "struct bsddialog_theme *theme"
222.Ft int
223.Fn bsddialog_set_default_theme "enum bsddialog_default_theme theme"
224.Ft int
225.Fn bsddialog_set_theme "struct bsddialog_theme *theme"
226.Sh DESCRIPTION
227The
228.Nm bsddialog
229library provides an API to build Text User Interface dialogs and widgets: to
230display messages, to get input and to inform about a computation status.
231.Pp
232.Fn bsddialog_init
233initializes the library, the only functions that can be called before is
234.Fn bsddialog_initconf
235described later.
236After the initialization the input and output should be handled via the library
237API.
238.Fn bsddialog_end
239restores the screen like before
240.Fn bsddialog_init ,
241then it is not possible to use the library functions.
242.Pp
243.Fn bsddialog_error
244returns a string to describe the last error, it should be called after a
245.Dv BSDDIALOG_ERROR
246returned value.
247.Fn bsddialog_clearterminal
248clears the screen.
249.Fn bsddialog_backtitle
250prints
251.Fa backtitle
252on the top of the screen, it is possible to set
253.Fa conf.ascii_lines
254and
255.Fa conf.no_lines ;
256.Fa conf
257is described later.
258.Pp
259Each
260.Fa char*
261argument has to be a well terminated string, can be empty
262.Pq Dq
263but not
264.Dv NULL .
265.Ss Dialogs
266The dialogs have common arguments.
267.Fa text
268is a string printed inside the dialog.
269.Fa rows
270and
271.Fa cols
272are height and width, their value can be between 2 and the screen size,
273.Dv BSDDIALOG_AUTOSIZE
274or
275.Dv BSDDIALOG_FULLSCREEN .
276.Fa conf
277is a struct to customize the dialog, it does not set global properties to the
278library.
279.Pp
280.Bd -literal -offset indent -compact
281struct bsddialog_conf {
282	bool ascii_lines;
283	unsigned int auto_minheight;
284	unsigned int auto_minwidth;
285	const char *bottomtitle;
286	bool clear;
287	int *get_height;
288	int *get_width;
289	bool no_lines;
290	bool shadow;
291	unsigned int sleep;
292	const char *title;
293	int y;
294	int x;
295	struct {
296		bool enable_esc;
297		const char *f1_file;
298		const char *f1_message;
299	} key;
300	struct {
301		bool highlight;
302		unsigned int tablen;
303	} text;
304	struct {
305		bool align_left;
306		bool no_desc;
307		bool no_name;
308		bool on_without_ok;
309		bool shortcut_buttons;
310	} menu;
311	struct {
312		bool enable_wchar;
313		int  securech;
314		bool value_without_ok;
315	} form;
316	struct {
317		bool without_ok;
318		const char *ok_label;
319		bool with_extra;
320		const char *extra_label;
321		bool without_cancel;
322		const char *cancel_label;
323		bool default_cancel;
324		bool with_help;
325		const char *help_label;
326		const char *generic1_label;
327		const char *generic2_label;
328		const char *default_label;
329	} button;
330};
331.Ed
332.Pp
333.Bl -column -compact
334.It Fa conf.ascii_lines
335ascii characters to draw lines, default wide characters.
336.It Fa conf.auto_minheight
337minimum height if
338.Fa rows
339is
340.Dv BSDDIALOG_AUTOSIZE .
341.It Fa conf.auto_minwidth
342minimum width if
343.Fa cols
344is
345.Dv BSDDIALOG_AUTOSIZE .
346.It Fa conf.bottomtitle
347subtitle at the dialog bottom side.
348.It Fa conf.clear
349hide the dialog at exit.
350.It Fa conf.get_height
351if not
352.Dv NULL
353is set like the dialog height.
354.It Fa conf.get_width
355if not
356.Dv NULL
357is set like the dialog width.
358.It Fa conf.no_lines
359not draw lines.
360.It Fa conf.shadow
361draw shadow.
362.It Fa conf.sleep
363wait before to return, the value is in seconds.
364.It Fa conf.title
365title at the top dialog side.
366.It Fa conf.y
367vertical position, 0 is top screen size, can be
368.Dv BSDDIALOG_CENTER .
369.It Fa conf.x
370horizontal position, 0 is left screen side, can be
371.Dv BSDDIALOG_CENTER .
372.El
373.Pp
374.Bl -column -compact
375.It Fa conf.key.enable_esc
376enables
377.Dv ESC
378key to close the dialog.
379.It Fa conf.key.f1_file
380file to open if F1 is pressed.
381.It Fa conf.key.f1_message
382message to display if F1 is pressed.
383.El
384.Pp
385.Fa conf.text.highlight
386enables highlights for
387.Fa text ,
388properly the following sequences are considered escapes:
389.Bl -column -compact
390.It Dq \eZ0
391black.
392.It Dq \eZ1
393red.
394.It Dq \eZ2
395green.
396.It Dq \eZ3
397yellow.
398.It Dq \eZ4
399blue.
400.It Dq \eZ5
401magenta.
402.It Dq \eZ6
403cyan.
404.It Dq \eZ7
405white.
406.It Dq \eZr
407reverse colors between foreground and background.
408.It Dq \eZR
409disable reverse.
410.It Dq \eZb
411bold.
412.It Dq \eZB
413disable bold.
414.It Dq \eZu
415underline.
416.It Dq \eZU
417disable underline.
418.It Dq \eZn
419disable each customization.
420.El
421.Fa conf.text.tablen
422tab length.
423.Pp
424.Bl -column -compact
425.It Fa conf.button.without_ok
426disable OK button.
427.It Fa conf.button.ok_label
428set label for OK button.
429.It Fa conf.button.with_extra
430add Extra button.
431.It Fa conf.button.extra_label
432set a label for Extra button.
433.It Fa conf.button.without_cancel
434disable Cancel button.
435.It Fa conf.button.cancel_label
436sets a label for Cancel button.
437.It Fa conf.button.default_cancel
438on startup focus on the Cancel button.
439.It Fa conf.button.with_help
440add Help button.
441.It Fa conf.button.help_label
442set a label for Help button.
443.It Fa conf.button.generic1_label
444add a button with the specified label.
445.It Fa conf.button.generic2_label
446add a button with the specified label.
447.It Fa conf.button.default_label
448focus on the button with the specified label.
449.El
450.Pp
451.Fn bsddialog_initconf
452initializes
453.Fa conf
454disabling each property, except
455.Fa conf.shadow
456to true,
457.Fa conf.y
458and
459.Fa conf.x
460to
461.Dv BSDDIALOG_CENTER .
462.Pp
463.Fn bsddialog_infobox
464builds a dialog without buttons and returns instantly.
465.Fn bsddialog_msgbox
466builds a dialog with OK button.
467.Fn bsddialog_yesno
468provides a dialog for a
469.Dq Yes-No Question ,
470the labels on buttons are Yes and No.
471.Pp
472.Fn bsddialog_pause
473builds a dialog waiting until the timeout in
474.Fa seconds
475expires or a button is pressed.
476.Pp
477.Fn bsddialog_datebox
478builds a dialog to select a date,
479.Fa yy ,
480.Fa mm ,
481and
482.Fa dd
483are default values on startup, selected date at exit.
484.Fn bsddialog_timebox
485builds a dialog to choose a time,
486.Fa hh ,
487.Fa mm ,
488and
489.Fa ss
490are default values on startup, selected time at exit.
491.Pp
492.Fn bsddialog_checklist ,
493.Fn bsddialog_menu
494and
495.Fn bsddialog_radiolist
496build dialogs to select some item from a list via the SPACE key, an item is
497defined like:
498.Pp
499.Bd -literal -offset indent -compact
500struct bsddialog_menuitem {
501	const char *prefix;
502	bool on;
503	unsigned int depth;
504	const char *name;
505	const char *desc;
506	const char *bottomdesc;
507};
508.Ed
509.Pp
510.Fa prefix ,
511.Fa name
512and
513.Fa desc
514are strings to describe the item and are printed on its row,
515.Fa bottomdesc
516is printed on the bottom side of the screen,
517.Fa depth
518is a margin between the
519.Fa prefix
520and
521.Fa name
522useful to implement a
523.Dq treeview,
524.Fa on
525is set to
526.Dv true
527if the item is selected,
528.Dv false
529otherwise.
530.Fa items
531is an array of items of
532.Fa nitem
533elements,
534.Fa menurows
535specifies the graphical fixed height of the list, if
536.Fa cols
537is set to
538.Dv BSDDIALOG_AUTOSIZE
539.Fa menurows
540specifies a maximum value.
541Finally, if not
542.Dv NULL ,
543.Fa focusitem
544specifies the default item on startup and the last focused item at exit, could
545be a negative value if no item is focused.
546.Pp
547.Fn bsddialog_mixedlist
548builds a dialog with collections of checklists, radiolists and separators.
549A collection is a set defined like:
550.Pp
551.Bd -literal -offset indent -compact
552enum bsddialog_grouptype {
553	BSDDIALOG_CHECKLIST,
554	BSDDIALOG_RADIOLIST,
555	BSDDIALOG_SEPARATOR,
556};
557
558struct bsddialog_menugroup {
559	enum bsddialog_grouptype type;
560	unsigned int nitems;
561	struct bsddialog_menuitem *items;
562};
563.Ed
564.Pp
565.Fa groups
566is an array of sets of
567.Fa ngroups
568elements.
569.Fa menurows
570is the graphical height size for the list.
571If not
572.Dv NULL ,
573.Fa focuslist
574and
575.Fa focusitem
576specify the default item on startup and the last focused item at exit, could be
577a negative value if no item is focused.
578.Pp
579.Fn bsddialog_checklist ,
580.Fn bsddialog_menu ,
581.Fn bsddialog_mixedlist
582and
583.Fn bsddialog_radiolist
584can be costomizated by:
585.Bl -column -compact
586.It Fa conf.menu.align_left
587aligns items to left, default center.
588.It Fa conf.menu.no_desc
589hide description.
590.It Fa conf.menu.no_name
591hide names.
592.It Fa conf.menu.on_without_ok
593set items
594.Fa on
595also if the OK button is not pressed.
596.It Fa conf.menu.shortcut_buttons
597enable shortcut keys on buttons, default on items.
598.El
599.Pp
600.Fn bsddialog_form
601builds a dialog to display a list of items to get strings in input, an item is
602defined like:
603.Pp
604.Bd -literal -offset indent -compact
605struct bsddialog_formitem {
606	const char *label;
607	unsigned int ylabel;
608	unsigned int xlabel;
609
610	const char *init;
611	unsigned int yfield;
612	unsigned int xfield;
613	unsigned int fieldlen;
614	unsigned int maxvaluelen;
615	char *value;
616
617	unsigned int flags;
618
619	const char *bottomdesc;
620};
621.Ed
622.Pp
623.Fa label
624describes the request, it is printed at the position
625.Fa ylabel
626and
627.Fa xlabel .
628The field for the input is at the position
629.Fa yfield
630and
631.Fa xfield ,
632.Fa fieldlen
633is its graphical width, while
634.Fa maxvalelen
635is the maximum length of the input string,
636.Fa init
637is the default value.
638If the OK button is pressed
639.Fa value
640is the allocated memory with the current field string.
641.Fa flags
642is an OR value to set the
643.Dv BSDDIALOG_FIELDHIDDEN
644and
645.Dv BSDDIALOG_FIELDREADONLY
646flags for the field.
647.Fa bottomdesc
648is printed on the bottom side of the screen if the item is focused.
649.Fa items
650is an array of items of
651.Fa nitems
652elements,
653.Fa formrows
654specifies the graphical fixed height for the items list;
655.Fa ylabel
656and
657.Fa yfield
658have to be between 1 and
659.Fa formrows .
660.Pp
661.Fn bsddialog_form
662can be customized by:
663.Bl -column -compact
664.It Fa conf.form.enable_wchar
665enables characters greater than 127 in the field,
666.Fa value
667is a pointer to allocated memory for a
668.Em wchar_t
669string.
670.It Fa conf.form.securech
671charachter to hide the input
672with
673.Dv BSDDIALOG_FIELDHIDDEN .
674.It Fa conf.form.value_without_ok
675allocate memory and set
676.Fa value
677also if the OK button is not pressed.
678.El
679.Pp
680.Fn bsddialog_gauge
681builds a dialog with a bar to shows
682.Fa perc ,
683if the file descriptor
684.Fa fd
685is greater or equal to 0 the dialog waits to read
686.Fa separator
687from it, then the first string replaces
688.Fa perc
689and the following strings replace
690.Fa text
691until the next
692.Fa separator ,
693the loop ends reading
694.Dv EOF .
695.Pp
696.Fn bsddialog_mixedgauge
697draws a main bar with the
698.Fa mainperc
699percentage and
700.Fa nminibars
701each one with a
702.Fa minilabel
703and a
704.Fa miniperc
705with a value between 0 and 100 or
706.Dv BSDDIALOG_MG_SUCCEEDED ,
707.Dv BSDDIALOG_MG_FAILED ,
708.Dv BSDDIALOG_MG_PASSED ,
709.Dv BSDDIALOG_MG_COMPLETED ,
710.Dv BSDDIALOG_MG_CHECKED ,
711.Dv BSDDIALOG_MG_DONE ,
712.Dv BSDDIALOG_MG_SKIPPED ,
713.Dv BSDDIALOG_MG_INPROGRESS ,
714.Dv BSDDIALOG_MG_BLANK ,
715.Dv BSDDIALOG_MG_NA
716or
717.Dv BSDDIALOG_MG_PENDING
718to print a descriptive string.
719.Pp
720.Fn bsddialog_rangebox
721to select a value between
722.Fa min
723and
724.Fa max .
725.Fa value
726is the default value on startup and the selected value at exit.
727The current value is printed inside a bar, the keys UP, DOWN, HOME, END, PAGEUP
728and PAGEDOWN can change it.
729.Pp
730.Fn bsddialog_textbox
731opens and prints
732.Fa file
733in a dialog, the UP, DOWN, HOME, END, PAGEUP and PAGEDOWN keys are availble to
734navigate the file.
735OK button is renamed EXIT.
736.Ss Theme
737The graphical properties are global to the library, they are represented by
738.Fa struct bsddialog_theme
739and can be customized at runtime via the
740.In bsddialog_theme.h
741API.
742.Pp
743.Bd -literal -offset indent -compact
744struct bsddialog_theme {
745	struct {
746		int color;
747	} screen;
748	struct {
749		int color;
750		unsigned int h;
751		unsigned int w;
752	} shadow;
753	struct {
754		int  color;
755		bool delimtitle;
756		int  titlecolor;
757		int  lineraisecolor;
758		int  linelowercolor;
759		int  bottomtitlecolor;
760		int  arrowcolor;
761	} dialog;
762	struct {
763		int f_selectorcolor;
764		int selectorcolor;
765		int f_namecolor;
766		int namecolor;
767		int f_desccolor;
768		int desccolor;
769		int namesepcolor;
770		int descsepcolor;
771		int f_shortcutcolor;
772		int shortcutcolor;
773	} menu;
774	struct {
775		int f_fieldcolor;
776		int fieldcolor;
777		int readonlycolor;
778	} form;
779	struct {
780		int f_color;
781		int color;
782	} bar;
783	struct {
784		unsigned int hmargin;
785		int leftdelim;
786		int rightdelim;
787		int delimcolor;
788		int f_delimcolor;
789		int color;
790		int f_color;
791		int shortcutcolor;
792		int f_shortcutcolor;
793	} button;
794};
795.Ed
796.Pp
797A member with the
798.Dq f_
799prefix refers to an element with focus.
800.Pp
801.Fn bsddialog_get_theme
802sets
803.Fa theme
804like the current theme.
805.Pp
806A color can be set by the value returned by
807.Fn bsddialog_color ,
808Possible values for
809.Fa background
810and
811.Fa foreground
812are:
813.Dv BSDDIALOG_BLACK ,
814.Dv BSDDIALOG_RED ,
815.Dv BSDDIALOG_GREEN ,
816.Dv BSDDIALOG_YELLOW ,
817.Dv BSDDIALOG_BLUE ,
818.Dv BSDDIALOG_MAGENTA ,
819.Dv BSDDIALOG_CYAN ,
820and
821.Dv BSDDIALOG_WHITE ,
822.Fa flags
823specifies OR-flags, possible values:
824.Dv BSDDIALOG_BOLD ,
825.Dv BSDDIALOG_REVERSE
826and
827.Dv BSDDIALOG_UNDERLINE .
828.Pp
829.Fn bsddialog_set_theme
830sets
831.Fa theme
832like current theme, the changes takes effect only for dialogs built after the
833call.
834.Pp
835The library provides predefined themes:
836.Dv BSDDIALOG_THEME_BLACKWHITE ,
837.Dv BSDDIALOG_THEME_BSDDIALOG ,
838.Dv BSDDIALOG_THEME_FLAT
839and
840.Dv BSDDIALOG_THEME_DIALOG ,
841they can be set via
842.Fn bsddialog_set_default_theme .
843.Sh RETURN VALUES
844The functions return the value
845.Dv BSDDIALOG_ERROR
846if unsuccessful;
847otherwise, depending on the pressed button, the following values can be
848returned:
849.Dv BSDDIALOG_OK ,
850.Dv BSDDIALOG_CANCEL ,
851.Dv BSDDIALOG_HELP ,
852.Dv BSDDIALOG_EXTRA ,
853.Dv BSDDIALOG_GENERIC1
854or
855.Dv BSDDIALOG_GENERIC2 .
856.Dv BSDDIALOG_YES
857and
858.Dv BSDDIALOG_NO
859are aliases for
860.Dv BSDDIALOG_OK
861and
862.Dv BSDDIALOG_CANCEL ,
863respectively.
864.Pp
865The functions return
866.Dv BSDDIALOG_ESC
867if
868.Fa conf.key.enable_esc
869is enabled and the ESC key is pressed.
870.Pp
871.Fn bsddialog_pause
872returns
873.Dv BSDDIALOG_TIMEOUT
874if the timeout expires.
875.Sh EXAMPLES
876.Dq Yes-No Question
877Example:
878.Pp
879.Bd -literal -offset indent -compact
880int output;
881struct bsddialog_conf conf;
882
883if (bsddialog_init() == BSDDIALOG_ERROR)
884	return (1);
885
886bsddialog_initconf(&conf);
887conf.title = "yesno";
888output = bsddialog_yesno(&conf, "Example", 7, 25);
889
890bsddialog_end();
891
892switch (output) {
893case BSDDIALOG_YES:
894	printf("Yes\\n");
895	break;
896case BSDDIALOG_NO
897	printf("NO\\n");
898	break;
899case BSDDIALOG_ERROR:
900	printf("Error: %s\\n", bsddialog_geterror());
901}
902.Ed
903.Pp
904Theme Example:
905.Pp
906.Bd -literal -offset indent -compact
907struct bsddialog_conf conf;
908struct bsddialog_theme theme;
909
910bsddialog_init();
911
912bsddialog_initconf(&conf);
913bsddialog_msgbox(&conf, "Default theme", 7, 25);
914
915bsddialog_get_theme(&theme);
916theme.screen.color = bsddialog_color(BSDDIALOG_RED, BSDDIALOG_GREEN,
917    BSDDIALOG_BOLD);
918bsddialog_set_theme(&theme);
919bsddialog_backtitle(&conf, "Red foreground and Green background");
920bsddialog_msgbox(&conf, "Change screen color", 7, 25);
921
922bsddialog_set_default_theme(BSDDIALOG_THEME_BLACKWHITE);
923bsddialog_msgbox(&conf, "Black and White theme", 7, 25);
924
925bsddialog_end();
926.Ed
927.Pp
928Mixedlist Example:
929.Pp
930.Bd -literal -offset indent -compact
931unsigned int i, j;
932struct bsddialog_conf conf;
933struct bsddialog_menuitem item;
934struct bsddialog_menuitem check[2] = {
935    { "1", true,  0, "Name 1", "Desc 1", "Check Bottom Desc 1" },
936    { "2", false, 0, "Name 2", "Desc 2", "Check Bottom Desc 2" }
937};
938struct bsddialog_menuitem sep[1] = {
939    { "3", true, 0, "Radiolist", "(desc)", "" }
940};
941struct bsddialog_menuitem radio[5] = {
942    { "4", true,  0, "Name 1", "Desc 1", "Radio Bottom Desc 1" },
943    { "5", false, 0, "Name 2", "Desc 2", "Radio Bottom Desc 2" }
944};
945struct bsddialog_menugroup group[3] = {
946    { BSDDIALOG_CHECKLIST, 2, check },
947    { BSDDIALOG_SEPARATOR, 1, sep   },
948    { BSDDIALOG_RADIOLIST, 2, radio }
949};
950
951bsddialog_init();
952bsddialog_initconf(&conf);
953bsddialog_mixedlist(&conf, "Example", 20, 30, 11, 3, group, NULL,
954    NULL);
955bsddialog_end();
956
957for (i = 0; i < 3; i++) {
958	for (j = 0; j < group[i].nitems; j++) {
959		item = group[i].items[j];
960		switch (item.type) {
961		case BSDDIALOG_SEPARATOR:
962			printf("---- %s ----\\n", item.name);
963			break;
964		case BSDDIALOG_RADIOLIST:
965			printf(" (%c) %s\\n",
966			    item.on ? '*' : ' ', item.name);
967			break;
968		case BSDDIALOG_CHECKLIST:
969			printf(" [%c] %s\\n",
970			    item.on ? 'X' : ' ', item.name);
971			break;
972		}
973	}
974}
975.Ed
976.Sh SEE ALSO
977.Xr bsddialog 1 ,
978.Xr curses 3 ,
979.Xr ncurses 3
980.Sh HISTORY
981The
982.Nm bsddialog
983library first appeared in
984.Fx 14.0 .
985.Sh AUTHORS
986.Nm bsddialog
987was written by
988.An Alfonso Sabato Siciliano Aq Mt alf.siciliano@gmail.com .
989.Sh BUGS
990.Fn bsddialog_form
991does not resize the dialog after a terminal resize and does not provide
992scrolling for items.