diff options
Diffstat (limited to 'contrib/bsddialog/examples_library')
18 files changed, 852 insertions, 0 deletions
diff --git a/contrib/bsddialog/examples_library/calendar.c b/contrib/bsddialog/examples_library/calendar.c new file mode 100644 index 000000000000..5899fc4986fd --- /dev/null +++ b/contrib/bsddialog/examples_library/calendar.c @@ -0,0 +1,45 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2022 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> +#include <time.h> + +int main() +{ + int output; + unsigned int yy, mm, dd; + struct bsddialog_conf conf; + time_t cal; + struct tm *localtm; + + time(&cal); + localtm = localtime(&cal); + yy = localtm->tm_year + 1900; + mm = localtm->tm_mon + 1; + dd = localtm->tm_mday; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "calendar"; + output = bsddialog_calendar(&conf, "Example", 18, 40, &yy, &mm, &dd); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + + printf("Date: %u/%u/%u\n", yy, mm, dd); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/checklist.c b/contrib/bsddialog/examples_library/checklist.c new file mode 100644 index 000000000000..a2b178d14270 --- /dev/null +++ b/contrib/bsddialog/examples_library/checklist.c @@ -0,0 +1,45 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int i, output; + struct bsddialog_conf conf; + struct bsddialog_menuitem items[5] = { + {"i", true, 0, "Name 1", "Desc 1", "Bottom Desc 1"}, + {"ii", false, 0, "Name 2", "Desc 2", "Bottom Desc 2"}, + {"iii", true, 0, "Name 3", "Desc 3", "Bottom Desc 3"}, + {"iv", false, 0, "Name 4", "Desc 4", "Bottom Desc 4"}, + {"v", true, 0, "Name 5", "Desc 5", "Bottom Desc 5"} + }; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "checklist"; + output = bsddialog_checklist(&conf, "Example", 15, 30, 5, 5, items, + NULL); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + + printf("Checklist:\n"); + for (i = 0; i < 5; i++) + printf(" [%c] %s\n", items[i].on ? 'X' : ' ', items[i].name); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/compile b/contrib/bsddialog/examples_library/compile new file mode 100755 index 000000000000..1a68313090f6 --- /dev/null +++ b/contrib/bsddialog/examples_library/compile @@ -0,0 +1,23 @@ +#!/bin/sh +#- +# SPDX-License-Identifier: CC0-1.0 +# +# Written in 2021 by Alfonso Sabato Siciliano. +# To the extent possible under law, the author has dedicated all copyright +# and related and neighboring rights to this software to the public domain +# worldwide. This software is distributed without any warranty, see: +# <http://creativecommons.org/publicdomain/zero/1.0/>. + +set -x + +libpath=../lib +examples="menu checklist radiolist mixedlist theme infobox yesno msgbox \ +datebox form timebox rangebox pause calendar gauge mixedgauge textbox" + +rm -f $examples + +for e in $examples +do + cc -g -Wall -Wextra -I$libpath ${e}.c -o $e \ + -Wl,-rpath=$libpath -L$libpath -lbsddialog +done diff --git a/contrib/bsddialog/examples_library/datebox.c b/contrib/bsddialog/examples_library/datebox.c new file mode 100644 index 000000000000..e0741319d388 --- /dev/null +++ b/contrib/bsddialog/examples_library/datebox.c @@ -0,0 +1,44 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> +#include <time.h> + +int main() +{ + int output; + unsigned int yy, mm, dd; + struct bsddialog_conf conf; + time_t cal; + struct tm *localtm; + + time(&cal); + localtm = localtime(&cal); + yy = localtm->tm_year + 1900; + mm = localtm->tm_mon + 1; + dd = localtm->tm_mday; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "datebox"; + output = bsddialog_datebox(&conf, "Example", 9, 35, &yy, &mm, &dd); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + printf("Date: %u/%u/%u\n", yy, mm, dd); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/form.c b/contrib/bsddialog/examples_library/form.c new file mode 100644 index 000000000000..4c6336610852 --- /dev/null +++ b/contrib/bsddialog/examples_library/form.c @@ -0,0 +1,52 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> + +#define H BSDDIALOG_FIELDHIDDEN +#define RO BSDDIALOG_FIELDREADONLY + +int main() +{ + int i, output; + struct bsddialog_conf conf; + struct bsddialog_formitem items[3] = { + {"Input:", 0, 0, "value", 0, 10, 30, 50, NULL, 0, "desc 1"}, + {"Input:", 1, 0, "read only", 1, 10, 30, 50, NULL, RO, "desc 2"}, + {"Password:", 2, 0, "", 2, 10, 30, 50, NULL, H, "desc 3"} + }; + + /* Optional, unless for unicode/multi-column characters */ + setlocale(LC_ALL, ""); + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "form"; + conf.form.securech = '*'; + output = bsddialog_form(&conf, "Example", 10, 50, 3, 3, items, NULL); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s", bsddialog_geterror()); + return (1); + } + + for (i = 0; i < 3; i++) { + printf("%s \"%s\"\n", items[i].label, items[i].value); + free(items[i].value); + } + + return (0); +} diff --git a/contrib/bsddialog/examples_library/gauge.c b/contrib/bsddialog/examples_library/gauge.c new file mode 100644 index 000000000000..8ed1a8f57664 --- /dev/null +++ b/contrib/bsddialog/examples_library/gauge.c @@ -0,0 +1,57 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2023 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +static void sender(int fd) +{ + int i; + + for (i = 1; i <= 10; i++) { + sleep(1); + dprintf(fd, "SEP\n"); + dprintf(fd, "%d\n", i * 10); + dprintf(fd, "In Progress... [%d / 10]\n", i); + dprintf(fd, "SEP\n"); + } + sleep(1); + dprintf(fd, "EOF\n"); +} + +int main() +{ + int rv, fd[2]; + struct bsddialog_conf conf; + + /* add checks and sync */ + pipe(fd); + if (fork() == 0) { + close(fd[0]); + sender(fd[1]); + exit (0); + } + close(fd[1]); + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "gauge"; + rv = bsddialog_gauge(&conf, "Example", 7, 30, 0, fd[0], "SEP", "EOF"); + bsddialog_end(); + if (rv == BSDDIALOG_ERROR) + printf("Error: %s\n", bsddialog_geterror()); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/infobox.c b/contrib/bsddialog/examples_library/infobox.c new file mode 100644 index 000000000000..bbd7f665d5a6 --- /dev/null +++ b/contrib/bsddialog/examples_library/infobox.c @@ -0,0 +1,34 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int output; + struct bsddialog_conf conf; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "infobox"; + conf.sleep = 3; + output = bsddialog_infobox(&conf, "Example\n(3 seconds)", 7, 20); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/menu.c b/contrib/bsddialog/examples_library/menu.c new file mode 100644 index 000000000000..5c4941f6d5de --- /dev/null +++ b/contrib/bsddialog/examples_library/menu.c @@ -0,0 +1,44 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int i, output; + struct bsddialog_conf conf; + struct bsddialog_menuitem items[5] = { + {"I", true, 0, "Name 1", "Desc 1", "Bottom Desc 1"}, + {"II", false, 0, "Name 2", "Desc 2", "Bottom Desc 2"}, + {"III", true, 0, "Name 3", "Desc 3", "Bottom Desc 3"}, + {"IV", false, 0, "Name 4", "Desc 4", "Bottom Desc 4"}, + {"V", true, 0, "Name 5", "Desc 5", "Bottom Desc 5"} + }; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "menu"; + output = bsddialog_menu(&conf, "Example", 15, 30, 5, 5, items, NULL); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + + printf("Menu:\n"); + for (i = 0; i < 5; i++) + printf(" [%c] %s\n", items[i].on ? 'X' : ' ', items[i].name); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/mixedgauge.c b/contrib/bsddialog/examples_library/mixedgauge.c new file mode 100644 index 000000000000..e74bb3512a9a --- /dev/null +++ b/contrib/bsddialog/examples_library/mixedgauge.c @@ -0,0 +1,79 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2023 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> + +#define NMINIBAR 13 + +static const char *minilabels[NMINIBAR] = { + "Label 1", + "Label 2", + "Label 3", + "Label 4", + "Label 5", + "Label 6", + "Label 7", + "Label 8", + "Label 9", + "Label 10", + "Label 11", + "Label X", + "Label Y", +}; + +static int minipercs[NMINIBAR] = { + 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, + BSDDIALOG_MG_PENDING, + 67, + 0, +}; + +static void exit_error() +{ + if (bsddialog_inmode()) + bsddialog_end(); + printf("Error: %s\n", bsddialog_geterror()); + exit (1); +} + +int main() +{ + int retval, i; + struct bsddialog_conf conf; + + if (bsddialog_init() == BSDDIALOG_ERROR) + exit_error(); + bsddialog_initconf(&conf); + conf.title = "mixedgauge"; + for (i = 0; i <= 10; i++) { + minipercs[11] += 3; + minipercs[12] = i * 10; + retval= bsddialog_mixedgauge(&conf, "Example", 20, 40, + 50 + i * 5, NMINIBAR, minilabels, minipercs); + if (retval == BSDDIALOG_ERROR) + exit_error(); + sleep(1); + } + bsddialog_end(); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/mixedlist.c b/contrib/bsddialog/examples_library/mixedlist.c new file mode 100644 index 000000000000..6d286996931b --- /dev/null +++ b/contrib/bsddialog/examples_library/mixedlist.c @@ -0,0 +1,78 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int output; + unsigned int i, j; + struct bsddialog_conf conf; + struct bsddialog_menuitem item; + struct bsddialog_menuitem sep1[1] = { + { "", true, 0, "Checklist", "(desc)", "" } + }; + struct bsddialog_menuitem check[5] = { + { "+", true, 0, "Name 1", "Desc 1", "Bottom Desc 1" }, + { "" , false, 0, "Name 2", "Desc 2", "Bottom Desc 2" }, + { "+", true, 0, "Name 3", "Desc 3", "Bottom Desc 3" }, + { "" , false, 0, "Name 4", "Desc 4", "Bottom Desc 4" }, + { "+", true, 0, "Name 5", "Desc 5", "Bottom Desc 5" } + }; + struct bsddialog_menuitem sep2[2] = { + { "", true, 0, "Radiolist", "(desc)", "" }, + { "", true, 0, "Subtitle", "(desc)", "" } + }; + struct bsddialog_menuitem radio[5] = { + { "", true, 0, "Name 1", "Desc 1", "Bottom Desc 1" }, + { "+", false, 0, "Name 2", "Desc 2", "Bottom Desc 2" }, + { "", false, 0, "Name 3", "Desc 3", "Bottom Desc 3" }, + { "+", false, 0, "Name 4", "Desc 4", "Bottom Desc 4" }, + { "", false, 0, "Name 5", "Desc 5", "Bottom Desc 5" } + }; + struct bsddialog_menugroup group[4] = { + { BSDDIALOG_SEPARATOR, 1, sep1, 0 }, + { BSDDIALOG_CHECKLIST, 5, check, 0 }, + { BSDDIALOG_SEPARATOR, 2, sep2, 0 }, + { BSDDIALOG_RADIOLIST, 5, radio, 0 } + }; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "mixedlist"; + output = bsddialog_mixedlist(&conf, "Example", 20, 0, 13, 4, group, + NULL, NULL); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + + printf("Mixedlist:\n"); + for (i = 0; i < 4; i++) { + for (j = 0; j < group[i].nitems; j++) { + item = group[i].items[j]; + if (group[i].type == BSDDIALOG_SEPARATOR) + printf("----- %s -----\n", item.name); + else if (group[i].type == BSDDIALOG_RADIOLIST) + printf(" (%c) %s\n", + item.on ? '*' : ' ', item.name); + else /* BSDDIALOG_CHECKLIST */ + printf(" [%c] %s\n", + item.on ? 'X' : ' ', item.name); + } + } + + return (0); +} diff --git a/contrib/bsddialog/examples_library/msgbox.c b/contrib/bsddialog/examples_library/msgbox.c new file mode 100644 index 000000000000..988e2976ee8e --- /dev/null +++ b/contrib/bsddialog/examples_library/msgbox.c @@ -0,0 +1,38 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int output; + struct bsddialog_conf conf; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "msgbox"; + output = bsddialog_msgbox(&conf, "Example", 7, 20); + bsddialog_end(); + + switch (output) { + case BSDDIALOG_ERROR: + printf("Error %s\n", bsddialog_geterror()); + return (1); + case BSDDIALOG_OK: + printf("[OK]\n"); + break; + } + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/pause.c b/contrib/bsddialog/examples_library/pause.c new file mode 100644 index 000000000000..fd79d33aa4c0 --- /dev/null +++ b/contrib/bsddialog/examples_library/pause.c @@ -0,0 +1,46 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int output; + unsigned int sec; + struct bsddialog_conf conf; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "pause"; + sec = 10; + output = bsddialog_pause(&conf, "Example", 8, 50, &sec); + bsddialog_end(); + + switch (output) { + case BSDDIALOG_ERROR: + printf("Error: %s\n", bsddialog_geterror()); + return (1); + case BSDDIALOG_OK: + printf("[OK] remaining time: %u\n", sec); + break; + case BSDDIALOG_CANCEL: + printf("[Cancel] remaining time: %u\n", sec); + break; + case BSDDIALOG_TIMEOUT: + printf("Timeout\n"); + break; + } + + return (0); +} diff --git a/contrib/bsddialog/examples_library/radiolist.c b/contrib/bsddialog/examples_library/radiolist.c new file mode 100644 index 000000000000..09df32ac2e74 --- /dev/null +++ b/contrib/bsddialog/examples_library/radiolist.c @@ -0,0 +1,45 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int i, output; + struct bsddialog_conf conf; + struct bsddialog_menuitem items[5] = { + {"I", true, 0, "Name 1", "Desc 1", "Bottom Desc 1"}, + {"II", false, 0, "Name 2", "Desc 2", "Bottom Desc 2"}, + {"III", true, 0, "Name 3", "Desc 3", "Bottom Desc 3"}, + {"IV", false, 0, "Name 4", "Desc 4", "Bottom Desc 4"}, + {"V", true, 0, "Name 5", "Desc 5", "Bottom Desc 5"} + }; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "radiolist"; + output = bsddialog_radiolist(&conf, "Example", 15, 30, 5, 5, items, + NULL); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + + printf("Radiolist:\n"); + for (i = 0; i < 5; i++) + printf(" (%c) %s\n", items[i].on ? '*' : ' ', items[i].name); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/rangebox.c b/contrib/bsddialog/examples_library/rangebox.c new file mode 100644 index 000000000000..50498c459fc6 --- /dev/null +++ b/contrib/bsddialog/examples_library/rangebox.c @@ -0,0 +1,35 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int value, output; + struct bsddialog_conf conf; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "rangebox"; + value = 5; + output = bsddialog_rangebox(&conf, "Example", 8, 50, 0, 10, &value); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + printf("Value: %d\n", value); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/textbox.c b/contrib/bsddialog/examples_library/textbox.c new file mode 100644 index 000000000000..2e76cbb97891 --- /dev/null +++ b/contrib/bsddialog/examples_library/textbox.c @@ -0,0 +1,38 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2025 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int output; + struct bsddialog_conf conf; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "textbox"; + output = bsddialog_textbox(&conf, "./textbox.c", 20, 80); + bsddialog_end(); + + switch (output) { + case BSDDIALOG_ERROR: + printf("Error %s\n", bsddialog_geterror()); + return (1); + case BSDDIALOG_OK: + printf("[Exit]\n"); + break; + } + + return (0); +} diff --git a/contrib/bsddialog/examples_library/theme.c b/contrib/bsddialog/examples_library/theme.c new file mode 100644 index 000000000000..689633e624ed --- /dev/null +++ b/contrib/bsddialog/examples_library/theme.c @@ -0,0 +1,64 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <bsddialog_theme.h> +#include <stdio.h> + +int main() +{ + int output, focusitem; + struct bsddialog_conf conf; + enum bsddialog_default_theme theme; + struct bsddialog_menuitem items[4] = { + {"", false, 0, "Flat", "default flat theme", + "enum bsddialog_default_theme BSDDIALOG_THEME_FLAT" }, + {"", false, 0, "3D", "pseudo 3D theme", + "enum bsddialog_default_theme BSDDIALOG_THEME_3D" }, + {"", false, 0, "BlackWhite","black and white theme", + "enum bsddialog_default_theme BSDDIALOG_THEME_BLACKWHITE" }, + {"", false, 0, "Quit", "Exit", "Quit, Cancel or ESC to exit" } + }; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.ascii_lines = true; + bsddialog_backtitle(&conf, "Theme Example"); + bsddialog_initconf(&conf); + conf.key.enable_esc = true; + conf.title = " Theme "; + focusitem = -1; + while (true) { + output = bsddialog_menu(&conf, "Choose theme", 15, 45, 4, 4, + items, &focusitem); + + if (output != BSDDIALOG_OK || items[3].on) + break; + + if (items[0].on) { + theme = BSDDIALOG_THEME_FLAT; + focusitem = 0; + } else if (items[1].on) { + theme = BSDDIALOG_THEME_3D; + focusitem = 1; + } else if (items[2].on) { + theme = BSDDIALOG_THEME_BLACKWHITE; + focusitem = 2; + } + bsddialog_set_default_theme(theme); + } + + bsddialog_end(); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/timebox.c b/contrib/bsddialog/examples_library/timebox.c new file mode 100644 index 000000000000..a9354c99c9be --- /dev/null +++ b/contrib/bsddialog/examples_library/timebox.c @@ -0,0 +1,44 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> +#include <time.h> + +int main() +{ + int output; + unsigned int hh, mm, ss; + struct bsddialog_conf conf; + time_t clock; + struct tm *localtm; + + time(&clock); + localtm = localtime(&clock); + hh = localtm->tm_hour; + mm = localtm->tm_min; + ss = localtm->tm_sec; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "timebox"; + output = bsddialog_timebox(&conf, "Example", 9, 35, &hh, &mm, &ss); + bsddialog_end(); + if (output == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + printf("Time: %u:%u:%u\n", hh, mm, ss); + + return (0); +}
\ No newline at end of file diff --git a/contrib/bsddialog/examples_library/yesno.c b/contrib/bsddialog/examples_library/yesno.c new file mode 100644 index 000000000000..36cb59fa013b --- /dev/null +++ b/contrib/bsddialog/examples_library/yesno.c @@ -0,0 +1,41 @@ +/*- + * SPDX-License-Identifier: CC0-1.0 + * + * Written in 2021 by Alfonso Sabato Siciliano. + * To the extent possible under law, the author has dedicated all copyright + * and related and neighboring rights to this software to the public domain + * worldwide. This software is distributed without any warranty, see: + * <http://creativecommons.org/publicdomain/zero/1.0/>. + */ + +#include <bsddialog.h> +#include <stdio.h> + +int main() +{ + int output; + struct bsddialog_conf conf; + + if (bsddialog_init() == BSDDIALOG_ERROR) { + printf("Error: %s\n", bsddialog_geterror()); + return (1); + } + bsddialog_initconf(&conf); + conf.title = "yesno"; + output = bsddialog_yesno(&conf, "Example", 7, 25); + bsddialog_end(); + + switch (output) { + case BSDDIALOG_ERROR: + printf("Error %s\n", bsddialog_geterror()); + return (1); + case BSDDIALOG_YES: + printf("[YES]\n"); + break; + case BSDDIALOG_NO: + printf("[NO]\n"); + break; + } + + return (0); +}
\ No newline at end of file |
