FreeBSD manual

download PDF document: bsddialog.3.pdf

BSDDIALOG(3) FreeBSD Library Functions Manual BSDDIALOG(3)
NAME bsddialog_backtitle, bsddialog_calendar, bsddialog_clearterminal, bsddialog_color, bsddialog_color_attrs, bsddialog_checklist, bsddialog_datebox, bsddialog_end, bsddialog_form, bsddialog_gauge, bsddialog_geterror, bsddialog_get_theme, bsddialog_hascolors, bsddialog_infobox, bsddialog_init, bsddialog_init_notheme, bsddialog_initconf, bsddialog_menu, bsddialog_mixedgauge, bsddialog_mixedlist, bsddialog_msgbox, bsddialog_pause, bsddialog_radiolist, bsddialog_rangebox, bsddialog_set_theme, bsddialog_set_default_theme, bsddialog_textbox, bsddialog_timebox, bsddialog_yesno - TUI dialogs
LIBRARY library "libbsddialog"
SYNOPSIS #include <bsddialog.h>
int bsddialog_backtitle(struct bsddialog_conf *conf, const char *backtitle);
int bsddialog_calendar(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd);
int bsddialog_checklist(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int menurows, unsigned int nitems, struct bsddialog_menuitem *items, int *focusitem);
int bsddialog_clearterminal(void);
int bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd);
int bsddialog_end(void);
int bsddialog_form(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int formrows, unsigned int nitems, struct bsddialog_formitem *items);
int bsddialog_gauge(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int perc, int fd, const char *sep);
const char * bsddialog_geterror(void);
int bsddialog_infobox(struct bsddialog_conf *conf, const char *text, int rows, int cols);
int bsddialog_initconf(struct bsddialog_conf *conf);
int bsddialog_menu(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int menurows, unsigned int nitems, struct bsddialog_menuitem *items, int *focusitem);
int bsddialog_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int mainperc, unsigned int nminibars, char **minilabels, int *minipercs);
int bsddialog_mixedlist(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int menurows, unsigned int ngroups, struct bsddialog_menugroup *groups, int *focuslist, int *focusitem);
int bsddialog_msgbox(struct bsddialog_conf *conf, const char *text, int rows, int cols);
int bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int seconds);
int bsddialog_radiolist(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int menurows, unsigned int nitems, struct bsddialog_menuitem *items, int *focusitem);
int bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows, int cols, int min, int max, int *value);
int bsddialog_textbox(struct bsddialog_conf *conf, const char *file, int rows, int cols);
int bsddialog_timebox(struct bsddialog_conf *conf, const char *text, int rows, int cols, unsigned int *hh, unsigned int *mm, unsigned int *ss);
int bsddialog_yesno(struct bsddialog_conf *conf, const char *text, int rows, int cols);
#include <bsddialog_theme.h>
int bsddialog_color(enum bsddialog_color foreground, enum bsddialog_color background, unsigned int flags);
int bsddialog_color_attrs(int color, enum bsddialog_color *foreground, enum bsddialog_color *background, unsigned int *flags);
int
int bsddialog_set_theme(struct bsddialog_theme *theme);
DESCRIPTION The bsddialog library provides an API to build Text User Interface dialogs and widgets: to display messages, to get input and to inform about a computation status.
bsddialog_init() initializes the library, the only functions that can be called before is bsddialog_initconf() described later. After the initialization the input and output should be handled via the library API. bsddialog_end() restores the screen like before bsddialog_init(), then it is not possible to use the library functions. bsddialog_init_notheme() is equivalent to bsddialog_init() except it does not set the default graphical theme; see Theme subsection to set a theme explicitly.
bsddialog_error() returns a string to describe the last error, it should be called after a BSDDIALOG_ERROR returned value. bsddialog_clearterminal() clears the screen. bsddialog_backtitle() prints backtitle on the top of the screen, it is possible to set conf.ascii_lines and conf.no_lines; conf is described later.
Each char* argument has to be a well terminated string, it can be a multibyte character string depending on current locale, see setlocale(3).
Dialogs The dialogs have common arguments. text is a string printed inside the dialog. rows and cols are height and width, their value can be between 2 and the screen size, BSDDIALOG_AUTOSIZE or BSDDIALOG_FULLSCREEN. conf is a struct to customize the dialog, it does not set global properties to the library.
struct bsddialog_conf { bool ascii_lines; unsigned int auto_minheight; unsigned int auto_minwidth; unsigned int auto_topmargin; unsigned int auto_downmargin; const char *bottomtitle; bool clear; int *get_height; int *get_width; bool no_lines; bool shadow; unsigned int sleep; const char *title; int y; int x; struct { bool enable_esc; const char *f1_file; const char *f1_message; } key; struct { unsigned int cols_per_row; bool highlight; unsigned int tablen;
} menu; struct { char securech; char *securembch; bool value_wchar; bool value_without_ok; } form; struct { bool always_active; bool without_ok; const char *ok_label; bool with_extra; const char *extra_label; bool without_cancel; const char *cancel_label; bool default_cancel; bool with_help; const char *help_label; const char *generic1_label; const char *generic2_label; const char *default_label; } button; };
conf.ascii_lines ascii characters to draw lines, default wide characters. conf.auto_minheight minimum height if rows is BSDDIALOG_AUTOSIZE. conf.auto_minwidth minimum width if cols is BSDDIALOG_AUTOSIZE. conf.auto_topmargin top margin if rows is BSDDIALOG_AUTOSIZE or BSDDIALOG_FULLSCREEN, conf.y has to be BSDDIALOG_CENTER. conf.auto_downmargin down margin if rows is BSDDIALOG_AUTOSIZE or BSDDIALOG_FULLSCREEN. conf.bottomtitle subtitle at the dialog bottom side. conf.clear hide the dialog at exit. conf.get_height if not NULL is set like the dialog height. conf.get_width if not NULL is set like the dialog width. conf.no_lines not draw lines. conf.shadow draw shadow. conf.sleep wait before to return, the value is in seconds. conf.title title at the top dialog side. conf.y vertical position, 0 is top screen size, can be BSDDIALOG_CENTER. conf.x horizontal position, 0 is left screen side, can be BSDDIALOG_CENTER.
conf.key.enable_esc enables ESC key to close the dialog. conf.key.f1_file file to open if F1 is pressed. conf.key.f1_message message to display if F1 is pressed.
conf.text.cols_per_row Try to set the number of columns for a row of text with autosizing; default 10. conf.text.highlight enables highlights for text, properly the following sequences are considered escapes: "\Z0" black. "\Z1" red. "\Z2" green. "\Z3" yellow. "\Z4" blue. "\Z5" magenta. "\Z6" cyan. "\Z7" white. conf.text.tablen tab length for text argument and bsddialog_textbox() function.
conf.button.always_active buttons always active, avoidind focus switch between buttons and input fields or input boxes in bsddialog_form(), bsddialog_datebox(), bsddialog_calendar() and bsddialog_timebox(). conf.button.without_ok disable OK button. conf.button.ok_label set label for OK button. conf.button.with_extra add Extra button. conf.button.extra_label set a label for Extra button. conf.button.without_cancel disable Cancel button. conf.button.cancel_label sets a label for Cancel button. conf.button.default_cancel on startup focus on the Cancel button. conf.button.with_help add Help button. conf.button.help_label set a label for Help button. conf.button.generic1_label add a button with the specified label. conf.button.generic2_label add a button with the specified label. conf.button.default_label focus on the button with the specified label.
bsddialog_initconf() initializes conf disabling each property, except conf.shadow to true, conf.y and conf.x to BSDDIALOG_CENTER, conf.text.cols_per_row to 10.
bsddialog_infobox() builds a dialog without buttons and returns instantly. bsddialog_msgbox() builds a dialog with OK button. bsddialog_yesno() provides a dialog for a "Yes-No Question", the labels on buttons are Yes and No.
bsddialog_pause() builds a dialog waiting until the timeout in seconds expires or a button is pressed.
bsddialog_calendar() and bsddialog_datebox() build a dialog to select a date, yy, mm, and dd are default values on startup, selected date at exit. bsddialog_timebox() builds a dialog to choose a time, hh, mm, and ss are default values on startup, selected time at exit.
bsddialog_checklist(), bsddialog_menu() and bsddialog_radiolist() build dialogs to select some item from a list via the SPACE key, an item is defined like:
struct bsddialog_menuitem { const char *prefix; bool on; unsigned int depth; const char *name; const char *desc; const char *bottomdesc; };
prefix, name and desc are strings to describe the item and are printed on its row, bottomdesc is printed on the bottom side of the screen, depth is a margin between the prefix and name useful to implement a "treeview," on is set to true if the item is selected, false otherwise. items is an array of items of nitem elements, menurows specifies the graphical fixed height of the list, if cols is set to BSDDIALOG_AUTOSIZE menurows specifies a maximum value. Finally, if not NULL, focusitem specifies the default item on startup and the last focused item at exit, could be a negative value if no item is focused.
};
struct bsddialog_menugroup { enum bsddialog_menutype type; unsigned int nitems; struct bsddialog_menuitem *items; };
groups is an array of sets of ngroups elements. menurows is the graphical height size for the list. If not NULL, focuslist and focusitem specify the default item on startup and the last focused item at exit, could be a negative value if no item is focused.
bsddialog_checklist(), bsddialog_menu(), bsddialog_mixedlist() and bsddialog_radiolist() can be costomizated by: conf.menu.align_left aligns items to left, default center. conf.menu.no_desc hide description. conf.menu.no_name hide names. conf.menu.on_without_ok set items on also if the OK button is not pressed. conf.menu.shortcut_buttons enable shortcut keys on buttons, default on items.
bsddialog_form() builds a dialog to display an array of items of nitems elements to get strings in input. formrows specifies the graphical height for the box around the items, 0 for autosizing. An item is defined like:
struct bsddialog_formitem { const char *label; unsigned int ylabel; unsigned int xlabel;
const char *init; unsigned int yfield; unsigned int xfield; unsigned int fieldlen; unsigned int maxvaluelen; char *value;
unsigned int flags;
const char *bottomdesc; };
label is a string to describe the request, it is printed at the position ylabel and xlabel. The field for the input is at the position yfield and xfield, fieldlen is its graphical width, while maxvalelen is the maximum number of characters of the input string. init is the default field value. If the OK button is pressed value is the allocated memory with the current field string, its size depends on the current locale. flags is an OR value to set the BSDDIALOG_FIELDHIDDEN, BSDDIALOG_FIELDREADONLY, BSDDIALOG_FIELDNOCOLOR, BSDDIALOG_FIELDCURSOREND, BSDDIALOG_FIELDEXTEND and BSDDIALOG_FIELDSINGLEBYTE. flags for the field. bottomdesc is printed on the bottom side of the screen if the item is focused.
bsddialog_form() can be customized by: conf.form.securech charachter to hide the input with BSDDIALOG_FIELDHIDDEN. descriptor fd is greater or equal to 0 the dialog waits to read separator from it, then the first string replaces perc and the following strings replace text until the next separator, the loop ends reading EOF.
bsddialog_mixedgauge() draws a main bar with the mainperc percentage and nminibars each one with a minilabel and a miniperc with a value between 0 and 100 or BSDDIALOG_MG_SUCCEEDED, BSDDIALOG_MG_FAILED, BSDDIALOG_MG_PASSED, BSDDIALOG_MG_COMPLETED, BSDDIALOG_MG_CHECKED, BSDDIALOG_MG_DONE, BSDDIALOG_MG_SKIPPED, BSDDIALOG_MG_INPROGRESS, BSDDIALOG_MG_BLANK, BSDDIALOG_MG_NA or BSDDIALOG_MG_PENDING to print a descriptive string.
bsddialog_rangebox() to select a value between min and max. value is the default value on startup and the selected value at exit. The current value is printed inside a bar, the keys UP, DOWN, HOME, END, PAGEUP and PAGEDOWN can change it.
bsddialog_textbox() opens and prints file in a dialog, the UP, DOWN, HOME, END, PAGEUP and PAGEDOWN keys are availble to navigate the file. OK button is renamed EXIT.
Theme The graphical properties are global to the library, they are represented by struct bsddialog_theme and can be customized at runtime via the <bsddialog_theme.h> API.
struct bsddialog_theme { struct { int color; } screen; struct { int color; unsigned int y; unsigned int x; } shadow; struct { int color; bool delimtitle; int titlecolor; int lineraisecolor; int linelowercolor; int bottomtitlecolor; int arrowcolor; } dialog; struct { int f_selectorcolor; int selectorcolor; int f_namecolor; int namecolor; int f_desccolor; int desccolor; int namesepcolor; int descsepcolor; int f_shortcutcolor; int shortcutcolor; int bottomdesccolor; } menu; struct { int f_fieldcolor;
} bar; struct { unsigned int minmargin; unsigned int maxmargin; char leftdelim; char rightdelim; int delimcolor; int f_delimcolor; int color; int f_color; int shortcutcolor; int f_shortcutcolor; } button; };
A member with the "f_" prefix refers to an element with focus.
bsddialog_get_theme() sets theme like the current theme.
A color can be set by the value returned by bsddialog_color(), Possible values for background and foreground are: BSDDIALOG_BLACK, BSDDIALOG_RED, BSDDIALOG_GREEN, BSDDIALOG_YELLOW, BSDDIALOG_BLUE, BSDDIALOG_MAGENTA, BSDDIALOG_CYAN, and BSDDIALOG_WHITE, flags specifies OR-flags, possible values: BSDDIALOG_BOLD, BSDDIALOG_REVERSE and BSDDIALOG_UNDERLINE. bsddialog_color_attrs() gets the properties of a color.
bsddialog_set_theme() sets theme like current theme, the changes takes effect only for dialogs built after the call.
The library provides predefined themes: BSDDIALOG_THEME_BLACKWHITE, BSDDIALOG_THEME_BSDDIALOG, BSDDIALOG_THEME_FLAT and BSDDIALOG_THEME_DIALOG, they can be set via bsddialog_set_default_theme().
bsddialog_hascolors() returns true if the terminal provides colors, false otherwise.
RETURN VALUES The functions return the value BSDDIALOG_ERROR if unsuccessful; otherwise, depending on the pressed button, the following values can be returned: BSDDIALOG_OK, BSDDIALOG_CANCEL, BSDDIALOG_HELP, BSDDIALOG_EXTRA, BSDDIALOG_GENERIC1 or BSDDIALOG_GENERIC2. BSDDIALOG_YES and BSDDIALOG_NO are aliases for BSDDIALOG_OK and BSDDIALOG_CANCEL, respectively.
The functions return BSDDIALOG_ESC if conf.key.enable_esc is enabled and the ESC key is pressed.
bsddialog_pause() returns BSDDIALOG_TIMEOUT if the timeout expires.
EXAMPLES "Yes-No Question" Example:
int output; struct bsddialog_conf conf;
if (bsddialog_init() == BSDDIALOG_ERROR) return (1);
case BSDDIALOG_YES: printf("Yes\n"); break; case BSDDIALOG_NO printf("NO\n"); break; case BSDDIALOG_ERROR: printf("Error: %s\n", bsddialog_geterror()); }
Theme Example:
struct bsddialog_conf conf; struct bsddialog_theme theme;
bsddialog_init();
bsddialog_initconf(&conf); bsddialog_msgbox(&conf, "Default theme", 7, 25);
bsddialog_get_theme(&theme); theme.screen.color = bsddialog_color(BSDDIALOG_RED, BSDDIALOG_GREEN, BSDDIALOG_BOLD); bsddialog_set_theme(&theme); bsddialog_backtitle(&conf, "Red foreground and Green background"); bsddialog_msgbox(&conf, "Change screen color", 7, 25);
bsddialog_set_default_theme(BSDDIALOG_THEME_BLACKWHITE); bsddialog_msgbox(&conf, "Black and White theme", 7, 25);
bsddialog_end();
Mixedlist Example:
unsigned int i, j; struct bsddialog_conf conf; struct bsddialog_menuitem item; struct bsddialog_menuitem check[2] = { { "1", true, 0, "Name 1", "Desc 1", "Check Bottom Desc 1" }, { "2", false, 0, "Name 2", "Desc 2", "Check Bottom Desc 2" } }; struct bsddialog_menuitem sep[1] = { { "3", true, 0, "Radiolist", "(desc)", "" } }; struct bsddialog_menuitem radio[2] = { { "4", true, 0, "Name 1", "Desc 1", "Radio Bottom Desc 1" }, { "5", false, 0, "Name 2", "Desc 2", "Radio Bottom Desc 2" } }; struct bsddialog_menugroup group[3] = { { BSDDIALOG_CHECKLIST, 2, check }, { BSDDIALOG_SEPARATOR, 1, sep }, { BSDDIALOG_RADIOLIST, 2, radio } };
bsddialog_init(); bsddialog_initconf(&conf); bsddialog_mixedlist(&conf, "Example", 20, 30, 11, 3, group, NULL, NULL); bsddialog_end(); break; case BSDDIALOG_RADIOLIST: printf(" (%c) %s\n", item.on ? '*' : ' ', item.name); break; case BSDDIALOG_CHECKLIST: printf(" [%c] %s\n", item.on ? 'X' : ' ', item.name); break; } } }
SEE ALSO bsddialog(1), curses(3)
HISTORY The bsddialog library first appeared in FreeBSD 14.0.
AUTHORS bsddialog was written by Alfonso Sabato Siciliano <asiciliano@FreeBSD.org>.
FreeBSD 14.0-RELEASE-p11 September 23, 2022 FreeBSD 14.0-RELEASE-p11