BSDDIALOG(3)

NAME
bsddialog_backtitle, bsddialog_clearterminal, bsddialog_color, bsddialog_checklist, bsddialog_datebox, bsddialog_end, bsddialog_form, bsddialog_gauge, bsddialog_geterror, bsddialog_get_theme, bsddialog_infobox, bsddialog_init, 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
libbsddialog

SYNOPSIS
#include <bsddialog.h>
int
bsddialog_backtitle(struct bsddialog_conf *conf, const char *backtitle);
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_init(void);
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_get_theme(struct bsddialog_theme *theme);
int
bsddialog_set_default_theme(enum bsddialog_default_theme theme);
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_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, can be empty (“”) but not NULL.

  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;
    	const char *bottomtitle;
    	bool clear;
    	const char *f1_file;
    	const char *f1_message;
    	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;
    	} key;
    	struct {
    		bool highlight;
    		unsigned int tablen;
    	} text;
    	struct {
    		bool align_left;
    		bool no_desc;
    		bool no_name;
    		bool shortcut_buttons;
    	} menu;
    	struct {
    		int  securech;
    		bool value_withcancel;
    		bool value_withextra;
    		bool value_withhelp;
    	} form;
    	struct {
    		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.bottomtitle
subtitle at the dialog bottom side.
conf.clear
hide the dialog at exit.
conf.f1_file
file to open if F1 is pressed.
conf.f1_message
message to display if F1 is pressed.
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.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.
“\Zr”
reverse colors between foreground and background.
“\ZR”
disable reverse.
“\Zb”
bold.
“\ZB”
disable bold.
“\Zu”
underline.
“\ZU”
disable underline.
“\Zn”
disable each customization.
conf.text.tablen tab length.

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.

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_datebox() builds 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.

bsddialog_mixedlist() builds a dialog with collections of checklists, radiolists and separators. A collection is a set defined like:

    enum bsddialog_grouptype {
    	BSDDIALOG_CHECKLIST,
    	BSDDIALOG_RADIOLIST,
    	BSDDIALOG_SEPARATOR,
    };
    struct bsddialog_menugroup {
    	enum bsddialog_grouptype 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 a list of items to get strings in input, 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 describes 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 length of the input string, init is the default value. If the OK button is pressed value is the allocated memory with the current field string. flags is an OR value to set the BSDDIALOG_FIELDHIDDEN and BSDDIALOG_FIELDREADONLY flags for the field. bottomdesc is printed on the bottom side of the screen if the item is focused. items is an array of items of nitems elements, formrows specifies the graphical fixed height for the items list; ylabel and yfield have to be between 1 and formrows.

bsddialog_form() can be customized by:
conf.form.securech
charachter to hide the input with BSDDIALOG_FIELDHIDDEN.
conf.form.value_without_ok
allocate memory and set value also if the OK button is not pressed.

bsddialog_gauge() builds a dialog with a bar to shows perc, if the file 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 h;
    		unsigned int w;
    	} shadow;
    	struct {
    		int  color;
    		bool delimtitle;
    		int  titlecolor;
    		int  lineraisecolor;
    		int  linelowercolor;
    		int  bottomtitlecolor;
    	} dialog;
    	struct {
    		int arrowcolor;
    		int selectorcolor;
    		int f_namecolor;
    		int namecolor;
    		int f_desccolor;
    		int desccolor;
    		int namesepcolor;
    		int descsepcolor;
    		int f_shortcutcolor;
    		int shortcutcolor;
    	} menu;
    	struct {
    		int f_fieldcolor;
    		int fieldcolor;
    		int readonlycolor;
    	} form;
    	struct {
    		int f_color;
    		int color;
    	} bar;
    	struct {
    		unsigned int space;
    		int leftch;
    		int rightch;
    		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_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_DEFAULT and BSDDIALOG_THEME_DIALOG, they can be set via bsddialog_set_default_theme().

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);
    bsddialog_initconf(&conf);
    conf.title = "yesno";
    output = bsddialog_yesno(&conf, "Example", 7, 25);
    bsddialog_end();
    switch (output) {
    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;
    if (bsddialog_init() == BSDDIALOG_ERROR)
    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[5] = {
        { "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();
    for (i = 0; i < 3; i++) {
    	for (j = 0; j < group[i].nitems; j++) {
    		item = group[i].items[j];
    		switch (item.type) {
    		case BSDDIALOG_SEPARATOR:
    			printf("---- %s ----\n", item.name);
    			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), ncurses(3)

HISTORY
The bsddialog library first appeared in FreeBSD 14.0.

AUTHORS
bsddialog was written by Alfonso Sabato Siciliano <alf.siciliano@gmail.com>.

BUGS
bsddialog_form() does not resize the dialog after a terminal resize and does not provide scrolling for items.