LibBSDDialog

Posted on January 16, 2022

LibBSDDialog provides an API to build TUI dialogs and widgets to show messages, to get input and to inform about a computation status.

Example to build a msgbox with Hello World!:

#include <bsddialog.h>

int main()
{
	struct bsddialog_conf conf;

	bsddialog_init();
	bsddialog_initconf(&conf);
	bsddialog_msgbox(&conf, "Hello World!", 8, 20);
	bsddialog_end();

	return (0);
}


Of course, it is possible to get user input and to change the UI, “Yes-No Question” example:

#include <bsddialog.h>
#include <bsddialog_theme.h>
#include <stdio.h>

int main()
{
	int output;
	struct bsddialog_conf conf;

	bsddialog_init();
	bsddialog_set_default_theme(BSDDIALOG_THEME_BSDDIALOG);

	bsddialog_initconf(&conf);
	conf.title = " yesno ";
	conf.text.highlight = true;
	output = bsddialog_yesno(&conf, "\nHello \\Z3World\\Zn!", 10, 30);

	bsddialog_end();

	switch (output) {
	case BSDDIALOG_YES:
		printf("YES\n");
		break;
	case BSDDIALOG_NO:
		printf("NO\n");
		break;
	}

	return (0);
}

And to show computation status:


To compile the examples:

% git clone https://gitlab.com/alfix/bsddialog.git
% cd bsddialog
% make
% cc -I./lib example.c -o example -L./lib -lbsddialog -Wl,-rpath=./lib
% ./example

Dialogs and widgets:

  • infobox, msgbox, yesno.
  • radiolist, checklist, menu, mixedlist.
  • form.
  • gauge, pause, mixedgauge, rangebox.
  • datebox, timebox.
  • textbox.

Documentation:

The library has a manual to describe the API

% man ./lib/bsddialog.3

and a collection of examples in the Public Domain to build new projects

% cd examples_library
% sh compile
% ./datebox
% ./form
% ./infobox
% ./menu
% ./mixedlist
% ./msgbox
% ./pause
% ./radiolist
% ./rangebox
% ./theme
% ./timebox
% ./yesno

LibBSDDialog is an open source project released under the term of the BSD 2 Clause License, repository: https://gitlab.com/alfix/bsddialog.

Happy Coding!