2 .\" Copyright (c) 2021-2022 Alfonso Sabato Siciliano
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
29 .Nm bsddialog_backtitle ,
30 .Nm bsddialog_clearterminal ,
32 .Nm bsddialog_color_attrs ,
33 .Nm bsddialog_checklist ,
34 .Nm bsddialog_datebox ,
38 .Nm bsddialog_geterror ,
39 .Nm bsddialog_get_theme ,
40 .Nm bsddialog_hascolors ,
41 .Nm bsddialog_infobox ,
43 .Nm bsddialog_init_notheme ,
44 .Nm bsddialog_initconf ,
46 .Nm bsddialog_mixedgauge ,
47 .Nm bsddialog_mixedlist ,
48 .Nm bsddialog_msgbox ,
50 .Nm bsddialog_radiolist ,
51 .Nm bsddialog_rangebox ,
52 .Nm bsddialog_set_theme ,
53 .Nm bsddialog_set_default_theme ,
54 .Nm bsddialog_textbox ,
55 .Nm bsddialog_timebox ,
63 .Fn bsddialog_backtitle "struct bsddialog_conf *conf" "const char *backtitle"
65 .Fo bsddialog_checklist
66 .Fa "struct bsddialog_conf *conf"
67 .Fa "const char *text"
70 .Fa "unsigned int menurows"
71 .Fa "unsigned int nitems"
72 .Fa "struct bsddialog_menuitem *items"
76 .Fn bsddialog_clearterminal "void"
78 .Fo bsddialog_datebox"
79 .Fa "struct bsddialog_conf *conf"
80 .Fa "const char *text"
83 .Fa "unsigned int *yy"
84 .Fa "unsigned int *mm"
85 .Fa "unsigned int *dd"
88 .Fn bsddialog_end "void"
91 .Fa "struct bsddialog_conf *conf"
92 .Fa "const char *text"
95 .Fa "unsigned int formrows"
96 .Fa "unsigned int nitems"
97 .Fa "struct bsddialog_formitem *items"
101 .Fa "struct bsddialog_conf *conf"
102 .Fa "const char *text"
105 .Fa "unsigned int perc"
107 .Fa "const char *sep"
110 .Fn bsddialog_geterror "void"
112 .Fo bsddialog_infobox
113 .Fa "struct bsddialog_conf *conf"
114 .Fa "const char *text"
119 .Fn bsddialog_init "void"
121 .Fn bsddialog_init_notheme "void"
123 .Fn bsddialog_initconf "struct bsddialog_conf *conf"
126 .Fa "struct bsddialog_conf *conf"
127 .Fa "const char *text"
130 .Fa "unsigned int menurows"
131 .Fa "unsigned int nitems"
132 .Fa "struct bsddialog_menuitem *items"
136 .Fo bsddialog_mixedgauge
137 .Fa "struct bsddialog_conf *conf"
138 .Fa "const char *text"
141 .Fa "unsigned int mainperc"
142 .Fa "unsigned int nminibars"
143 .Fa "char **minilabels"
147 .Fo bsddialog_mixedlist
148 .Fa "struct bsddialog_conf *conf"
149 .Fa "const char *text"
152 .Fa "unsigned int menurows"
153 .Fa "unsigned int ngroups"
154 .Fa "struct bsddialog_menugroup *groups"
160 .Fa "struct bsddialog_conf *conf"
161 .Fa "const char *text"
167 .Fa "struct bsddialog_conf *conf"
168 .Fa "const char *text"
171 .Fa "unsigned int seconds"
174 .Fo bsddialog_radiolist
175 .Fa "struct bsddialog_conf *conf"
176 .Fa "const char *text"
179 .Fa "unsigned int menurows"
180 .Fa "unsigned int nitems"
181 .Fa "struct bsddialog_menuitem *items"
185 .Fo bsddialog_rangebox
186 .Fa "struct bsddialog_conf *conf"
187 .Fa "const char *text"
195 .Fo bsddialog_textbox
196 .Fa "struct bsddialog_conf *conf"
197 .Fa "const char *file"
202 .Fo bsddialog_timebox
203 .Fa "struct bsddialog_conf *conf"
204 .Fa "const char *text"
207 .Fa "unsigned int *hh"
208 .Fa "unsigned int *mm"
209 .Fa "unsigned int *ss"
213 .Fa "struct bsddialog_conf *conf"
214 .Fa "const char *text"
218 .In bsddialog_theme.h
221 .Fa "enum bsddialog_color foreground"
222 .Fa "enum bsddialog_color background"
223 .Fa "unsigned int flags"
226 .Fo bsddialog_color_attrs
228 .Fa "enum bsddialog_color *foreground"
229 .Fa "enum bsddialog_color *background"
230 .Fa "unsigned int *flags"
233 .Fn bsddialog_get_theme "struct bsddialog_theme *theme"
235 .Fn bsddialog_hascolors "void"
237 .Fn bsddialog_set_default_theme "enum bsddialog_default_theme theme"
239 .Fn bsddialog_set_theme "struct bsddialog_theme *theme"
243 library provides an API to build Text User Interface dialogs and widgets: to
244 display messages, to get input and to inform about a computation status.
247 initializes the library, the only functions that can be called before is
248 .Fn bsddialog_initconf
250 After the initialization the input and output should be handled via the library
253 restores the screen like before
255 then it is not possible to use the library functions.
256 .Fn bsddialog_init_notheme
259 except it does not set the default graphical theme; see
261 subsection to set a theme explicitly.
264 returns a string to describe the last error, it should be called after a
267 .Fn bsddialog_clearterminal
269 .Fn bsddialog_backtitle
272 on the top of the screen, it is possible to set
281 argument has to be a well terminated string, it can be a multibyte character
282 string depending on current locale, see
285 The dialogs have common arguments.
287 is a string printed inside the dialog.
291 are height and width, their value can be between 2 and the screen size,
292 .Dv BSDDIALOG_AUTOSIZE
294 .Dv BSDDIALOG_FULLSCREEN .
296 is a struct to customize the dialog, it does not set global properties to the
299 .Bd -literal -offset indent -compact
300 struct bsddialog_conf {
302 unsigned int auto_minheight;
303 unsigned int auto_minwidth;
304 unsigned int auto_topmargin;
305 unsigned int auto_downmargin;
306 const char *bottomtitle;
319 const char *f1_message;
322 unsigned int cols_per_row;
331 bool shortcut_buttons;
337 bool value_without_ok;
342 const char *ok_label;
344 const char *extra_label;
346 const char *cancel_label;
349 const char *help_label;
350 const char *generic1_label;
351 const char *generic2_label;
352 const char *default_label;
358 .It Fa conf.ascii_lines
359 ascii characters to draw lines, default wide characters.
360 .It Fa conf.auto_minheight
364 .Dv BSDDIALOG_AUTOSIZE .
365 .It Fa conf.auto_minwidth
369 .Dv BSDDIALOG_AUTOSIZE .
370 .It Fa conf.auto_topmargin
374 .Dv BSDDIALOG_AUTOSIZE
376 .Dv BSDDIALOG_FULLSCREEN ,
379 .Dv BSDDIALOG_CENTER .
380 .It Fa conf.auto_downmargin
384 .Dv BSDDIALOG_AUTOSIZE
386 .Dv BSDDIALOG_FULLSCREEN .
387 .It Fa conf.bottomtitle
388 subtitle at the dialog bottom side.
390 hide the dialog at exit.
391 .It Fa conf.get_height
394 is set like the dialog height.
395 .It Fa conf.get_width
398 is set like the dialog width.
404 wait before to return, the value is in seconds.
406 title at the top dialog side.
408 vertical position, 0 is top screen size, can be
409 .Dv BSDDIALOG_CENTER .
411 horizontal position, 0 is left screen side, can be
412 .Dv BSDDIALOG_CENTER .
416 .It Fa conf.key.enable_esc
419 key to close the dialog.
420 .It Fa conf.key.f1_file
421 file to open if F1 is pressed.
422 .It Fa conf.key.f1_message
423 message to display if F1 is pressed.
427 .It Fa conf.text.cols_per_row
428 Try to set the number of columns for a row of
430 with autosizing; default
432 .It Fa conf.text.highlight
433 enables highlights for
435 properly the following sequences are considered escapes:
453 reverse foreground and background.
465 disable each customization.
466 .It Fa conf.text.tablen
470 .Fn bsddialog_textbox
475 .It Fa conf.button.always_active
476 buttons always active, avoidind focus switch between buttons and input fields or
479 .Fn bsddialog_datebox
481 .Fn bsddialog_timebox .
482 .It Fa conf.button.without_ok
484 .It Fa conf.button.ok_label
485 set label for OK button.
486 .It Fa conf.button.with_extra
488 .It Fa conf.button.extra_label
489 set a label for Extra button.
490 .It Fa conf.button.without_cancel
491 disable Cancel button.
492 .It Fa conf.button.cancel_label
493 sets a label for Cancel button.
494 .It Fa conf.button.default_cancel
495 on startup focus on the Cancel button.
496 .It Fa conf.button.with_help
498 .It Fa conf.button.help_label
499 set a label for Help button.
500 .It Fa conf.button.generic1_label
501 add a button with the specified label.
502 .It Fa conf.button.generic2_label
503 add a button with the specified label.
504 .It Fa conf.button.default_label
505 focus on the button with the specified label.
508 .Fn bsddialog_initconf
511 disabling each property, except
518 .Dv BSDDIALOG_CENTER .
520 .Fn bsddialog_infobox
521 builds a dialog without buttons and returns instantly.
523 builds a dialog with OK button.
525 provides a dialog for a
526 .Dq Yes-No Question ,
527 the labels on buttons are Yes and No.
530 builds a dialog waiting until the timeout in
532 expires or a button is pressed.
534 .Fn bsddialog_datebox
535 builds a dialog to select a date,
540 are default values on startup, selected date at exit.
541 .Fn bsddialog_timebox
542 builds a dialog to choose a time,
547 are default values on startup, selected time at exit.
549 .Fn bsddialog_checklist ,
552 .Fn bsddialog_radiolist
553 build dialogs to select some item from a list via the SPACE key, an item is
556 .Bd -literal -offset indent -compact
557 struct bsddialog_menuitem {
563 const char *bottomdesc;
571 are strings to describe the item and are printed on its row,
573 is printed on the bottom side of the screen,
575 is a margin between the
579 useful to implement a
584 if the item is selected,
588 is an array of items of
592 specifies the graphical fixed height of the list, if
595 .Dv BSDDIALOG_AUTOSIZE
597 specifies a maximum value.
601 specifies the default item on startup and the last focused item at exit, could
602 be a negative value if no item is focused.
604 .Fn bsddialog_mixedlist
605 builds a dialog with collections of checklists, radiolists and separators.
606 A collection is a set defined like:
608 .Bd -literal -offset indent -compact
609 enum bsddialog_grouptype {
615 struct bsddialog_menugroup {
616 enum bsddialog_grouptype type;
618 struct bsddialog_menuitem *items;
623 is an array of sets of
627 is the graphical height size for the list.
633 specify the default item on startup and the last focused item at exit, could be
634 a negative value if no item is focused.
636 .Fn bsddialog_checklist ,
638 .Fn bsddialog_mixedlist
640 .Fn bsddialog_radiolist
641 can be costomizated by:
643 .It Fa conf.menu.align_left
644 aligns items to left, default center.
645 .It Fa conf.menu.no_desc
647 .It Fa conf.menu.no_name
649 .It Fa conf.menu.on_without_ok
652 also if the OK button is not pressed.
653 .It Fa conf.menu.shortcut_buttons
654 enable shortcut keys on buttons, default on items.
658 builds a dialog to display an array of
662 elements to get strings in input.
664 specifies the graphical height for the box around the items,
667 An item is defined like:
669 .Bd -literal -offset indent -compact
670 struct bsddialog_formitem {
678 unsigned int fieldlen;
679 unsigned int maxvaluelen;
684 const char *bottomdesc;
689 is a string to describe the request, it is printed at the position
693 The field for the input is at the position
698 is its graphical width, while
700 is the maximum number of characters of the input string.
702 is the default field value.
703 If the OK button is pressed
705 is the allocated memory with the current field string, its size depends on
708 is an OR value to set the
709 .Dv BSDDIALOG_FIELDHIDDEN ,
710 .Dv BSDDIALOG_FIELDREADONLY ,
711 .Dv BSDDIALOG_FIELDNOCOLOR ,
712 .Dv BSDDIALOG_FIELDCURSOREND ,
713 .Dv BSDDIALOG_FIELDEXTEND
715 .Dv BSDDIALOG_FIELDSINGLEBYTE .
718 is printed on the bottom side of the screen if the item is focused.
721 can be customized by:
723 .It Fa conf.form.securech
724 charachter to hide the input with
725 .Dv BSDDIALOG_FIELDHIDDEN .
726 .It Fa conf.form.securembch
727 multibyte charachter to hide the input with
728 .Dv BSDDIALOG_FIELDHIDDEN ,
729 .Fa conf.form.securech
731 .It Fa conf.form.value_wchar
737 .It Fa conf.form.value_without_ok
738 allocate memory and set
740 also if the OK button is not pressed.
744 builds a dialog with a bar to shows
746 if the file descriptor
748 is greater or equal to 0 the dialog waits to read
750 from it, then the first string replaces
752 and the following strings replace
756 the loop ends reading
759 .Fn bsddialog_mixedgauge
760 draws a main bar with the
768 with a value between 0 and 100 or
769 .Dv BSDDIALOG_MG_SUCCEEDED ,
770 .Dv BSDDIALOG_MG_FAILED ,
771 .Dv BSDDIALOG_MG_PASSED ,
772 .Dv BSDDIALOG_MG_COMPLETED ,
773 .Dv BSDDIALOG_MG_CHECKED ,
774 .Dv BSDDIALOG_MG_DONE ,
775 .Dv BSDDIALOG_MG_SKIPPED ,
776 .Dv BSDDIALOG_MG_INPROGRESS ,
777 .Dv BSDDIALOG_MG_BLANK ,
780 .Dv BSDDIALOG_MG_PENDING
781 to print a descriptive string.
783 .Fn bsddialog_rangebox
784 to select a value between
789 is the default value on startup and the selected value at exit.
790 The current value is printed inside a bar, the keys UP, DOWN, HOME, END, PAGEUP
791 and PAGEDOWN can change it.
793 .Fn bsddialog_textbox
796 in a dialog, the UP, DOWN, HOME, END, PAGEUP and PAGEDOWN keys are availble to
798 OK button is renamed EXIT.
800 The graphical properties are global to the library, they are represented by
801 .Fa struct bsddialog_theme
802 and can be customized at runtime via the
803 .In bsddialog_theme.h
806 .Bd -literal -offset indent -compact
807 struct bsddialog_theme {
822 int bottomtitlecolor;
849 unsigned int minmargin;
850 unsigned int maxmargin;
865 prefix refers to an element with focus.
867 .Fn bsddialog_get_theme
870 like the current theme.
872 A color can be set by the value returned by
873 .Fn bsddialog_color ,
879 .Dv BSDDIALOG_BLACK ,
881 .Dv BSDDIALOG_GREEN ,
882 .Dv BSDDIALOG_YELLOW ,
884 .Dv BSDDIALOG_MAGENTA ,
887 .Dv BSDDIALOG_WHITE ,
889 specifies OR-flags, possible values:
891 .Dv BSDDIALOG_REVERSE
893 .Dv BSDDIALOG_UNDERLINE .
894 .Fn bsddialog_color_attrs
895 gets the properties of a color.
897 .Fn bsddialog_set_theme
900 like current theme, the changes takes effect only for dialogs built after the
903 The library provides predefined themes:
904 .Dv BSDDIALOG_THEME_BLACKWHITE ,
905 .Dv BSDDIALOG_THEME_BSDDIALOG ,
906 .Dv BSDDIALOG_THEME_FLAT
908 .Dv BSDDIALOG_THEME_DIALOG ,
910 .Fn bsddialog_set_default_theme .
912 .Fn bsddialog_hascolors
915 if the terminal provides colors,
919 The functions return the value
922 otherwise, depending on the pressed button, the following values can be
925 .Dv BSDDIALOG_CANCEL ,
927 .Dv BSDDIALOG_EXTRA ,
928 .Dv BSDDIALOG_GENERIC1
930 .Dv BSDDIALOG_GENERIC2 .
937 .Dv BSDDIALOG_CANCEL ,
943 .Fa conf.key.enable_esc
944 is enabled and the ESC key is pressed.
948 .Dv BSDDIALOG_TIMEOUT
949 if the timeout expires.
954 .Bd -literal -offset indent -compact
956 struct bsddialog_conf conf;
958 if (bsddialog_init() == BSDDIALOG_ERROR)
961 bsddialog_initconf(&conf);
962 conf.title = "yesno";
963 output = bsddialog_yesno(&conf, "Example", 7, 25);
974 case BSDDIALOG_ERROR:
975 printf("Error: %s\\n", bsddialog_geterror());
981 .Bd -literal -offset indent -compact
982 struct bsddialog_conf conf;
983 struct bsddialog_theme theme;
987 bsddialog_initconf(&conf);
988 bsddialog_msgbox(&conf, "Default theme", 7, 25);
990 bsddialog_get_theme(&theme);
991 theme.screen.color = bsddialog_color(BSDDIALOG_RED, BSDDIALOG_GREEN,
993 bsddialog_set_theme(&theme);
994 bsddialog_backtitle(&conf, "Red foreground and Green background");
995 bsddialog_msgbox(&conf, "Change screen color", 7, 25);
997 bsddialog_set_default_theme(BSDDIALOG_THEME_BLACKWHITE);
998 bsddialog_msgbox(&conf, "Black and White theme", 7, 25);
1005 .Bd -literal -offset indent -compact
1007 struct bsddialog_conf conf;
1008 struct bsddialog_menuitem item;
1009 struct bsddialog_menuitem check[2] = {
1010 { "1", true, 0, "Name 1", "Desc 1", "Check Bottom Desc 1" },
1011 { "2", false, 0, "Name 2", "Desc 2", "Check Bottom Desc 2" }
1013 struct bsddialog_menuitem sep[1] = {
1014 { "3", true, 0, "Radiolist", "(desc)", "" }
1016 struct bsddialog_menuitem radio[5] = {
1017 { "4", true, 0, "Name 1", "Desc 1", "Radio Bottom Desc 1" },
1018 { "5", false, 0, "Name 2", "Desc 2", "Radio Bottom Desc 2" }
1020 struct bsddialog_menugroup group[3] = {
1021 { BSDDIALOG_CHECKLIST, 2, check },
1022 { BSDDIALOG_SEPARATOR, 1, sep },
1023 { BSDDIALOG_RADIOLIST, 2, radio }
1027 bsddialog_initconf(&conf);
1028 bsddialog_mixedlist(&conf, "Example", 20, 30, 11, 3, group, NULL,
1032 for (i = 0; i < 3; i++) {
1033 for (j = 0; j < group[i].nitems; j++) {
1034 item = group[i].items[j];
1035 switch (item.type) {
1036 case BSDDIALOG_SEPARATOR:
1037 printf("---- %s ----\\n", item.name);
1039 case BSDDIALOG_RADIOLIST:
1040 printf(" (%c) %s\\n",
1041 item.on ? '*' : ' ', item.name);
1043 case BSDDIALOG_CHECKLIST:
1044 printf(" [%c] %s\\n",
1045 item.on ? 'X' : ' ', item.name);
1057 library first appeared in
1062 .An Alfonso Sabato Siciliano Aq Mt asiciliano@FreeBSD.org .