DEV Community

Alfonso Siciliano
Alfonso Siciliano

Posted on • Originally published at alfonsosiciliano.gitlab.io

LibBSDDialog

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);
}
Enter fullscreen mode Exit fullscreen mode

{ max-width=100% }


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);
}
Enter fullscreen mode Exit fullscreen mode

Image description

And to show computation status:

{ width=100% }


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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Happy Coding!

Top comments (0)