2 .\" Copyright (c) 2021-2023 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_calendar ,
33 .Nm bsddialog_color_attrs ,
34 .Nm bsddialog_checklist ,
35 .Nm bsddialog_datebox ,
39 .Nm bsddialog_geterror ,
40 .Nm bsddialog_get_theme ,
41 .Nm bsddialog_hascolors ,
42 .Nm bsddialog_infobox ,
44 .Nm bsddialog_init_notheme ,
45 .Nm bsddialog_initconf ,
46 .Nm bsddialog_inmode ,
48 .Nm bsddialog_mixedgauge ,
49 .Nm bsddialog_mixedlist ,
50 .Nm bsddialog_msgbox ,
52 .Nm bsddialog_radiolist ,
53 .Nm bsddialog_rangebox ,
54 .Nm bsddialog_refresh ,
55 .Nm bsddialog_set_theme ,
56 .Nm bsddialog_set_default_theme ,
57 .Nm bsddialog_textbox ,
58 .Nm bsddialog_timebox ,
66 .Fn bsddialog_backtitle "struct bsddialog_conf *conf" "const char *backtitle"
68 .Fo bsddialog_calendar
69 .Fa "struct bsddialog_conf *conf"
70 .Fa "const char *text"
73 .Fa "unsigned int *year"
74 .Fa "unsigned int *month"
75 .Fa "unsigned int *day"
78 .Fo bsddialog_checklist
79 .Fa "struct bsddialog_conf *conf"
80 .Fa "const char *text"
83 .Fa "unsigned int menurows"
84 .Fa "unsigned int nitems"
85 .Fa "struct bsddialog_menuitem *items"
89 .Fn bsddialog_clear "unsigned int y"
92 .Fa "struct bsddialog_conf *conf"
93 .Fa "const char *text"
96 .Fa "unsigned int *year"
97 .Fa "unsigned int *month"
98 .Fa "unsigned int *day"
101 .Fn bsddialog_end "void"
104 .Fa "struct bsddialog_conf *conf"
105 .Fa "const char *text"
108 .Fa "unsigned int formrows"
109 .Fa "unsigned int nitems"
110 .Fa "struct bsddialog_formitem *items"
115 .Fa "struct bsddialog_conf *conf"
116 .Fa "const char *text"
119 .Fa "unsigned int perc"
121 .Fa "const char *sep"
122 .Fa "const char *end"
125 .Fn bsddialog_geterror "void"
127 .Fo bsddialog_infobox
128 .Fa "struct bsddialog_conf *conf"
129 .Fa "const char *text"
134 .Fn bsddialog_init "void"
136 .Fn bsddialog_init_notheme "void"
138 .Fn bsddialog_inmode "void"
140 .Fn bsddialog_initconf "struct bsddialog_conf *conf"
143 .Fa "struct bsddialog_conf *conf"
144 .Fa "const char *text"
147 .Fa "unsigned int menurows"
148 .Fa "unsigned int nitems"
149 .Fa "struct bsddialog_menuitem *items"
153 .Fo bsddialog_mixedgauge
154 .Fa "struct bsddialog_conf *conf"
155 .Fa "const char *text"
158 .Fa "unsigned int mainperc"
159 .Fa "unsigned int nminibars"
160 .Fa "char **minilabels"
164 .Fo bsddialog_mixedlist
165 .Fa "struct bsddialog_conf *conf"
166 .Fa "const char *text"
169 .Fa "unsigned int menurows"
170 .Fa "unsigned int ngroups"
171 .Fa "struct bsddialog_menugroup *groups"
177 .Fa "struct bsddialog_conf *conf"
178 .Fa "const char *text"
184 .Fa "struct bsddialog_conf *conf"
185 .Fa "const char *text"
188 .Fa "unsigned int *seconds"
191 .Fo bsddialog_radiolist
192 .Fa "struct bsddialog_conf *conf"
193 .Fa "const char *text"
196 .Fa "unsigned int menurows"
197 .Fa "unsigned int nitems"
198 .Fa "struct bsddialog_menuitem *items"
202 .Fo bsddialog_rangebox
203 .Fa "struct bsddialog_conf *conf"
204 .Fa "const char *text"
212 .Fn bsddialog_refresh "void"
214 .Fo bsddialog_textbox
215 .Fa "struct bsddialog_conf *conf"
216 .Fa "const char *file"
221 .Fo bsddialog_timebox
222 .Fa "struct bsddialog_conf *conf"
223 .Fa "const char *text"
226 .Fa "unsigned int *hh"
227 .Fa "unsigned int *mm"
228 .Fa "unsigned int *ss"
232 .Fa "struct bsddialog_conf *conf"
233 .Fa "const char *text"
237 .In bsddialog_theme.h
240 .Fa "enum bsddialog_color foreground"
241 .Fa "enum bsddialog_color background"
242 .Fa "unsigned int flags"
245 .Fo bsddialog_color_attrs
247 .Fa "enum bsddialog_color *foreground"
248 .Fa "enum bsddialog_color *background"
249 .Fa "unsigned int *flags"
252 .Fn bsddialog_get_theme "struct bsddialog_theme *theme"
254 .Fn bsddialog_hascolors "void"
256 .Fn bsddialog_set_default_theme "enum bsddialog_default_theme theme"
258 .Fn bsddialog_set_theme "struct bsddialog_theme *theme"
262 library provides an API to build Text User Interface dialogs and widgets.
265 initializes the library, the only functions that can be called before is
266 .Fn bsddialog_initconf
268 After the initialization the input and output should be handled via the library
271 .Fn bsddialog_init_notheme
274 except it does not set the default graphical theme; see
276 subsection to set a theme explicitly.
279 restores the screen like before
281 After the call is not possible to use the library functions.
289 .Fn bsddialog_init_notheme
295 .Fn bsddialog_backtitle
298 on the top of the screen.
306 returns a string to describe the last error.
307 The function should be called after a
312 clears the screen from
315 .Fn bsddialog_refresh
316 useful to refresh the screen after a terminal mode change, see
319 The dialogs have common arguments.
321 is a string printed inside the dialog.
324 parameter can be a multibyte character string depending on current locale, see
329 are height and width, their value can be a fixed size,
330 .Dv BSDDIALOG_AUTOSIZE
332 .Dv BSDDIALOG_FULLSCREEN .
334 is a struct to customize the current dialog, it does not set global properties
337 .Bd -literal -offset indent -compact
338 struct bsddialog_conf {
340 unsigned int auto_minheight;
341 unsigned int auto_minwidth;
342 unsigned int auto_topmargin;
343 unsigned int auto_downmargin;
344 const char *bottomtitle;
357 const char *f1_message;
360 unsigned int cols_per_row;
368 bool shortcut_buttons;
380 const char *left1_label;
381 const char *left2_label;
382 const char *left3_label;
384 const char *ok_label;
386 const char *extra_label;
388 const char *cancel_label;
391 const char *help_label;
392 const char *right1_label;
393 const char *right2_label;
394 const char *right3_label;
395 const char *default_label;
401 .It Fa conf.ascii_lines
402 ascii characters to draw lines, default wide characters.
403 .It Fa conf.auto_minheight
407 .Dv BSDDIALOG_AUTOSIZE .
408 .It Fa conf.auto_minwidth
412 .Dv BSDDIALOG_AUTOSIZE .
413 .It Fa conf.auto_topmargin
417 .Dv BSDDIALOG_AUTOSIZE
419 .Dv BSDDIALOG_FULLSCREEN ,
422 .Dv BSDDIALOG_CENTER .
423 .It Fa conf.auto_downmargin
427 .Dv BSDDIALOG_AUTOSIZE
429 .Dv BSDDIALOG_FULLSCREEN .
430 .It Fa conf.bottomtitle
433 hide the dialog at exit.
434 .It Fa conf.get_height
437 is set like the dialog height.
438 .It Fa conf.get_width
441 is set like the dialog width.
447 wait before to return, the value is in seconds.
451 dialog vertical position, 0 is top screen, can be
452 .Dv BSDDIALOG_CENTER .
454 dialog horizontal position, 0 is left screen, can be
455 .Dv BSDDIALOG_CENTER .
459 .It Fa conf.key.enable_esc
462 key to close the dialog.
463 .It Fa conf.key.f1_file
464 open a file in a textbox if F1 is pressed.
465 .It Fa conf.key.f1_message
466 build a msgbox with message if F1 is pressed.
470 .It Fa conf.text.cols_per_row
471 Try to set the number of columns for a row of
473 with autosizing, default
475 .It Fa conf.text.escape
507 reverse foreground and background.
513 disable highlighting.
519 disable each customization.
520 .It Fa conf.text.tablen
524 .Fn bsddialog_textbox
529 .It Fa conf.button.always_active
530 buttons always active, avoiding focus switch between buttons and input fields or
533 .Fn bsddialog_datebox ,
534 .Fn bsddialog_calendar
536 .Fn bsddialog_timebox .
537 .It Fa conf.button.left1_label
538 add a button with the specified label.
539 .It Fa conf.button.left2_label
540 add a button with the specified label.
541 .It Fa conf.button.left3_label
542 add a button with the specified label.
543 .It Fa conf.button.without_ok
545 .It Fa conf.button.ok_label
546 set label for OK button.
547 .It Fa conf.button.with_extra
549 .It Fa conf.button.extra_label
550 set a label for Extra button.
551 .It Fa conf.button.without_cancel
552 disable Cancel button.
553 .It Fa conf.button.cancel_label
554 sets a label for Cancel button.
555 .It Fa conf.button.default_cancel
556 on startup focus on the Cancel button.
557 .It Fa conf.button.with_help
559 .It Fa conf.button.help_label
560 set a label for Help button.
561 .It Fa conf.button.right1_label
562 add a button with the specified label.
563 .It Fa conf.button.right2_label
564 add a button with the specified label.
565 .It Fa conf.button.right3_label
566 add a button with the specified label.
567 .It Fa conf.button.default_label
568 focus on the button with the specified label.
571 .Fn bsddialog_initconf
574 disabling each property, except
581 .Dv BSDDIALOG_CENTER ,
582 .Fa conf.text.cols_per_row
586 .Fn bsddialog_calendar
587 builds a dialog to select a date.
592 are default values on startup, selected date at exit.
594 .Fn bsddialog_checklist
595 builds dialogs to select some item from a list via the SPACE key, can be
601 .Fn bsddialog_datebox
602 builds a dialog to select a date.
607 are default values on startup, selected date at exit.
608 The function can be customized by:
610 .It Fa conf.date.format
611 date format user interface, possible values:
618 builds a dialog to display an array of
622 elements to get input strings.
624 is the graphical height for the items inside the dialog,
630 is the default item index on startup and the last focused item at exit, a
631 negative value if no item is focused.
632 An item is defined like:
634 .Bd -literal -offset indent -compact
635 struct bsddialog_formitem {
643 unsigned int fieldlen;
644 unsigned int maxvaluelen;
649 const char *bottomdesc;
654 is a string to describe the request at the position
658 The field for the input is at the position
663 is its graphical width, while
665 is the maximum number of characters of the input string.
667 is the default field value.
670 is the allocated memory with the current field string at exit, its size depends
671 on the current locale.
673 is an OR value to set the field:
674 .Dv BSDDIALOG_FIELDHIDDEN ,
675 .Dv BSDDIALOG_FIELDREADONLY ,
676 .Dv BSDDIALOG_FIELDNOCOLOR ,
677 .Dv BSDDIALOG_FIELDCURSOREND ,
678 .Dv BSDDIALOG_FIELDEXTEND ,
679 .Dv BSDDIALOG_FIELDSINGLEBYTE .
681 is printed at bottom screen if the item is focused.
684 can be customized by:
686 .It Fa conf.form.securech
687 charachter to hide the input with
688 .Dv BSDDIALOG_FIELDHIDDEN .
689 .It Fa conf.form.securembch
690 multibyte charachter to hide the input with
691 .Dv BSDDIALOG_FIELDHIDDEN ,
692 .Fa conf.form.securech
694 .It Fa conf.form.value_wchar
703 builds a dialog with a bar to show
705 If the file descriptor
707 is greater or equal to 0 the dialog waits to read
709 from it, then the first string replaces
711 and the following strings replace
715 the loop ends reading
718 .Fn bsddialog_infobox
719 builds a dialog without buttons and returns instantly.
722 builds a dialog to select an item from a list via SPACE or ENTER.
726 .Bd -literal -offset indent -compact
727 struct bsddialog_menuitem {
733 const char *bottomdesc;
741 are printed at the item row.
743 is printed at bottom screen if the item is focused.
753 if the item is selected,
757 is an array of items of
761 is the graphical height of the list inside the dialog, if
764 .Dv BSDDIALOG_AUTOSIZE
766 specifies a maximum value.
770 is the default item index on startup and the last focused item at exit, a
771 negative value if no item is focused.
773 .Fn bsddialog_checklist ,
775 .Fn bsddialog_mixedlist
777 .Fn bsddialog_radiolist
778 can be customized by:
780 .It Fa conf.menu.align_left
781 align items to left, default center.
782 .It Fa conf.menu.no_desc
783 hide items description.
784 .It Fa conf.menu.no_name
785 hide items name, mutually exclusive with
786 .Fa conf.menu.no_desc .
787 .It Fa conf.menu.shortcut_buttons
788 enable shortcut keys on buttons, default on items.
791 .Fn bsddialog_mixedgauge
792 builds a dialog with a main bar with the
801 can be: a positive value to print a bar with a percentace, a negative constant
802 .Dv BSDDIALOG_MG_SUCCEEDED ,
803 .Dv BSDDIALOG_MG_FAILED ,
804 .Dv BSDDIALOG_MG_PASSED ,
805 .Dv BSDDIALOG_MG_COMPLETED ,
806 .Dv BSDDIALOG_MG_CHECKED ,
807 .Dv BSDDIALOG_MG_DONE ,
808 .Dv BSDDIALOG_MG_SKIPPED ,
809 .Dv BSDDIALOG_MG_INPROGRESS ,
810 .Dv BSDDIALOG_MG_BLANK
813 .Dv BSDDIALOG_MG_NA ,
814 .Dv BSDDIALOG_MG_PENDING
815 to print a descriptive string, otherwise
819 .Fn bsddialog_mixedlist
820 builds a dialog with collections of checklists, radiolists and separators.
821 A collection is a set defined like:
823 .Bd -literal -offset indent -compact
824 enum bsddialog_menutype {
830 struct bsddialog_menugroup {
831 enum bsddialog_menutype type;
833 struct bsddialog_menuitem *items;
834 unsigned int min_on; /* unused for now */
839 is an array of sets of
843 is the graphical height size for the list.
849 specify the default item on startup and the last focused item at exit, could be
850 a negative value if no item is focused.
851 The dialog can be customized by
857 builds a dialog with OK button.
860 builds a dialog waiting until the timeout in
862 expires or a button is pressed.
865 is set like remaining time.
867 .Fn bsddialog_radiolist
868 builds dialogs to select at most an item from a list via the SPACE key, can be
874 .Fn bsddialog_rangebox
875 to select a value between
880 is the default value on startup and the selected value at exit.
881 The current value is printed inside a bar, the keys UP, DOWN, HOME, END, PAGEUP
882 and PAGEDOWN can change it.
884 .Fn bsddialog_textbox
887 UP, DOWN, LEFT, RIGHT, HOME, END, PAGEUP and PAGEDOWN keys are available to
888 navigate the file, TAB changes button.
893 .Fn bsddialog_timebox
894 builds a dialog to choose a time.
899 are default values on startup, selected time at exit.
902 provides a dialog for a
903 .Dq Yes-No Question ,
904 the labels on buttons are Yes and No.
906 The graphical properties are global to the library.
907 They are represented by
908 .Fa struct bsddialog_theme
909 and can be customized at runtime via the
910 .In bsddialog_theme.h
913 .Bd -literal -offset indent -compact
914 struct bsddialog_theme {
929 int bottomtitlecolor;
958 unsigned int minmargin;
959 unsigned int maxmargin;
974 refers to focus when an element can be in selected or not selected state.
977 generates and returns a color to set a
978 .Fa struct bsddialog_theme
981 .Fa enum bsddialog_color
983 .Dv BSDDIALOG_BLACK ,
985 .Dv BSDDIALOG_GREEN ,
986 .Dv BSDDIALOG_YELLOW ,
988 .Dv BSDDIALOG_MAGENTA ,
990 .Dv BSDDIALOG_WHITE .
993 .Dv BSDDIALOG_BLINK ,
995 .Dv BSDDIALOG_HALFBRIGHT ,
996 .Dv BSDDIALOG_HIGHLIGHT ,
997 .Dv BSDDIALOG_REVERSE ,
998 .Dv BSDDIALOG_UNDERLINE .
1000 .Fn bsddialog_color_attrs
1005 like the properties of
1008 .Fn bsddialog_color .
1010 .Fn bsddialog_get_theme
1013 like the current runtime theme.
1015 .Fn bsddialog_hascolors
1018 if the terminal provides colors,
1022 .Fn bsddialog_set_theme
1025 like current runtime theme.
1026 Changes take effect only for dialogs built after
1029 .Fn bsddialog_set_default_theme
1030 sets a library default theme like current theme, possible values:
1031 .Dv BSDDIALOG_THEME_BLACKWHITE ,
1032 .Dv BSDDIALOG_THEME_FLAT ,
1033 .Dv BSDDIALOG_THEME_3D .
1034 Changes take effect only for dialogs built after the call.
1036 The functions return the value
1039 otherwise, depending on the pressed button, the following values can be
1042 .Dv BSDDIALOG_CANCEL ,
1043 .Dv BSDDIALOG_HELP ,
1044 .Dv BSDDIALOG_EXTRA ,
1045 .Dv BSDDIALOG_LEFT1 ,
1046 .Dv BSDDIALOG_LEFT2 ,
1047 .Dv BSDDIALOG_LEFT3 ,
1048 .Dv BSDDIALOG_RIGHT1 ,
1049 .Dv BSDDIALOG_RIGHT2 ,
1050 .Dv BSDDIALOG_RIGHT3 .
1057 .Dv BSDDIALOG_CANCEL ,
1060 The functions return
1063 .Fa conf.key.enable_esc
1064 is enabled and the ESC key is pressed.
1068 .Dv BSDDIALOG_TIMEOUT
1069 if the timeout expires.
1074 .Bd -literal -offset indent -compact
1076 struct bsddialog_conf conf;
1078 if (bsddialog_init() == BSDDIALOG_ERROR)
1081 bsddialog_initconf(&conf);
1082 conf.title = "yesno";
1083 output = bsddialog_yesno(&conf, "Example", 7, 25);
1094 case BSDDIALOG_ERROR:
1095 printf("Error: %s\\n", bsddialog_geterror());
1102 .Bd -literal -offset indent -compact
1103 struct bsddialog_conf conf;
1104 struct bsddialog_theme theme;
1108 bsddialog_initconf(&conf);
1109 bsddialog_msgbox(&conf, "Default theme", 7, 25);
1111 bsddialog_get_theme(&theme);
1112 theme.screen.color = bsddialog_color(BSDDIALOG_RED, BSDDIALOG_GREEN,
1114 bsddialog_set_theme(&theme);
1115 bsddialog_backtitle(&conf, "Red foreground and Green background");
1116 bsddialog_msgbox(&conf, "Change screen color", 7, 25);
1118 bsddialog_set_default_theme(BSDDIALOG_THEME_BLACKWHITE);
1119 bsddialog_msgbox(&conf, "Black and White theme", 7, 25);
1126 .Bd -literal -offset indent -compact
1128 struct bsddialog_conf conf;
1129 struct bsddialog_menuitem item;
1130 struct bsddialog_menuitem check[2] = {
1131 { "1", true, 0, "Name 1", "Desc 1", "Check Bottom Desc 1" },
1132 { "2", false, 0, "Name 2", "Desc 2", "Check Bottom Desc 2" }
1134 struct bsddialog_menuitem sep[1] = {
1135 { "3", true, 0, "Radiolist", "(desc)", "" }
1137 struct bsddialog_menuitem radio[2] = {
1138 { "4", true, 0, "Name 1", "Desc 1", "Radio Bottom Desc 1" },
1139 { "5", false, 0, "Name 2", "Desc 2", "Radio Bottom Desc 2" }
1141 struct bsddialog_menugroup group[3] = {
1142 { BSDDIALOG_CHECKLIST, 2, check },
1143 { BSDDIALOG_SEPARATOR, 1, sep },
1144 { BSDDIALOG_RADIOLIST, 2, radio }
1148 bsddialog_initconf(&conf);
1149 bsddialog_mixedlist(&conf, "Example", 20, 30, 11, 3, group, NULL,
1153 for (i = 0; i < 3; i++) {
1154 for (j = 0; j < group[i].nitems; j++) {
1155 item = group[i].items[j];
1156 switch (item.type) {
1157 case BSDDIALOG_SEPARATOR:
1158 printf("---- %s ----\\n", item.name);
1160 case BSDDIALOG_RADIOLIST:
1161 printf(" (%c) %s\\n",
1162 item.on ? '*' : ' ', item.name);
1164 case BSDDIALOG_CHECKLIST:
1165 printf(" [%c] %s\\n",
1166 item.on ? 'X' : ' ', item.name);
1178 library first appeared in
1183 .An Alfonso Sabato Siciliano Aq Mt asiciliano@FreeBSD.org .