aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--CHANGELOG61
-rw-r--r--GNUMakefile2
-rw-r--r--Makefile8
-rw-r--r--README.md5
-rw-r--r--bsddialog.112
-rw-r--r--bsddialog.c107
-rw-r--r--examples_library/checklist.c3
-rwxr-xr-xexamples_library/compile2
-rw-r--r--examples_library/datebox.c8
-rw-r--r--examples_library/form.c4
-rw-r--r--examples_library/formw.c61
-rw-r--r--examples_library/infobox.c3
-rw-r--r--examples_library/menu.c3
-rw-r--r--examples_library/mixedlist.c20
-rw-r--r--examples_library/msgbox.c3
-rw-r--r--examples_library/pause.c3
-rw-r--r--examples_library/radiolist.c3
-rw-r--r--examples_library/rangebox.c3
-rw-r--r--examples_library/theme.c13
-rw-r--r--examples_library/timebox.c8
-rw-r--r--examples_library/yesno.c3
-rwxr-xr-xexamples_utility/checklist.sh27
-rwxr-xr-xexamples_utility/form.sh27
-rwxr-xr-xexamples_utility/gauge.sh4
-rwxr-xr-xexamples_utility/infobox.sh3
-rwxr-xr-xexamples_utility/inputbox.sh30
-rwxr-xr-xexamples_utility/menu.sh28
-rwxr-xr-xexamples_utility/mixedform.sh36
-rwxr-xr-xexamples_utility/mixedgauge.sh3
-rwxr-xr-xexamples_utility/msgbox.sh19
-rwxr-xr-xexamples_utility/passwordbox.sh30
-rwxr-xr-xexamples_utility/passwordform.sh30
-rwxr-xr-xexamples_utility/pause.sh36
-rwxr-xr-xexamples_utility/radiolist.sh29
-rwxr-xr-xexamples_utility/timebox.sh34
-rwxr-xr-xexamples_utility/treeview.sh17
-rwxr-xr-xexamples_utility/yesno.sh23
-rw-r--r--lib/GNUMakefile5
-rw-r--r--lib/Makefile11
-rw-r--r--lib/barbox.c54
-rw-r--r--lib/bsddialog.343
-rw-r--r--lib/bsddialog.h7
-rw-r--r--lib/bsddialog_theme.h11
-rw-r--r--lib/formbox.c108
-rw-r--r--lib/infobox.c3
-rw-r--r--lib/lib_util.c59
-rw-r--r--lib/lib_util.h10
-rw-r--r--lib/libbsddialog.c9
-rw-r--r--lib/menubox.c118
-rw-r--r--lib/messagebox.c9
-rw-r--r--lib/textbox.c5
-rw-r--r--lib/theme.c60
-rw-r--r--lib/timebox.c165
54 files changed, 957 insertions, 432 deletions
diff --git a/.gitignore b/.gitignore
index 557ad3300d1f..62f7b594a708 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@ examples_library/buildlist
examples_library/checklist
examples_library/datebox
examples_library/form
+examples_library/formw
examples_library/menu
examples_library/mixedlist
examples_library/radiolist
diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 000000000000..22eb3342cfe2
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,61 @@
+2022-03-02 version 0.2
+
+ Utility:
+ * add: (this) CHANGELOG.
+ * add: "menus" print item with focus (except with OK and ERROR).
+ * add: pause.sh example.
+ * add: timebox.sh example.
+ * change: --theme name "default" -> "flat".
+ * delete: treeview.sh example.
+ * fix: --separate-output does not quote (except with --quoted).
+ * fix: --datebox and --date-format month in output.
+ * improve: examples handle exit status.
+
+ Library:
+ * add: conf.form.enable_wchar for wide characters in bsddialog_form().
+ * add: theme.menu.f_selectorcolor.
+ * add: formw.c example.
+ * change: move conf.f1_file and conf.f1_message in conf.key.
+ * change: theme.button.[left|right]ch -> theme.button.[left|right]delim.
+ * change: theme.button.space -> theme.button.hmargin.
+ * change: theme.menu.arrowcolor -> theme.dialog.arrowcolor.
+ * change: default menu item depth 4 -> 2.
+ * fix: disable HOME, PPAGE, END and NPAGE keys in bsddialog_form().
+ * fix: visible cursor for timebox.c and form.c in VM VirtualBox.
+ * fix: mixedlist, center position of separator with big pad.
+ * fix: timebox and datebox set values only with BSDDIALOG_OK.
+ * fix: menurows autosize with fullscreen.
+ * fix: bar color with 0%.
+ * fix: bar label position.
+ * improve: timebox and datebox navigation (keys, buttons and shortcuts).
+ * improve: "menus" colors for accessibility.
+
+
+2022-01-27 version 0.1
+
+ * Common-Options: --ascii-lines, --backtitle <backtitle>, --begin-x <x>,
+ --begin-y <y>, --cancel-label <label>, --clear, --colors, --cr-wrap,
+ --date-format <format>, --defaultno, --default-button <label>,
+ --default-no, --default-item <name>, --disable-esc,
+ --esc-cancelvalue, --exit-label <label>, --extra-button,
+ --extra-label <label>, --generic-button1 <label>,
+ --generic-button2 <label>, --help, --help-button,
+ --help-label <label>, --help-status, --help-tags,
+ --hfile <filename>, --hline <string>, --hmsg <string>, --ignore,
+ --insecure, --item-depth, --item-help, --items-prefix,
+ --max-input <size>, --no-cancel, --nocancel, --no-collapse,
+ --no-items, --no-label <label>, --no-lines, --no-nl-expand,
+ --no-ok, --nook, --no-shadow, --no-tags, --ok-label <label>,
+ --output-fd <fd>, --output-separator <sep>, --print-maxsize,
+ --print-size, --print-version, --quoted, --separate-output,
+ --separator <sep>, --shadow, --single-quoted, --sleep <secs>,
+ --stderr, --stdout, --tab-len <spaces>,
+ --theme <blackwhite|bsddialog|default|dialog>,
+ --time-format <format>, --title <title>, --trim, --version,
+ --yes-label <label>.
+ * Dialogs: --checklist, --datebox, --form, --gauge, --infobox,
+ --inputbox, --menu, --mixedform, --mixedgauge, --msgbox,
+ --passwordbox, --passwordform, --pause, --radiolist, --rangebox,
+ --textbox, --timebox, --treeview, --yesno.
+ * Manuals: bsddialog.1, bsddialog.3.
+
diff --git a/GNUMakefile b/GNUMakefile
index 69cec29d6a67..ad3d4f55f4a7 100644
--- a/GNUMakefile
+++ b/GNUMakefile
@@ -8,7 +8,7 @@ SOURCES= bsddialog.c
OBJECTS= $(SOURCES:.c=.o)
LIBPATH= ./lib
LIBBSDDIALOG= $(LIBPATH)/libbsddialog.so
-CFLAGS= -Wall -I$(LIBPATH)
+CFLAGS= -Wall -Wextra -Wno-unused-parameter -I$(LIBPATH)
LDFLAGS= -Wl,-rpath=$(LIBPATH) -L$(LIBPATH) -lbsddialog
RM = rm -f
diff --git a/Makefile b/Makefile
index 2abfb9e27cd7..5d5d0cc923a5 100644
--- a/Makefile
+++ b/Makefile
@@ -9,13 +9,7 @@ OBJECTS= ${SOURCES:.c=.o}
LIBPATH= ${.CURDIR}/lib
LIBBSDDIALOG= ${LIBPATH}/libbsddialog.so
-CFLAGS+= -I${LIBPATH} -std=gnu99 -Wno-format-zero-length \
--fstack-protector-strong -Wsystem-headers -Werror -Wall -Wno-format-y2k -W \
--Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith \
--Wno-uninitialized -Wno-pointer-sign -Wno-empty-body -Wno-string-plus-int \
--Wno-unused-const-variable -Wno-tautological-compare -Wno-unused-value \
--Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion \
--Wno-unused-local-typedef -Wno-address-of-packed-member -Qunused-arguments
+CFLAGS+= -I${LIBPATH} -std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter
# `make -DDEBUG`
.if defined(DEBUG)
CFLAGS= -g -Wall -I${LIBPATH}
diff --git a/README.md b/README.md
index 17af3a0db8e5..3a814b38ddb4 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# BSDDialog 0.1
+# BSDDialog 0.2
This project provides **bsddialog** and **libbsddialog**, an utility and a
@@ -75,8 +75,9 @@ in the _Public Domain_ to build new projects:
% sh ./examples_utility/msgbox.sh
% sh ./examples_utility/passwordbox.sh
% sh ./examples_utility/passwordform.sh
+% sh ./examples_utility/pause.sh
% sh ./examples_utility/radiolist.sh
-% sh ./examples_utility/treeview.sh
+% sh ./examples_utility/timebox.sh
% sh ./examples_utility/yesno.sh
```
diff --git a/bsddialog.1 b/bsddialog.1
index c426c529e242..c87b760d2ea3 100644
--- a/bsddialog.1
+++ b/bsddialog.1
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd January 26, 2022
+.Dd February 3, 2022
.Dt BSDDIALOG 1
.Os
.Sh NAME
@@ -34,12 +34,12 @@
.Nm
.Fl Fl version
.Nm
-.Op Fl Fl common-opts
+.Op Fl Fl common-option
.Fl Fl dialog
.Ar text
.Ar rows
.Ar cols
-.Op Ar dialog-opts
+.Op Ar dialog-parameter
.Sh DESCRIPTION
The
.Nm bsddialog
@@ -263,7 +263,7 @@ Print version.
.It Fl Fl quoted
Quote items in output, default only when necessary.
.It Fl Fl separate-output
-Separate selected items with a new line.
+Separate selected items with a new line and avoid to quote.
.It Fl Fl separator Ar sep
Equivalent to
.Fl Fl output-separator .
@@ -283,7 +283,7 @@ Print input from user interface to standard output.
Number of spaces to print a TAB in
.Ar text .
.It Fl Fl theme Ar theme
-Set a graphical style: blackwhite, bsddialog, default or dialog.
+Set a graphical style: blackwhite, bsddialog, flat or dialog.
.It Fl Fl time-format Ar format
String accepted by
.Xr strftime 3
@@ -586,5 +586,5 @@ utility first appeared in
was written by
.An Alfonso Sabato Siciliano Aq Mt alf.siciliano@gmail.com .
.Sh BUGS
-The forms do not resize the dialog after a terminal change and does not provides
+Forms do not resize the dialog after a terminal change and do not provide
scrolling for items. \ No newline at end of file
diff --git a/bsddialog.c b/bsddialog.c
index 6bd11fd458b8..a902d751dab0 100644
--- a/bsddialog.c
+++ b/bsddialog.c
@@ -39,7 +39,7 @@
#include <bsddialog.h>
#include <bsddialog_theme.h>
-#define BSDDIALOG_VERSION "0.1"
+#define BSDDIALOG_VERSION "0.2"
enum OPTS {
/* Common options */
@@ -125,22 +125,22 @@ enum OPTS {
YESNO
};
-/* Menus flags and options */
+/* Menus options */
static bool item_prefix_opt, item_bottomdesc_opt, item_output_sepnl_opt;
static bool item_singlequote_opt, list_items_on_opt, item_tag_help_opt;
static bool item_always_quote_opt, item_depth_opt;
static char *item_output_sep_opt, *item_default_opt;
-/* Time and calendar options */
+/* Date and Time options */
static char *date_fmt_opt, *time_fmt_opt;
-/* Forms */
+/* Forms options */
static int unsigned max_input_form_opt;
-/* General flags and options */
+/* General options */
static int output_fd_opt;
static void
custom_text(bool cr_wrap, bool no_collapse, bool no_nl_expand, bool trim,
char *text, char *buf);
-
+
static void sigint_handler(int sig);
/* Dialogs */
@@ -192,7 +192,7 @@ static void usage(void)
"--print-size, --print-version, --quoted, --separate-output, "
"--separator <sep>, --shadow, --single-quoted, --sleep <secs>, "
"--stderr, --stdout, --tab-len <spaces>, "
- "--theme <blackwhite|bsddialog|default|dialog>, "
+ "--theme <blackwhite|bsddialog|flat|dialog>, "
"--time-format <format>, --title <title>, --trim, --version, "
"--yes-label <label>.\n");
printf("\n");
@@ -239,7 +239,8 @@ int main(int argc, char *argv[argc])
int input, rows, cols, output, getH, getW;
int (*dialogbuilder)(BUILDER_ARGS) = NULL;
enum bsddialog_default_theme theme_opt;
- char *text, *backtitle_opt, errorbuilder[1024];
+ char *text, *backtitle_opt;
+ char errorbuilder[1024];
struct winsize ws;
struct bsddialog_conf conf;
@@ -249,15 +250,16 @@ int main(int argc, char *argv[argc])
conf.key.enable_esc = true;
conf.menu.on_without_ok = true;
conf.form.value_without_ok = true;
+ conf.form.enable_wchar = true;
backtitle_opt = NULL;
- theme_opt = BSDDIALOG_THEME_DEFAULT;
+ theme_opt = BSDDIALOG_THEME_FLAT;
output_fd_opt = STDERR_FILENO;
print_maxsize_opt = false;
ignore_opt = false;
- errorbuilder[0] = '\0';
cr_wrap_opt = no_collapse_opt = no_nl_expand_opt = trim_opt = false;
esc_cancelvalue_opt = false;
+ errorbuilder[0] = '\0';
item_output_sepnl_opt = item_singlequote_opt = false;
item_prefix_opt = item_bottomdesc_opt = item_depth_opt = false;
@@ -375,7 +377,7 @@ int main(int argc, char *argv[argc])
case BEGIN_X:
conf.x = (int)strtol(optarg, NULL, 10);
if (conf.x < BSDDIALOG_CENTER) {
- printf("Error: --begin-x %d < %d",
+ printf("Error: --begin-x %d < %d",
conf.x, BSDDIALOG_CENTER);
return (255);
}
@@ -449,13 +451,13 @@ int main(int argc, char *argv[argc])
item_tag_help_opt = true;
break;
case HFILE:
- conf.f1_file = optarg;
+ conf.key.f1_file = optarg;
break;
case HLINE:
conf.bottomtitle = optarg;
break;
case HMSG:
- conf.f1_message = optarg;
+ conf.key.f1_message = optarg;
break;
case IGNORE:
ignore_opt = true;
@@ -515,7 +517,7 @@ int main(int argc, char *argv[argc])
print_maxsize_opt = true;
break;
case PRINT_SIZE:
- conf.get_height = &getH;;
+ conf.get_height = &getH;
conf.get_width = &getW;
break;
case PRINT_VERSION:
@@ -547,8 +549,8 @@ int main(int argc, char *argv[argc])
theme_opt = BSDDIALOG_THEME_BSDDIALOG;
else if (strcasecmp(optarg, "blackwhite") == 0)
theme_opt = BSDDIALOG_THEME_BLACKWHITE;
- else if (strcasecmp(optarg, "default") == 0)
- theme_opt = BSDDIALOG_THEME_DEFAULT;
+ else if (strcasecmp(optarg, "flat") == 0)
+ theme_opt = BSDDIALOG_THEME_FLAT;
else if (strcasecmp(optarg, "dialog") == 0)
theme_opt = BSDDIALOG_THEME_DIALOG;
else {
@@ -673,12 +675,13 @@ int main(int argc, char *argv[argc])
signal(SIGINT, sigint_handler);
- if (theme_opt != BSDDIALOG_THEME_DEFAULT)
+ if (theme_opt != BSDDIALOG_THEME_FLAT)
bsddialog_set_default_theme(theme_opt);
if (backtitle_opt != NULL)
bsddialog_backtitle(&conf, backtitle_opt);
+ errorbuilder[0] = '\0';
output = BSDDIALOG_OK;
if (dialogbuilder != NULL)
output = dialogbuilder(conf, text, rows, cols, argc, argv,
@@ -859,8 +862,8 @@ int rangebox_builder(BUILDER_ARGS)
int output, min, max, value;
if (argc < 2) {
- strcpy(errbuf, "usage --rangebox <text> <rows> <cols> <min> "
- "<max> [<init>]\n");
+ strcpy(errbuf, "usage --rangebox <text> <rows> <cols> "
+ "<min> <max> [<init>]\n");
return (BSDDIALOG_ERROR);
}
@@ -931,7 +934,7 @@ int datebox_builder(BUILDER_ARGS)
time(&cal);
localtm = localtime(&cal);
localtm->tm_year = yy - 1900;
- localtm->tm_mon = mm;
+ localtm->tm_mon = mm - 1;
localtm->tm_mday = dd;
strftime(stringdate, 1024, date_fmt_opt, localtm);
dprintf(output_fd_opt, "%s", stringdate);
@@ -970,7 +973,7 @@ int timebox_builder(BUILDER_ARGS)
time(&clock);
localtm = localtime(&clock);
localtm->tm_hour = hh;
- localtm->tm_min = mm;
+ localtm->tm_min = mm;
localtm->tm_sec = ss;
strftime(stringtime, 1024, time_fmt_opt, localtm);
dprintf(output_fd_opt, "%s", stringtime);
@@ -1031,31 +1034,36 @@ get_menu_items(char *errbuf, int argc, char **argv, bool setprefix,
}
static void
-print_menu_items(struct bsddialog_conf *conf, int output, int nitems,
- struct bsddialog_menuitem *items, int focusitem)
+print_menu_items(int output, int nitems, struct bsddialog_menuitem *items,
+ int focusitem)
{
bool sep, toquote;
int i;
char *sepstr, quotech;
- const char *helpvalue;
+ const char *focusname;
sep = false;
quotech = item_singlequote_opt ? '\'' : '"';
sepstr = item_output_sep_opt != NULL ? item_output_sep_opt : " ";
- if (output == BSDDIALOG_HELP && focusitem >= 0) {
- dprintf(output_fd_opt, "HELP ");
+ if (output != BSDDIALOG_OK && output != BSDDIALOG_ERROR &&
+ focusitem >= 0) {
+ focusname = items[focusitem].name;
- helpvalue = items[focusitem].name;
- if (item_bottomdesc_opt && item_tag_help_opt == false)
- helpvalue = items[focusitem].bottomdesc;
+ if (output == BSDDIALOG_HELP) {
+ dprintf(output_fd_opt, "HELP ");
+
+ if (item_bottomdesc_opt && item_tag_help_opt == false)
+ focusname = items[focusitem].bottomdesc;
+ }
toquote = item_always_quote_opt ||
- strchr(helpvalue, ' ') != NULL;
+ (item_output_sepnl_opt == false &&
+ strchr(focusname, ' ') != NULL);
if (toquote)
dprintf(output_fd_opt, "%c", quotech);
- dprintf(output_fd_opt, "%s", helpvalue);
+ dprintf(output_fd_opt, "%s", focusname);
if (toquote)
dprintf(output_fd_opt, "%c", quotech);
@@ -1078,7 +1086,8 @@ print_menu_items(struct bsddialog_conf *conf, int output, int nitems,
sep = true;
toquote = item_always_quote_opt ||
- strchr(items[i].name, ' ') != NULL;
+ (item_output_sepnl_opt == false &&
+ strchr(items[i].name, ' ') != NULL);
if (toquote)
dprintf(output_fd_opt, "%c", quotech);
@@ -1110,7 +1119,7 @@ int checklist_builder(BUILDER_ARGS)
output = bsddialog_checklist(&conf, text, rows, cols, menurows, nitems,
items, &focusitem);
- print_menu_items(&conf, output, nitems, items, focusitem);
+ print_menu_items(output, nitems, items, focusitem);
free(items);
@@ -1139,7 +1148,7 @@ int menu_builder(BUILDER_ARGS)
output = bsddialog_menu(&conf, text, rows, cols, menurows, nitems,
items, &focusitem);
- print_menu_items(&conf, output, nitems, items, focusitem);
+ print_menu_items(output, nitems, items, focusitem);
free(items);
@@ -1168,7 +1177,7 @@ int radiolist_builder(BUILDER_ARGS)
output = bsddialog_radiolist(&conf, text, rows, cols, menurows, nitems,
items, &focusitem);
- print_menu_items(&conf, output, nitems, items, focusitem);
+ print_menu_items(output, nitems, items, focusitem);
free(items);
@@ -1188,8 +1197,9 @@ int treeview_builder(BUILDER_ARGS)
menurows = (u_int)strtoul(argv[0], NULL, 10);
- output = get_menu_items(errbuf, argc-1, argv+1, item_prefix_opt, true,
- true, true, true, item_bottomdesc_opt, &nitems, &items, &focusitem);
+ output = get_menu_items(errbuf, argc-1, argv+1, item_prefix_opt,
+ true, true, true, true, item_bottomdesc_opt, &nitems, &items,
+ &focusitem);
if (output != 0)
return (output);
@@ -1199,7 +1209,7 @@ int treeview_builder(BUILDER_ARGS)
output = bsddialog_radiolist(&conf, text, rows, cols, menurows, nitems,
items, &focusitem);
- print_menu_items(&conf, output, nitems, items, focusitem);
+ print_menu_items(output, nitems, items, focusitem);
free(items);
@@ -1220,8 +1230,7 @@ alloc_formitems(int nitems, struct bsddialog_formitem **items, char *errbuf)
}
static void
-print_form_items(struct bsddialog_conf *conf, int output, int nitems,
- struct bsddialog_formitem *items)
+print_form_items(int output, int nitems, struct bsddialog_formitem *items)
{
int i;
@@ -1229,7 +1238,7 @@ print_form_items(struct bsddialog_conf *conf, int output, int nitems,
return;
for (i = 0; i < nitems; i++) {
- dprintf(output_fd_opt, "%s\n", items[i].value);
+ dprintf(output_fd_opt, "%ls\n", (wchar_t*)items[i].value);
free(items[i].value);
}
}
@@ -1241,7 +1250,7 @@ int form_builder(BUILDER_ARGS)
struct bsddialog_formitem *items;
sizeitem = item_bottomdesc_opt ? 9 : 8;
- if (argc < 1 || (((argc-1) % sizeitem) != 0)) {
+ if (argc < 1 || (argc - 1) % sizeitem != 0) {
strcpy(errbuf, "bad number of arguments for this form\n");
return (BSDDIALOG_ERROR);
}
@@ -1278,7 +1287,7 @@ int form_builder(BUILDER_ARGS)
output = bsddialog_form(&conf, text, rows, cols, formheight, nitems,
items);
- print_form_items(&conf, output, nitems, items);
+ print_form_items(output, nitems, items);
free(items);
return (output);
@@ -1301,7 +1310,7 @@ int inputbox_builder(BUILDER_ARGS)
item.bottomdesc = "";
output = bsddialog_form(&conf, text, rows, cols, 1, 1, &item);
- print_form_items(&conf, output, 1, &item);
+ print_form_items(output, 1, &item);
return (output);
}
@@ -1313,7 +1322,7 @@ int mixedform_builder(BUILDER_ARGS)
struct bsddialog_formitem *items;
sizeitem = item_bottomdesc_opt ? 10 : 9;
- if (argc < 1 || (((argc-1) % sizeitem) != 0)) {
+ if (argc < 1 || (argc-1) % sizeitem != 0) {
strcpy(errbuf, "bad number of arguments for this form\n");
return (BSDDIALOG_ERROR);
}
@@ -1342,7 +1351,7 @@ int mixedform_builder(BUILDER_ARGS)
output = bsddialog_form(&conf, text, rows, cols, formheight, nitems,
items);
- print_form_items(&conf, output, nitems, items);
+ print_form_items(output, nitems, items);
free(items);
return (output);
@@ -1365,7 +1374,7 @@ int passwordbox_builder(BUILDER_ARGS)
item.bottomdesc = "";
output = bsddialog_form(&conf, text, rows, cols, 1, 1, &item);
- print_form_items(&conf, output, 1, &item);
+ print_form_items(output, 1, &item);
return (output);
}
@@ -1377,7 +1386,7 @@ int passwordform_builder(BUILDER_ARGS)
struct bsddialog_formitem *items;
sizeitem = item_bottomdesc_opt ? 9 : 8;
- if (argc < 1 || (((argc-1) % sizeitem) != 0) ) {
+ if (argc < 1 || (argc - 1) % sizeitem != 0) {
strcpy(errbuf, "bad number of arguments for this form\n");
return (BSDDIALOG_ERROR);
}
@@ -1414,7 +1423,7 @@ int passwordform_builder(BUILDER_ARGS)
output = bsddialog_form(&conf, text, rows, cols, formheight, nitems,
items);
- print_form_items(&conf, output, nitems, items);
+ print_form_items(output, nitems, items);
free(items);
return (output);
diff --git a/examples_library/checklist.c b/examples_library/checklist.c
index 7851383d0553..6d860b91a076 100644
--- a/examples_library/checklist.c
+++ b/examples_library/checklist.c
@@ -8,11 +8,10 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
-#include <bsddialog.h>
-
int main()
{
int i, output;
diff --git a/examples_library/compile b/examples_library/compile
index 945d906cd43c..3c3961d06baf 100755
--- a/examples_library/compile
+++ b/examples_library/compile
@@ -10,7 +10,7 @@
libpath=../lib
examples="menu checklist radiolist mixedlist theme infobox yesno msgbox \
- datebox form timebox rangebox pause"
+ datebox form formw timebox rangebox pause"
for e in $examples
do
diff --git a/examples_library/datebox.c b/examples_library/datebox.c
index d2af7bd7fae0..a3c8946b7f79 100644
--- a/examples_library/datebox.c
+++ b/examples_library/datebox.c
@@ -8,12 +8,11 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
-#include <bsddialog.h>
-
int main()
{
int output;
@@ -35,8 +34,9 @@ int main()
bsddialog_initconf(&conf);
conf.title = "datebox";
- conf.bottomtitle = "Press TAB and arrows";
- output = bsddialog_datebox(&conf, "Example", 10, 50, &yy, &mm, &dd);
+ output = bsddialog_datebox(&conf,
+ "TAB / RIGHT / LEFT to move,\nUP / DOWN to select time", 10, 35,
+ &yy, &mm, &dd);
bsddialog_end();
diff --git a/examples_library/form.c b/examples_library/form.c
index 9bc7b0ccbe58..0256975f2023 100644
--- a/examples_library/form.c
+++ b/examples_library/form.c
@@ -8,13 +8,11 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
-
+#include <bsddialog.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <bsddialog.h>
-
#define H BSDDIALOG_FIELDHIDDEN
#define RO BSDDIALOG_FIELDREADONLY
diff --git a/examples_library/formw.c b/examples_library/formw.c
new file mode 100644
index 000000000000..edbeec98f2a3
--- /dev/null
+++ b/examples_library/formw.c
@@ -0,0 +1,61 @@
+/*-
+ * 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 <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define H BSDDIALOG_FIELDHIDDEN
+#define RO BSDDIALOG_FIELDREADONLY
+
+int main()
+{
+ int i, output;
+ struct bsddialog_conf conf;
+ struct bsddialog_formitem items[3] = {
+ {"Input:", 1, 1, "value", 1, 11, 30, 50, NULL, 0, "desc 1"},
+ {"Input:", 2, 1, "read only", 2, 11, 30, 50, NULL, RO, "desc 2"},
+ {"Password:", 3, 1, "", 3, 11, 30, 50, NULL, H, "desc 3"}
+ };
+
+ 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 = '*';
+ conf.form.enable_wchar = true;
+ output = bsddialog_form(&conf, "Example", 10, 50, 3, 3, items);
+
+ bsddialog_end();
+
+ if (output == BSDDIALOG_ERROR) {
+ printf("Error: %s", bsddialog_geterror());
+ return (1);
+ }
+
+ if (output == BSDDIALOG_CANCEL) {
+ printf("Cancel\n");
+ return (0);
+ }
+
+ for (i = 0; i < 3; i++) {
+ printf("%s \"%ls\"\n", items[i].label, (wchar_t*)items[i].value);
+ free(items[i].value);
+ }
+
+ return (output);
+} \ No newline at end of file
diff --git a/examples_library/infobox.c b/examples_library/infobox.c
index c022fa755fc6..7334cd7536bf 100644
--- a/examples_library/infobox.c
+++ b/examples_library/infobox.c
@@ -8,11 +8,10 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
-#include <bsddialog.h>
-
int main()
{
int output;
diff --git a/examples_library/menu.c b/examples_library/menu.c
index 6a2abe2aaadb..044e0030a010 100644
--- a/examples_library/menu.c
+++ b/examples_library/menu.c
@@ -8,11 +8,10 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
-#include <bsddialog.h>
-
int main()
{
int i, output;
diff --git a/examples_library/mixedlist.c b/examples_library/mixedlist.c
index 7f299218cb62..30198d20a155 100644
--- a/examples_library/mixedlist.c
+++ b/examples_library/mixedlist.c
@@ -8,17 +8,19 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
-#include <bsddialog.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" },
@@ -26,8 +28,9 @@ int main()
{ "" , false, 0, "Name 4", "Desc 4", "Bottom Desc 4" },
{ "+", true, 0, "Name 5", "Desc 5", "Bottom Desc 5" }
};
- struct bsddialog_menuitem sep[1] = {
- { "", true, 0, "Radiolist", "(desc)", "" }
+ 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" },
@@ -36,9 +39,10 @@ int main()
{ "+", false, 0, "Name 4", "Desc 4", "Bottom Desc 4" },
{ "", false, 0, "Name 5", "Desc 5", "Bottom Desc 5" }
};
- struct bsddialog_menugroup group[3] = {
+ struct bsddialog_menugroup group[4] = {
+ { BSDDIALOG_SEPARATOR, 1, sep1 },
{ BSDDIALOG_CHECKLIST, 5, check },
- { BSDDIALOG_SEPARATOR, 1, sep },
+ { BSDDIALOG_SEPARATOR, 2, sep2 },
{ BSDDIALOG_RADIOLIST, 5, radio }
};
@@ -49,7 +53,7 @@ int main()
bsddialog_initconf(&conf);
conf.title = "mixedlist";
- output = bsddialog_mixedlist(&conf, "Example", 20, 30, 11, 3, group,
+ output = bsddialog_mixedlist(&conf, "Example", 20, 0, 13, 4, group,
NULL, NULL);
bsddialog_end();
@@ -65,7 +69,7 @@ int main()
}
printf("Mixedlist:\n");
- for (i = 0; i < 3; i++) {
+ 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)
diff --git a/examples_library/msgbox.c b/examples_library/msgbox.c
index 32696894aa85..7d14073143ca 100644
--- a/examples_library/msgbox.c
+++ b/examples_library/msgbox.c
@@ -8,11 +8,10 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
-#include <bsddialog.h>
-
int main()
{
int output;
diff --git a/examples_library/pause.c b/examples_library/pause.c
index 62c35afb0192..1cd64f24a0cd 100644
--- a/examples_library/pause.c
+++ b/examples_library/pause.c
@@ -8,11 +8,10 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
-#include <bsddialog.h>
-
int main()
{
int output;
diff --git a/examples_library/radiolist.c b/examples_library/radiolist.c
index 79da63ad749f..ac8ed5bb4064 100644
--- a/examples_library/radiolist.c
+++ b/examples_library/radiolist.c
@@ -8,11 +8,10 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
-#include <bsddialog.h>
-
int main()
{
int i, output;
diff --git a/examples_library/rangebox.c b/examples_library/rangebox.c
index 06a62cc4b858..8e6bf91c35a6 100644
--- a/examples_library/rangebox.c
+++ b/examples_library/rangebox.c
@@ -8,11 +8,10 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
-#include <bsddialog.h>
-
int main()
{
int value, output;
diff --git a/examples_library/theme.c b/examples_library/theme.c
index fb09aa1d1b24..fcc5fd5cc31a 100644
--- a/examples_library/theme.c
+++ b/examples_library/theme.c
@@ -8,11 +8,10 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
-#include <stdio.h>
-#include <string.h>
-
#include <bsddialog.h>
#include <bsddialog_theme.h>
+#include <stdio.h>
+#include <string.h>
int main()
{
@@ -20,8 +19,8 @@ int main()
struct bsddialog_conf conf;
enum bsddialog_default_theme theme;
struct bsddialog_menuitem items[5] = {
- {"", false, 0, "Default", "dialog-like",
- "BSDDIALOG_THEME_DEFAULT" },
+ {"", false, 0, "Flat", "dialog-like",
+ "BSDDIALOG_THEME_FLAT" },
{"", false, 0, "Dialog", "dialog clone",
"BSDDIALOG_THEME_DIALOG" },
{"", false, 0, "BSDDialog", "new theme",
@@ -43,14 +42,14 @@ int main()
conf.title = " Theme ";
focusitem = -1;
while (true) {
- output = bsddialog_menu(&conf, "Choose theme", 15, 40, 5, 5,
+ output = bsddialog_menu(&conf, "Choose theme", 15, 45, 5, 5,
items, &focusitem);
if (output != BSDDIALOG_OK || items[4].on)
break;
if (items[0].on) {
- theme = BSDDIALOG_THEME_DEFAULT;
+ theme = BSDDIALOG_THEME_FLAT;
focusitem = 0;
}
else if (items[1].on) {
diff --git a/examples_library/timebox.c b/examples_library/timebox.c
index 6e3721ea9188..0e27f824af11 100644
--- a/examples_library/timebox.c
+++ b/examples_library/timebox.c
@@ -8,12 +8,11 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
-#include <bsddialog.h>
-
int main()
{
int output;
@@ -35,8 +34,9 @@ int main()
bsddialog_initconf(&conf);
conf.title = "timebox";
- conf.bottomtitle = "Press TAB and arrows";
- output = bsddialog_timebox(&conf, "Example", 10, 50, &hh, &mm, &ss);
+ output = bsddialog_timebox(&conf,
+ "TAB / RIGHT / LEFT to move,\nUP / DOWN to select time", 10, 35,
+ &hh, &mm, &ss);
bsddialog_end();
diff --git a/examples_library/yesno.c b/examples_library/yesno.c
index 5a9c95edc849..364a6c77fc26 100644
--- a/examples_library/yesno.c
+++ b/examples_library/yesno.c
@@ -8,11 +8,10 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
+#include <bsddialog.h>
#include <stdio.h>
#include <string.h>
-#include <bsddialog.h>
-
int main()
{
int output;
diff --git a/examples_utility/checklist.sh b/examples_utility/checklist.sh
index 94eb2043a3ab..fefabc282c80 100755
--- a/examples_utility/checklist.sh
+++ b/examples_utility/checklist.sh
@@ -3,15 +3,36 @@
# 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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_ESC=5}
-./bsddialog --title " checklist " --checklist "Hello World!" 15 30 5 \
+ITEMS=$(./bsddialog --title " checklist " --checklist "Hello World!" 15 30 5 \
"Tag 1" "DESC 1 xyz" on \
"Tag 2" "DESC 2 xyz" off \
"Tag 3" "DESC 3 xyz" on \
"Tag 4" "DESC 4 xyz" off \
"Tag 5" "DESC 5 xyz" on \
- 2>out.txt ; cat out.txt ; rm out.txt
+3>&1 1>&2 2>&3 3>&-)
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC] focus: $ITEMS"
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel] focus: $ITEMS"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK] Selected: $ITEMS"
+ ;;
+esac
diff --git a/examples_utility/form.sh b/examples_utility/form.sh
index ad1b5d275d0d..bd1bac8a3939 100755
--- a/examples_utility/form.sh
+++ b/examples_utility/form.sh
@@ -3,17 +3,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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_ESC=5}
-./bsddialog --title " form " --form "Hello World!" 12 40 5 \
+FORMS=$(./bsddialog --title " form " --form "Hello World!" 12 40 5 \
Label1: 1 1 Value1 1 9 18 25 \
Label2: 2 1 Value2 2 9 18 25 \
Label3: 3 1 Value3 3 9 18 25 \
Label4: 4 1 Value4 4 9 18 25 \
Label5: 5 1 Value5 5 9 18 25 \
- 2>out.txt ; cat out.txt ; rm out.txt
+3>&1 1>&2 2>&3 3>&-)
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC]"
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel]"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK]"
+ ;;
+esac
+echo "$FORMS"
diff --git a/examples_utility/gauge.sh b/examples_utility/gauge.sh
index 1665e04b4e8c..a06a77034b75 100755
--- a/examples_utility/gauge.sh
+++ b/examples_utility/gauge.sh
@@ -3,10 +3,11 @@
# 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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
characters="A B C D E F G"
total=`echo $characters | awk '{print split($0, a)}'`
@@ -25,4 +26,3 @@ do
fi
i=`expr $i + 1`
done | ./bsddialog --title " gauge " --gauge "[0/$total] Starting..." 10 70
-
diff --git a/examples_utility/infobox.sh b/examples_utility/infobox.sh
index 75d14d10177a..ff39ad4d5f0e 100755
--- a/examples_utility/infobox.sh
+++ b/examples_utility/infobox.sh
@@ -3,9 +3,10 @@
# 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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
./bsddialog --sleep 3 --title " infobox " --infobox "Hello World!\n3 secs" 6 20
diff --git a/examples_utility/inputbox.sh b/examples_utility/inputbox.sh
index 340500eaab1f..a359a3b8e833 100755
--- a/examples_utility/inputbox.sh
+++ b/examples_utility/inputbox.sh
@@ -3,10 +3,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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_ESC=5}
+
+FORM=$(./bsddialog --title " inputbox " --inputbox "Hello World!" 12 40 init \
+3>&1 1>&2 2>&3 3>&-)
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC]"
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel]"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK]"
+ ;;
+esac
+
+echo "$FORM"
-./bsddialog --title " inputbox " --inputbox "Hello World!" 12 40 default \
- 2>out.txt ; cat out.txt ; rm out.txt
diff --git a/examples_utility/menu.sh b/examples_utility/menu.sh
index fe56f4e079cf..002a82f6a870 100755
--- a/examples_utility/menu.sh
+++ b/examples_utility/menu.sh
@@ -3,15 +3,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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_ESC=5}
-./bsddialog --title " menu " --menu "Hello World!" 15 30 5 \
+ITEM=$(./bsddialog --title " menu " --menu "Hello World!" 15 30 5 \
"Tag 1" "DESC 1 xyz" \
"Tag 2" "DESC 2 xyz" \
"Tag 3" "DESC 3 xyz" \
"Tag 4" "DESC 4 xyz" \
- "Tag 5" "DESC 5 xyz" \
- 2>out.txt ; cat out.txt ; rm out.txt
+3>&1 1>&2 2>&3 3>&-)
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC] $ITEM"
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel] $ITEM"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK] $ITEM"
+ ;;
+esac
diff --git a/examples_utility/mixedform.sh b/examples_utility/mixedform.sh
index 303c1a63dd98..80b7abf93745 100755
--- a/examples_utility/mixedform.sh
+++ b/examples_utility/mixedform.sh
@@ -3,13 +3,37 @@
# 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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_ESC=5}
+
+FORMS=$(./bsddialog --insecure --title " mixedform " \
+ --mixedform "Hello World!" 12 40 3 \
+ Label: 1 1 Entry 1 11 18 25 0 \
+ Label: 2 1 Read-Only 2 11 18 25 2 \
+ Password: 3 1 "" 3 11 18 25 1 \
+3>&1 1>&2 2>&3 3>&-)
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC]"
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel]"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK]"
+ ;;
+esac
-./bsddialog --insecure --title " mixedform " --mixedform "Hello World!" 12 40 5 \
- Label: 11 Entry 1 11 18 25 0 \
- Label: 21 Read-Only 2 11 18 25 2 \
- Password: 31 "" 3 11 18 25 1 \
- 2>out.txt ; cat out.txt ; rm out.txt
+echo "$FORMS"
diff --git a/examples_utility/mixedgauge.sh b/examples_utility/mixedgauge.sh
index 735f8dc42922..e98ff70614db 100755
--- a/examples_utility/mixedgauge.sh
+++ b/examples_utility/mixedgauge.sh
@@ -3,10 +3,11 @@
# 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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
perc=0
while [ $perc -le 100 ]
diff --git a/examples_utility/msgbox.sh b/examples_utility/msgbox.sh
index 9e14ed6cbba4..cad3c9ecb72a 100755
--- a/examples_utility/msgbox.sh
+++ b/examples_utility/msgbox.sh
@@ -3,9 +3,26 @@
# 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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_ESC=5}
./bsddialog --title " msgbox " --msgbox "Hello World!" 6 20
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC]"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK]"
+ ;;
+esac
diff --git a/examples_utility/passwordbox.sh b/examples_utility/passwordbox.sh
index 673491f64140..0f93a13c877c 100755
--- a/examples_utility/passwordbox.sh
+++ b/examples_utility/passwordbox.sh
@@ -3,10 +3,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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_ESC=5}
+
+FORM=$(./bsddialog --insecure --title " password " \
+ --passwordbox "Hello World!" 12 40 \
+3>&1 1>&2 2>&3 3>&-)
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC]"
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel]"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK]"
+ ;;
+esac
-./bsddialog --insecure --title " password " --passwordbox "Hello World!" 12 40 \
- 2>out.txt ; cat out.txt ; rm out.txt
+echo "$FORM"
diff --git a/examples_utility/passwordform.sh b/examples_utility/passwordform.sh
index 658f1635dffc..19b3a355b6eb 100755
--- a/examples_utility/passwordform.sh
+++ b/examples_utility/passwordform.sh
@@ -3,15 +3,39 @@
# 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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_ESC=5}
-./bsddialog --insecure --title " passwordform " --passwordform "Example" 12 40 5 \
+FORMS=$(./bsddialog --insecure --title " passwordform " \
+ --passwordform "Example" 12 40 5 \
Password1: 1 1 "" 1 12 18 25 \
Password2: 2 1 "" 2 12 18 25 \
Password3: 3 1 "" 3 12 18 25 \
Password4: 4 1 "" 4 12 18 25 \
Password5: 5 1 "" 5 12 18 25 \
- 2>out.txt ; cat out.txt ; rm out.txt
+3>&1 1>&2 2>&3 3>&-)
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC]"
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel]"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK]"
+ ;;
+esac
+
+echo "$FORMS"
diff --git a/examples_utility/pause.sh b/examples_utility/pause.sh
new file mode 100755
index 000000000000..225549dddffb
--- /dev/null
+++ b/examples_utility/pause.sh
@@ -0,0 +1,36 @@
+#!/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/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_TIMEOUT=4}
+: ${BSDDIALOG_ESC=5}
+
+./bsddialog --title " pause " --pause "Hello World!" 7 35 10
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC]"
+ ;;
+ $BSDDIALOG_TIMEOUT )
+ echo "[TIMEOUT]"
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel]"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK]"
+ ;;
+esac
diff --git a/examples_utility/radiolist.sh b/examples_utility/radiolist.sh
index 2b4ce8d56809..9de483369c75 100755
--- a/examples_utility/radiolist.sh
+++ b/examples_utility/radiolist.sh
@@ -3,15 +3,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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_ESC=5}
-./bsddialog --title " radiolist " --radiolist "Hello World!" 15 30 5 \
+ITEM=$(./bsddialog --title " radiolist " --radiolist "Hello World!" 15 30 5 \
"Tag 1" "DESC 1 xyz" off \
"Tag 2" "DESC 2 xyz" off \
"Tag 3" "DESC 3 xyz" on \
"Tag 4" "DESC 4 xyz" off \
"Tag 5" "DESC 5 xyz" off \
- 2>out.txt ; cat out.txt ; rm out.txt
+3>&1 1>&2 2>&3 3>&-)
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC] focus "
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel] focus "
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK]"
+ ;;
+esac
+
+echo "$ITEM"
diff --git a/examples_utility/timebox.sh b/examples_utility/timebox.sh
new file mode 100755
index 000000000000..81d24d558dc9
--- /dev/null
+++ b/examples_utility/timebox.sh
@@ -0,0 +1,34 @@
+#!/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/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_OK=0}
+: ${BSDDIALOG_CANCEL=1}
+: ${BSDDIALOG_ESC=5}
+
+TIME=$(./bsddialog --title " timebox " \
+ --timebox "Tab / Left / Right to move\nUp / Down to select" 10 40 \
+3>&1 1>&2 2>&3 3>&-)
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC]"
+ ;;
+ $BSDDIALOG_CANCEL )
+ echo "[Cancel]"
+ ;;
+ $BSDDIALOG_OK )
+ echo "[OK] $TIME"
+ ;;
+esac
diff --git a/examples_utility/treeview.sh b/examples_utility/treeview.sh
deleted file mode 100755
index 3566c6812714..000000000000
--- a/examples_utility/treeview.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/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/>.
-
-./bsddialog --title " treeview " --treeview "Hello World!" 15 40 5 \
- 0 "Tag 1" "DESC 1 xyz" off \
- 1 "Tag 2" "DESC 2 xyz" off \
- 2 "Tag 3" "DESC 3 xyz" on \
- 1 "Tag 4" "DESC 4 xyz" off \
- 1 "Tag 5" "DESC 5 xyz" off \
- 2>out.txt ; cat out.txt ; rm out.txt
diff --git a/examples_utility/yesno.sh b/examples_utility/yesno.sh
index cfa082e8d24e..d384086657e6 100755
--- a/examples_utility/yesno.sh
+++ b/examples_utility/yesno.sh
@@ -3,9 +3,30 @@
# 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/>.
+# <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+: ${BSDDIALOG_ERROR=255}
+: ${BSDDIALOG_YES=0}
+: ${BSDDIALOG_NO=1}
+: ${BSDDIALOG_ESC=5}
./bsddialog --title " yesno " --yesno "Hello World!" 6 25
+
+case $? in
+ $BSDDIALOG_ERROR )
+ exit 1
+ ;;
+ $BSDDIALOG_ESC )
+ echo "[ESC]"
+ ;;
+ $BSDDIALOG_NO )
+ echo "[NO]"
+ ;;
+ $BSDDIALOG_YES )
+ echo "[YES]"
+ ;;
+esac
diff --git a/lib/GNUMakefile b/lib/GNUMakefile
index 842e03494b4c..0d724b803be3 100644
--- a/lib/GNUMakefile
+++ b/lib/GNUMakefile
@@ -3,14 +3,15 @@
#
# Written in 2021 by Alfonso Sabato Siciliano
-VERSION = 0.1
+VERSION = 0.2
LIBRARY = bsddialog
LIBRARY_SO = lib${LIBRARY:=.so}
HEADERS = bsddialog.h bsddialog_theme.h bsddialog_progressview.h
SOURCES = barbox.c formbox.c infobox.c libbsddialog.c lib_util.c menubox.c \
messagebox.c textbox.c theme.c timebox.c
OBJECTS = $(SOURCES:.c=.o)
-CFLAGS = -Wall -Werror -fpic
+CFLAGS = -D_XOPEN_SOURCE_EXTENDED -Wall -Wextra -Wno-implicit-fallthrough \
+ -Werror -fpic
LDFLAGS = -lformw -lncursesw -ltinfo
LIBFLAG = -shared
diff --git a/lib/Makefile b/lib/Makefile
index d9f2ce8ed69b..962b059b3e03 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -3,7 +3,7 @@
#
# Written in 2021 by Alfonso Sabato Siciliano
-VERSION = 0.1
+VERSION = 0.2
LIBRARY = bsddialog
LIBRARY_SO = lib${LIBRARY:=.so}
LIBRARY_A = lib${LIBRARY:=.a}
@@ -11,17 +11,16 @@ HEADERS = bsddialog.h bsddialog_theme.h bsddialog_progressview.h
SOURCES = barbox.c formbox.c infobox.c libbsddialog.c lib_util.c menubox.c \
messagebox.c textbox.c theme.c timebox.c
OBJECTS = ${SOURCES:.c=.o}
-CFLAGS += -fPIC -Wall -Wextra
+CFLAGS += -D_XOPEN_SOURCE_EXTENDED -fPIC -Wall -Wextra
LDFLAGS += -fstack-protector-strong -shared -Wl,-x -Wl,--fatal-warnings \
-Wl,--warn-shared-textrel -Wl,-soname,${LIBRARY_SO}.${VERSION} \
-L/usr/lib -lformw -lncursesw -ltinfow
.if defined(DEBUG)
# `make -DDEBUG`
-CFLAGS = -g -fPIC -Wall -Wextra
+CFLAGS = -g -D_XOPEN_SOURCE_EXTENDED -fPIC -Wall -Wextra
.else
-CFLAGS += -O2 -pipe -std=gnu99 -Wno-format-zero-length \
- -fstack-protector-strong -Qunused-arguments
+CFLAGS += -std=gnu99 -fstack-protector-strong
.endif
LOCALBASE = /usr/local
@@ -66,7 +65,7 @@ install:
${INSTALL} -l rs ${LOCALBASE}/lib/${LIBRARY_SO}.${VERSION} ${LOCALBASE}/lib/${LIBRARY_SO}
${INSTALL} -m 644 ${LIBRARY_A} ${LOCALBASE}/lib
${LDCONFIG} ${LOCALBASE}/lib
- ${INSTALL} -m 644 ${LIBRARY}.3.gz ${MNADIR}
+ ${INSTALL} -m 644 ${LIBRARY}.3.gz ${MANDIR}
unistall:
${RM} ${LOCALBASE}/include/${LIBRARY}*.h
diff --git a/lib/barbox.c b/lib/barbox.c
index 72000fad747c..49aa105c1de3 100644
--- a/lib/barbox.c
+++ b/lib/barbox.c
@@ -39,26 +39,27 @@
#include "bsddialog_theme.h"
#include "lib_util.h"
-#define BARPADDING 3
-#define MINBARWIDTH (15 + BARPADDING * 2)
+#define BARPADDING 2
+#define MINBARLEN 15
+#define MINBARWIDTH (2 + 2 * BARPADDING + MINBARLEN)
+#define MINMGBARLEN 18
+#define MINMGBARWIDTH (2 + 2 * BARPADDING + MINMGBARLEN)
bool bsddialog_interruptprogview;
bool bsddialog_abortprogview;
int bsddialog_total_progview;
-extern struct bsddialog_theme t;
-
static void
-draw_bar(WINDOW *win, int y, int x, int size, int perc, bool withlabel,
+draw_bar(WINDOW *win, int y, int x, int barlen, int perc, bool withlabel,
int label)
{
- int i, blue_x, color;
+ int i, blue_x, color, stringlen;
char labelstr[128];
- blue_x = (int)((perc*(size))/100);
+ blue_x = perc > 0 ? (perc * barlen) / 100 : -1;
wmove(win, y, x);
- for (i = 0; i < size; i++) {
+ for (i = 0; i < barlen; i++) {
color = (i <= blue_x) ? t.bar.f_color : t.bar.color;
wattron(win, color);
waddch(win, ' ');
@@ -69,9 +70,10 @@ draw_bar(WINDOW *win, int y, int x, int size, int perc, bool withlabel,
sprintf(labelstr, "%d", label);
else
sprintf(labelstr, "%3d%%", perc);
- wmove(win, y, x + size/2 - 2);
- for (i = 0; i < (int)strlen(labelstr); i++) {
- color = (blue_x + 1 <= size/2 - (int)strlen(labelstr)/2 + i ) ?
+ stringlen = (int)strlen(labelstr);
+ wmove(win, y, x + barlen/2 - stringlen/2);
+ for (i = 0; i < stringlen; i++) {
+ color = (blue_x + 1 <= barlen/2 - stringlen/2 + i ) ?
t.bar.color : t.bar.f_color;
wattron(win, color);
waddch(win, labelstr[i]);
@@ -106,11 +108,9 @@ bar_checksize(int rows, int cols, struct buttons *bs)
int minheight, minwidth;
minwidth = 0;
- if (bs != NULL) { /* gauge has not buttons */
- minwidth = bs->nbuttons * bs->sizebutton;
- if (bs->nbuttons > 0)
- minwidth += (bs->nbuttons-1) * t.button.space;
- }
+ if (bs != NULL) /* gauge has not buttons */
+ minwidth = buttons_width(*bs);
+
minwidth = MAX(minwidth, MINBARWIDTH);
minwidth += VBORDERS;
@@ -152,7 +152,7 @@ bsddialog_gauge(struct bsddialog_conf *conf, const char *text, int rows,
bar = new_boxed_window(conf, y+h-4, x+3, 3, w-6, RAISED);
mainloop = (fd < 0) ? false : true;
-
+
if (mainloop) {
fd2 = dup(fd);
input = fdopen(fd2, "r");
@@ -181,7 +181,6 @@ bsddialog_gauge(struct bsddialog_conf *conf, const char *text, int rows,
if (mainloop == false)
break;
fscanf(input, "%d", &perc);
- perc = perc < 0 ? 0 : perc;
perc = perc > 100 ? 100 : perc;
pntext = &ntext[0];
ntext[0] = '\0';
@@ -242,7 +241,8 @@ do_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows, int cols,
max_minbarlen = 0;
for (i = 0; i < (int)nminibars; i++)
max_minbarlen = MAX(max_minbarlen, (int)strlen(minilabels[i]));
- max_minbarlen += 3 + 16 /* seps + [...] or mainbar */;
+ max_minbarlen += 3 + 16; /* seps + [...] */
+ max_minbarlen = MAX(max_minbarlen, MINMGBARWIDTH); /* mainbar */
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
return (BSDDIALOG_ERROR);
@@ -311,7 +311,7 @@ do_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows, int cols,
wrefresh(widget);
getmaxyx(textpad, htextpad, i /* unused */);
ypad = y + h - 4 - htextpad;
- ypad = ypad < y+(int)nminibars ? y+nminibars : ypad;
+ ypad = ypad < y+(int)nminibars ? y+(int)nminibars : ypad;
prefresh(textpad, 0, 0, ypad, x+2, y+h-4, x+w-2);
/* main bar */
@@ -463,7 +463,7 @@ bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
prefresh(textpad, 0, 0, y+1, x+1+TEXTHMARGIN, y+h-7, x+w-1-TEXTHMARGIN);
- sizebar = w - HBORDERS - 2 - BARPADDING * 2;
+ sizebar = w - HBORDERS - (2 * BARPADDING) - 2;
bigchange = MAX(1, sizebar/10);
bar = new_boxed_window(conf, y + h - 6, x + 1 + BARPADDING, 3,
@@ -546,7 +546,8 @@ bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
}
break;
case KEY_F(1):
- if (conf->f1_file == NULL && conf->f1_message == NULL)
+ if (conf->key.f1_file == NULL &&
+ conf->key.f1_message == NULL)
break;
if (f1help(conf) != 0)
return (BSDDIALOG_ERROR);
@@ -572,7 +573,7 @@ bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
doupdate();
- sizebar = w - HBORDERS - 2 - BARPADDING * 2;
+ sizebar = w - HBORDERS - (2 * BARPADDING) - 2;
bigchange = MAX(1, sizebar/10);
wclear(bar);
mvwin(bar, y + h - 6, x + 1 + BARPADDING);
@@ -627,7 +628,7 @@ bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows,
prefresh(textpad, 0, 0, y+1, x+1+TEXTHMARGIN, y+h-7, x+w-1-TEXTHMARGIN);
- sizebar = w - HBORDERS - 2 - BARPADDING * 2;
+ sizebar = w - HBORDERS - (2 * BARPADDING) - 2;
bar = new_boxed_window(conf, y + h - 6, x + 1 + BARPADDING, 3,
sizebar + 2, RAISED);
@@ -690,7 +691,8 @@ bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows,
}
break;
case KEY_F(1):
- if (conf->f1_file == NULL && conf->f1_message == NULL)
+ if (conf->key.f1_file == NULL &&
+ conf->key.f1_message == NULL)
break;
if (f1help(conf) != 0)
return (BSDDIALOG_ERROR);
@@ -716,7 +718,7 @@ bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows,
doupdate();
- sizebar = w - HBORDERS - 2 - BARPADDING * 2;
+ sizebar = w - HBORDERS - (2 * BARPADDING) - 2;
wclear(bar);
mvwin(bar, y + h - 6, x + 1 + BARPADDING);
wresize(bar, 3, sizebar + 2);
diff --git a/lib/bsddialog.3 b/lib/bsddialog.3
index 4139970626b5..38500b4da6ca 100644
--- a/lib/bsddialog.3
+++ b/lib/bsddialog.3
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd January 23, 2022
+.Dd February 9, 2022
.Dt BSDDIALOG 3
.Os
.Sh NAME
@@ -284,8 +284,6 @@ struct bsddialog_conf {
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;
@@ -296,6 +294,8 @@ struct bsddialog_conf {
int x;
struct {
bool enable_esc;
+ const char *f1_file;
+ const char *f1_message;
} key;
struct {
bool highlight;
@@ -305,13 +305,13 @@ struct bsddialog_conf {
bool align_left;
bool no_desc;
bool no_name;
+ bool on_without_ok;
bool shortcut_buttons;
} menu;
struct {
+ bool enable_wchar;
int securech;
- bool value_withcancel;
- bool value_withextra;
- bool value_withhelp;
+ bool value_without_ok;
} form;
struct {
bool without_ok;
@@ -347,10 +347,6 @@ is
subtitle at the dialog bottom side.
.It Fa conf.clear
hide the dialog at exit.
-.It Fa conf.f1_file
-file to open if F1 is pressed.
-.It Fa conf.f1_message
-message to display if F1 is pressed.
.It Fa conf.get_height
if not
.Dv NULL
@@ -375,10 +371,16 @@ horizontal position, 0 is left screen side, can be
.Dv BSDDIALOG_CENTER .
.El
.Pp
-.Fa conf.key.enable_esc
+.Bl -column -compact
+.It Fa conf.key.enable_esc
enables
.Dv ESC
key to close the dialog.
+.It Fa conf.key.f1_file
+file to open if F1 is pressed.
+.It Fa conf.key.f1_message
+message to display if F1 is pressed.
+.El
.Pp
.Fa conf.text.highlight
enables highlights for
@@ -659,6 +661,12 @@ have to be between 1 and
.Fn bsddialog_form
can be customized by:
.Bl -column -compact
+.It Fa conf.form.enable_wchar
+enables characters greater than 127 in the field,
+.Fa value
+is a pointer to allocated memory for a
+.Em wchar_t
+string.
.It Fa conf.form.securech
charachter to hide the input
with
@@ -749,9 +757,10 @@ struct bsddialog_theme {
int lineraisecolor;
int linelowercolor;
int bottomtitlecolor;
+ int arrowcolor;
} dialog;
struct {
- int arrowcolor;
+ int f_selectorcolor;
int selectorcolor;
int f_namecolor;
int namecolor;
@@ -772,9 +781,9 @@ struct bsddialog_theme {
int color;
} bar;
struct {
- unsigned int space;
- int leftch;
- int rightch;
+ unsigned int hmargin;
+ int leftdelim;
+ int rightdelim;
int delimcolor;
int f_delimcolor;
int color;
@@ -826,7 +835,7 @@ call.
The library provides predefined themes:
.Dv BSDDIALOG_THEME_BLACKWHITE ,
.Dv BSDDIALOG_THEME_BSDDIALOG ,
-.Dv BSDDIALOG_THEME_DEFAULT
+.Dv BSDDIALOG_THEME_FLAT
and
.Dv BSDDIALOG_THEME_DIALOG ,
they can be set via
@@ -898,7 +907,7 @@ Theme Example:
struct bsddialog_conf conf;
struct bsddialog_theme theme;
-if (bsddialog_init() == BSDDIALOG_ERROR)
+bsddialog_init();
bsddialog_initconf(&conf);
bsddialog_msgbox(&conf, "Default theme", 7, 25);
diff --git a/lib/bsddialog.h b/lib/bsddialog.h
index 142713cc1ecf..37f9899141c0 100644
--- a/lib/bsddialog.h
+++ b/lib/bsddialog.h
@@ -30,7 +30,7 @@
#include <stdbool.h>
-#define LIBBSDDIALOG_VERSION "0.1"
+#define LIBBSDDIALOG_VERSION "0.2"
/* Exit status */
#define BSDDIALOG_ERROR -1
@@ -73,8 +73,6 @@ struct bsddialog_conf {
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;
@@ -85,6 +83,8 @@ struct bsddialog_conf {
int x;
struct {
bool enable_esc;
+ const char *f1_file;
+ const char *f1_message;
} key;
struct {
bool highlight;
@@ -98,6 +98,7 @@ struct bsddialog_conf {
bool shortcut_buttons;
} menu;
struct {
+ bool enable_wchar;
int securech;
bool value_without_ok;
} form;
diff --git a/lib/bsddialog_theme.h b/lib/bsddialog_theme.h
index 65ba5f5e94e8..89381cfe28d5 100644
--- a/lib/bsddialog_theme.h
+++ b/lib/bsddialog_theme.h
@@ -49,9 +49,10 @@ struct bsddialog_theme {
int lineraisecolor;
int linelowercolor;
int bottomtitlecolor;
+ int arrowcolor;
} dialog;
struct {
- int arrowcolor;
+ int f_selectorcolor;
int selectorcolor;
int f_namecolor;
int namecolor;
@@ -72,9 +73,9 @@ struct bsddialog_theme {
int color;
} bar;
struct {
- unsigned int space;
- int leftch;
- int rightch;
+ unsigned int hmargin;
+ int leftdelim;
+ int rightdelim;
int delimcolor;
int f_delimcolor;
int color;
@@ -87,7 +88,7 @@ struct bsddialog_theme {
enum bsddialog_default_theme {
BSDDIALOG_THEME_BLACKWHITE,
BSDDIALOG_THEME_BSDDIALOG,
- BSDDIALOG_THEME_DEFAULT,
+ BSDDIALOG_THEME_FLAT,
BSDDIALOG_THEME_DIALOG
};
diff --git a/lib/formbox.c b/lib/formbox.c
index ade1660c2645..564fa99d69a8 100644
--- a/lib/formbox.c
+++ b/lib/formbox.c
@@ -36,16 +36,14 @@
#include "bsddialog_theme.h"
#include "lib_util.h"
-#define REDRAWFORM 19860214 /* magic number */
#define ISFIELDHIDDEN(item) (item.flags & BSDDIALOG_FIELDHIDDEN)
#define ISFIELDREADONLY(item) (item.flags & BSDDIALOG_FIELDREADONLY)
-
-extern struct bsddialog_theme t;
+#define REDRAWFORM 19860214 /* magic number */
/* field_userptr for private buffer and view options */
struct myfield {
int buflen;
- char *buf;
+ wchar_t *buf;
int pos;
int maxpos;
bool secure;
@@ -97,7 +95,23 @@ static void print_bottomdesc(struct myfield *mf)
}
}
-int
+static char *w2c(wchar_t *string)
+{
+ int i, len;
+ char *value;
+
+ len = wcslen(string);
+ if ((value = calloc(len + 1, sizeof(char))) == NULL)
+ return NULL;
+
+ for (i = 0; i < len; i++)
+ value[i] = string[i];
+ value[i] = '\0';
+
+ return value;
+}
+
+static int
return_values(struct bsddialog_conf *conf, int output, int nitems,
struct bsddialog_formitem *items, FORM *form, FIELD **cfield)
{
@@ -107,11 +121,15 @@ return_values(struct bsddialog_conf *conf, int output, int nitems,
if (output != BSDDIALOG_OK && conf->form.value_without_ok == false)
return (output);
- form_driver(form, REQ_NEXT_FIELD);
- form_driver(form, REQ_PREV_FIELD);
+ form_driver_w(form, KEY_CODE_YES, REQ_NEXT_FIELD);
+ form_driver_w(form, KEY_CODE_YES, REQ_PREV_FIELD);
for (i = 0; i < nitems; i++) {
mf = GETMYFIELD(cfield[i]);
- items[i].value = strdup(mf->buf);
+ if (conf->form.enable_wchar) {
+ items[i].value = (char*)wcsdup(mf->buf);
+ } else {
+ items[i].value = w2c(mf->buf);
+ }
if (items[i].value == NULL)
RETURN_ERROR("Cannot allocate memory for form value");
}
@@ -125,15 +143,16 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
struct bsddialog_formitem *items)
{
bool loop, buttupdate, informwin;
- int i, input, output;
+ int i, chtype, output;
+ wint_t input;
struct myfield *mf;
mf = GETMYFIELD2(form);
print_bottomdesc(mf);
pos_form_cursor(form);
- form_driver(form, REQ_END_LINE);
+ form_driver_w(form, KEY_CODE_YES, REQ_END_LINE);
mf->pos = MIN(mf->buflen, mf->maxpos);
- curs_set(2);
+ curs_set(1);
informwin = true;
bs.curr = -1;
@@ -147,8 +166,17 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
buttupdate = false;
}
wrefresh(formwin);
- input = getch();
+ chtype = get_wch(&input);
+ if (chtype != KEY_CODE_YES && input > 127 &&
+ conf->form.enable_wchar == false)
+ continue;
switch(input) {
+ case KEY_HOME:
+ case KEY_PPAGE:
+ case KEY_END:
+ case KEY_NPAGE:
+ /* disabled keys */
+ break;
case KEY_ENTER:
case 10: /* Enter */
if (informwin)
@@ -174,7 +202,7 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
informwin = bs.curr >= (int)bs.nbuttons ?
true : false;
if (informwin) {
- curs_set(2);
+ curs_set(1);
pos_form_cursor(form);
}
}
@@ -182,7 +210,7 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
break;
case KEY_LEFT:
if (informwin) {
- form_driver(form, REQ_PREV_CHAR);
+ form_driver_w(form, KEY_CODE_YES, REQ_PREV_CHAR);
mf = GETMYFIELD2(form);
if (mf->pos > 0)
mf->pos -= 1;
@@ -199,7 +227,7 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
if (mf->pos >= mf->buflen)
break;
mf->pos += 1;
- form_driver(form, REQ_NEXT_CHAR);
+ form_driver_w(form, KEY_CODE_YES, REQ_NEXT_CHAR);
} else {
if (bs.curr < (int) bs.nbuttons - 1) {
bs.curr++;
@@ -212,8 +240,8 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
break;
set_field_fore(current_field(form), t.form.fieldcolor);
set_field_back(current_field(form), t.form.fieldcolor);
- form_driver(form, REQ_PREV_FIELD);
- form_driver(form, REQ_END_LINE);
+ form_driver_w(form, KEY_CODE_YES, REQ_PREV_FIELD);
+ form_driver_w(form, KEY_CODE_YES, REQ_END_LINE);
mf = GETMYFIELD2(form);
print_bottomdesc(mf);
mf->pos = MIN(mf->buflen, mf->maxpos);
@@ -225,8 +253,8 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
break;
set_field_fore(current_field(form), t.form.fieldcolor);
set_field_back(current_field(form), t.form.fieldcolor);
- form_driver(form, REQ_NEXT_FIELD);
- form_driver(form, REQ_END_LINE);
+ form_driver_w(form, KEY_CODE_YES, REQ_NEXT_FIELD);
+ form_driver_w(form, KEY_CODE_YES, REQ_END_LINE);
mf = GETMYFIELD2(form);
print_bottomdesc(mf);
mf->pos = MIN(mf->buflen, mf->maxpos);
@@ -238,21 +266,22 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
mf = GETMYFIELD2(form);
if (mf->pos <= 0)
break;
- form_driver(form, REQ_DEL_PREV);
- form_driver(form, REQ_BEG_LINE);
+ form_driver_w(form, KEY_CODE_YES, REQ_DEL_PREV);
+ form_driver_w(form, KEY_CODE_YES, REQ_BEG_LINE);
mf->pos = mf->pos - 1;
for (i = 0; i < mf->pos; i++)
- form_driver(form, REQ_NEXT_CHAR);
+ form_driver_w(form, KEY_CODE_YES, REQ_NEXT_CHAR);
shiftleft(mf);
break;
case KEY_DC:
- form_driver(form, REQ_DEL_CHAR);
+ form_driver_w(form, KEY_CODE_YES, REQ_DEL_CHAR);
mf = GETMYFIELD2(form);
if (mf->pos < mf->buflen)
shiftleft(mf);
break;
case KEY_F(1):
- if (conf->f1_file == NULL && conf->f1_message == NULL)
+ if (conf->key.f1_file == NULL &&
+ conf->key.f1_message == NULL)
break;
if (f1help(conf) != 0)
return (BSDDIALOG_ERROR);
@@ -263,11 +292,13 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
break;
default:
if (informwin) {
+ if (chtype == KEY_CODE_YES)
+ break;
mf = GETMYFIELD2(form);
if (mf->secure)
- form_driver(form, mf->securech);
+ form_driver_w(form, chtype, mf->securech);
else
- form_driver(form, input);
+ form_driver_w(form, chtype, input);
insertch(mf, input);
}
else {
@@ -330,8 +361,7 @@ form_checksize(int rows, int cols, const char *text, int formheight, int nitems,
mincols = VBORDERS;
/* buttons */
- mincols += bs.nbuttons * bs.sizebutton;
- mincols += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
+ mincols += buttons_width(bs);
mincols = MAX(mincols, (int)linelen + 4);
if (cols < mincols)
@@ -356,13 +386,13 @@ bsddialog_form(struct bsddialog_conf *conf, const char *text, int rows,
int cols, unsigned int formheight, unsigned int nitems,
struct bsddialog_formitem *items)
{
- WINDOW *widget, *formwin, *textpad, *shadow;
int i, output, color, y, x, h, w;
- FIELD **cfield;
- FORM *form;
+ unsigned long j, maxline, mybufsize;
struct buttons bs;
struct myfield *myfields;
- unsigned long maxline;
+ FIELD **cfield;
+ FORM *form;
+ WINDOW *widget, *formwin, *textpad, *shadow;
/* disable form scrolling */
if (formheight < nitems)
@@ -385,13 +415,17 @@ bsddialog_form(struct bsddialog_conf *conf, const char *text, int rows,
items[i].xfield-1, 0, 0);
field_opts_off(cfield[i], O_STATIC);
set_max_field(cfield[i], items[i].maxvaluelen);
+ /* setlocale() should handle set_field_buffer() */
set_field_buffer(cfield[i], 0, items[i].init);
- myfields[i].buf = malloc(items[i].maxvaluelen + 1);
- memset(myfields[i].buf, 0, items[i].maxvaluelen + 1);
- strncpy(myfields[i].buf, items[i].init, items[i].maxvaluelen);
+ mybufsize = (items[i].maxvaluelen + 1) * sizeof(wchar_t);
+ myfields[i].buf = malloc(mybufsize);
+ memset(myfields[i].buf, 0, mybufsize);
+ for (j = 0; j < items[i].maxvaluelen && j < strlen(items[i].init);
+ j++)
+ myfields[i].buf[j] = items[i].init[j];
- myfields[i].buflen = strlen(myfields[i].buf);
+ myfields[i].buflen = wcslen(myfields[i].buf);
myfields[i].maxpos = items[i].maxvaluelen -1;
myfields[i].pos = MIN(myfields[i].buflen, myfields[i].maxpos);
@@ -500,4 +534,4 @@ bsddialog_form(struct bsddialog_conf *conf, const char *text, int rows,
end_dialog(conf, shadow, widget, textpad);
return (output);
-} \ No newline at end of file
+}
diff --git a/lib/infobox.c b/lib/infobox.c
index 4ded942fb300..5a6b7c2fd692 100644
--- a/lib/infobox.c
+++ b/lib/infobox.c
@@ -30,11 +30,8 @@
#include <curses.h>
#include "bsddialog.h"
-#include "bsddialog_theme.h"
#include "lib_util.h"
-extern struct bsddialog_theme t;
-
static int
infobox_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h,
int *w, const char *text)
diff --git a/lib/lib_util.c b/lib/lib_util.c
index f7e6a2ae15ab..4c2ab76bc592 100644
--- a/lib/lib_util.c
+++ b/lib/lib_util.c
@@ -37,10 +37,8 @@
#include "bsddialog_theme.h"
#include "lib_util.h"
-extern struct bsddialog_theme t;
-
#define TABLEN 4 /* Default tab len */
-#define ERRBUFLEN 1024 /* Error buffer */
+#define ERRBUFLEN 1024 /* Error buffer */
/* Error */
static char errorbuffer[ERRBUFLEN];
@@ -50,7 +48,7 @@ const char *get_error_string(void)
return (errorbuffer);
}
-void set_error_string(char *str)
+void set_error_string(const char *str)
{
strncpy(errorbuffer, str, ERRBUFLEN-1);
}
@@ -91,11 +89,11 @@ int f1help(struct bsddialog_conf *conf)
hconf.text.highlight = conf->text.highlight;
output = BSDDIALOG_OK;
- if (conf->f1_message != NULL)
- output = bsddialog_msgbox(&hconf, conf->f1_message, 0, 0);
+ if (conf->key.f1_message != NULL)
+ output = bsddialog_msgbox(&hconf, conf->key.f1_message, 0, 0);
- if (output != BSDDIALOG_ERROR && conf->f1_file != NULL)
- output = bsddialog_textbox(&hconf, conf->f1_file, 0, 0);
+ if (output != BSDDIALOG_ERROR && conf->key.f1_file != NULL)
+ output = bsddialog_textbox(&hconf, conf->key.f1_file, 0, 0);
return (output == BSDDIALOG_ERROR ? BSDDIALOG_ERROR : 0);
}
@@ -118,14 +116,14 @@ draw_button(WINDOW *window, int y, int x, int size, const char *text,
}
wattron(window, color_arrows);
- mvwaddch(window, y, x, t.button.leftch);
+ mvwaddch(window, y, x, t.button.leftdelim);
wattroff(window, color_arrows);
wattron(window, color_button);
for (i = 1; i < size - 1; i++)
waddch(window, ' ');
wattroff(window, color_button);
wattron(window, color_arrows);
- mvwaddch(window, y, x + i, t.button.rightch);
+ mvwaddch(window, y, x + i, t.button.rightdelim);
wattroff(window, color_arrows);
x = x + 1 + ((size - 2 - strlen(text))/2);
@@ -148,19 +146,18 @@ draw_buttons(WINDOW *window, struct buttons bs, bool shortcut)
getmaxyx(window, rows, cols);
y = rows - 2;
- startx = bs.sizebutton * bs.nbuttons + (bs.nbuttons-1) * t.button.space;
- startx = cols/2 - startx/2;
+ startx = cols/2 - buttons_width(bs)/2;
- for (i = 0; i < (int) bs.nbuttons; i++) {
- x = i * (bs.sizebutton + t.button.space);
+ for (i = 0; i < (int)bs.nbuttons; i++) {
+ x = i * (bs.sizebutton + t.button.hmargin);
draw_button(window, y, startx + x, bs.sizebutton, bs.label[i],
i == bs.curr, shortcut);
}
}
void
-get_buttons(struct bsddialog_conf *conf, struct buttons *bs, char *yesoklabel,
- char *nocancellabel)
+get_buttons(struct bsddialog_conf *conf, struct buttons *bs,
+ const char *yesoklabel, const char *nocancellabel)
{
int i;
#define SIZEBUTTON 8
@@ -233,6 +230,17 @@ get_buttons(struct bsddialog_conf *conf, struct buttons *bs, char *yesoklabel,
bs->sizebutton += 2;
}
+int buttons_width(struct buttons bs)
+{
+ unsigned int width;
+
+ width = bs.nbuttons * bs.sizebutton;
+ if (bs.nbuttons > 0)
+ width += (bs.nbuttons - 1) * t.button.hmargin;
+
+ return (width);
+}
+
bool shortcut_buttons(int key, struct buttons *bs)
{
bool match;
@@ -532,11 +540,8 @@ text_size(struct bsddialog_conf *conf, int rows, int cols, const char *text,
bool changewtext;
wbuttons = 0;
- if (bs != NULL) {
- wbuttons = bs->nbuttons * bs->sizebutton;
- if (bs->nbuttons > 0)
- wbuttons += (bs->nbuttons-1) * t.button.space;
- }
+ if (bs != NULL)
+ wbuttons = buttons_width(*bs);
if (cols == BSDDIALOG_AUTOSIZE) {
startwtext = MAX(startwtext, wbuttons - TEXTHMARGINS);
@@ -577,7 +582,7 @@ int widget_max_height(struct bsddialog_conf *conf)
{
int maxheight;
- maxheight = conf->shadow ? SCREENLINES - t.shadow.h : SCREENLINES;
+ maxheight = conf->shadow ? SCREENLINES - (int)t.shadow.h : SCREENLINES;
if (maxheight <= 0)
RETURN_ERROR("Terminal too small, screen lines - shadow <= 0");
@@ -595,7 +600,7 @@ int widget_max_width(struct bsddialog_conf *conf)
{
int maxwidth;
- maxwidth = conf->shadow ? SCREENCOLS - t.shadow.w : SCREENCOLS;
+ maxwidth = conf->shadow ? SCREENCOLS - (int)t.shadow.w : SCREENCOLS;
if (maxwidth <= 0)
RETURN_ERROR("Terminal too small, screen cols - shadow <= 0");
@@ -647,10 +652,8 @@ widget_min_width(struct bsddialog_conf *conf, int wtext, int minwidget,
min = 0;
/* buttons */
- if (bs != NULL) {
- min += bs->nbuttons * bs->sizebutton;
- min += bs->nbuttons > 0 ? (bs->nbuttons-1) * t.button.space : 0;
- }
+ if (bs != NULL)
+ min += buttons_width(*bs);
/* text */
if (wtext > 0)
@@ -774,7 +777,7 @@ draw_borders(struct bsddialog_conf *conf, WINDOW *win, int rows, int cols,
rtee = ACS_RTEE;
}
- leftcolor = elev == RAISED ?
+ leftcolor = elev == RAISED ?
t.dialog.lineraisecolor : t.dialog.linelowercolor;
rightcolor = elev == RAISED ?
t.dialog.linelowercolor : t.dialog.lineraisecolor;
diff --git a/lib/lib_util.h b/lib/lib_util.h
index a3ed2508cd49..6ebc73cf1055 100644
--- a/lib/lib_util.h
+++ b/lib/lib_util.h
@@ -33,6 +33,9 @@
#define TEXTHMARGIN 1
#define TEXTHMARGINS (TEXTHMARGIN + TEXTHMARGIN)
+/* current theme */
+extern struct bsddialog_theme t;
+
/* debug */
#define BSDDIALOG_DEBUG(y,x,fmt, ...) do { \
mvprintw(y, x, fmt, __VA_ARGS__); \
@@ -41,7 +44,7 @@
/* error buffer */
const char *get_error_string(void);
-void set_error_string(char *string);
+void set_error_string(const char *string);
#define RETURN_ERROR(str) do { \
set_error_string(str); \
@@ -61,12 +64,13 @@ struct buttons {
#define BUTTON_OK_LABEL "OK"
#define BUTTON_CANCEL_LABEL "Cancel"
void
-get_buttons(struct bsddialog_conf *conf, struct buttons *bs, char *yesoklabel,
- char *nocancellabel);
+get_buttons(struct bsddialog_conf *conf, struct buttons *bs,
+ const char *yesoklabel, const char *nocancellabel);
void
draw_buttons(WINDOW *window, struct buttons bs, bool shortcut);
+int buttons_width(struct buttons bs);
bool shortcut_buttons(int key, struct buttons *bs);
/* help window with F1 key */
diff --git a/lib/libbsddialog.c b/lib/libbsddialog.c
index 65134eabe5f3..761bdc3efa77 100644
--- a/lib/libbsddialog.c
+++ b/lib/libbsddialog.c
@@ -34,8 +34,6 @@
#include "bsddialog_theme.h"
#include "lib_util.h"
-extern struct bsddialog_theme t;
-
int bsddialog_init(void)
{
int i, j, c, error;
@@ -59,14 +57,15 @@ int bsddialog_init(void)
c = 1;
error += start_color();
- for (i = 0; i < 8; i++)
+ for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
error += init_pair(c, i, j);
c++;
+ }
}
- if (error == OK)
- theme = BSDDIALOG_THEME_DEFAULT;
+ if (error == OK && has_colors())
+ theme = BSDDIALOG_THEME_FLAT;
else
theme = BSDDIALOG_THEME_BLACKWHITE;
diff --git a/lib/menubox.c b/lib/menubox.c
index 0d8e3b14521c..22ed15e6e7a0 100644
--- a/lib/menubox.c
+++ b/lib/menubox.c
@@ -36,10 +36,8 @@
#include "bsddialog_theme.h"
#include "lib_util.h"
-#define DEPTHSPACE 4
-#define MIN_HEIGHT VBORDERS + 6 /* 2 buttons 1 text 3 menu */
-
-extern struct bsddialog_theme t;
+#define DEPTH 2
+#define MIN_HEIGHT VBORDERS + 6 /* 2 buttons 1 text 3 menu */
enum menumode {
CHECKLISTMODE,
@@ -197,7 +195,7 @@ getnextshortcut(struct bsddialog_conf *conf, int npritems,
if (i > abs)
return (i);
- if (i < abs && next == -1)
+ if (i < abs && next == -1)
next = i;
}
}
@@ -221,31 +219,25 @@ getmode(enum menumode mode, struct bsddialog_menugroup group)
}
static void
-drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
- struct lineposition pos, struct privateitem *pritem, bool focus)
+drawseparators(struct bsddialog_conf *conf, WINDOW *pad, int linelen,
+ int nitems, struct privateitem *pritems)
{
- int colordesc, colorname, colorshortcut, linech;
- unsigned int depth;
- enum menumode mode;
- const char *prefix, *name, *desc, *bottomdesc, *shortcut;
-
- prefix = pritem->item->prefix;
- name = pritem->item->name;
- depth = pritem->item->depth;
- desc = pritem->item->desc;
- bottomdesc = pritem->item->bottomdesc;
-
- mode = pritem->type;
+ int i, linech, labellen;
+ const char *desc, *name;
- if (mode == SEPARATORMODE) {
+ for (i = 0; i < nitems; i++) {
+ if (pritems[i].type != SEPARATORMODE)
+ continue;
if (conf->no_lines == false) {
wattron(pad, t.menu.desccolor);
linech = conf->ascii_lines ? '-' : ACS_HLINE;
- mvwhline(pad, y, 0, linech, pos.line);
+ mvwhline(pad, i, 0, linech, linelen);
wattroff(pad, t.menu.desccolor);
}
- wmove(pad, y,
- pos.line/2 - (strlen(name) + strlen(desc)) / 2 );
+ name = pritems[i].item->name;
+ desc = pritems[i].item->desc;
+ labellen = strlen(name) + strlen(desc) + 1;
+ wmove(pad, i, labellen < linelen ? linelen/2 - labellen/2 : 0);
wattron(pad, t.menu.namesepcolor);
waddstr(pad, name);
wattroff(pad, t.menu.namesepcolor);
@@ -254,27 +246,37 @@ drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
wattron(pad, t.menu.descsepcolor);
waddstr(pad, desc);
wattroff(pad, t.menu.descsepcolor);
- return;
}
+}
+
+static void
+drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
+ struct lineposition pos, struct privateitem *pritem, bool focus)
+{
+ int colordesc, colorname, colorshortcut;
+ const char *shortcut;
+ struct bsddialog_menuitem *item;
+
+ item = pritem->item;
/* prefix */
- if (prefix != NULL && prefix[0] != '\0')
- mvwaddstr(pad, y, 0, prefix);
+ if (item->prefix != NULL && item->prefix[0] != '\0')
+ mvwaddstr(pad, y, 0, item->prefix);
/* selector */
wmove(pad, y, pos.xselector);
- wattron(pad, t.menu.selectorcolor);
- if (mode == CHECKLISTMODE)
+ wattron(pad, focus ? t.menu.f_selectorcolor : t.menu.selectorcolor);
+ if (pritem->type == CHECKLISTMODE)
wprintw(pad, "[%c]", pritem->on ? 'X' : ' ');
- if (mode == RADIOLISTMODE)
+ if (pritem->type == RADIOLISTMODE)
wprintw(pad, "(%c)", pritem->on ? '*' : ' ');
- wattroff(pad, t.menu.selectorcolor);
+ wattroff(pad, focus ? t.menu.f_selectorcolor : t.menu.selectorcolor);
/* name */
colorname = focus ? t.menu.f_namecolor : t.menu.namecolor;
if (conf->menu.no_name == false) {
wattron(pad, colorname);
- mvwaddstr(pad, y, pos.xname + depth * DEPTHSPACE, name);
+ mvwaddstr(pad, y, pos.xname + item->depth * DEPTH, item->name);
wattroff(pad, colorname);
}
@@ -287,9 +289,10 @@ drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
if (conf->menu.no_desc == false) {
wattron(pad, colordesc);
if (conf->menu.no_name)
- mvwaddstr(pad, y, pos.xname + depth * DEPTHSPACE, desc);
+ mvwaddstr(pad, y, pos.xname + item->depth * DEPTH,
+ item->desc);
else
- mvwaddstr(pad, y, pos.xdesc, desc);
+ mvwaddstr(pad, y, pos.xdesc, item->desc);
wattroff(pad, colordesc);
}
@@ -300,10 +303,10 @@ drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
wattron(pad, colorshortcut);
if (conf->menu.no_name)
- shortcut = desc;
+ shortcut = item->desc;
else
- shortcut = name;
- wmove(pad, y, pos.xname + depth * DEPTHSPACE);
+ shortcut = item->name;
+ wmove(pad, y, pos.xname + item->depth * DEPTH);
if (shortcut != NULL && shortcut[0] != '\0')
waddch(pad, shortcut[0]);
wattroff(pad, colorshortcut);
@@ -312,8 +315,8 @@ drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
/* bottom description */
move(SCREENLINES - 1, 2);
clrtoeol();
- if (bottomdesc != NULL && focus) {
- addstr(bottomdesc);
+ if (item->bottomdesc != NULL && focus) {
+ addstr(item->bottomdesc);
refresh();
}
}
@@ -329,20 +332,21 @@ menu_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
if (*menurows == BSDDIALOG_AUTOSIZE) {
/* algo 1): grows vertically */
/* notext = 1; */
- /* algo 2): grows horizontally, better with little terminals */
+ /* algo 2): grows horizontally, better with little screens */
notext += nitems;
notext = MIN(notext, widget_max_height(conf) - HBORDERS - 3);
} else
notext += *menurows;
- if (cols == BSDDIALOG_AUTOSIZE || rows == BSDDIALOG_AUTOSIZE) {
- if (text_size(conf, rows, cols, text, &bs, notext, linelen + 6,
+ /* cols autosize, rows autosize, rows fullscreen, menu particularity */
+ if (cols == BSDDIALOG_AUTOSIZE || rows <= BSDDIALOG_AUTOSIZE) {
+ if (text_size(conf, rows, cols, text, &bs, notext, linelen + 4,
&htext, &wtext) != 0)
return (BSDDIALOG_ERROR);
}
if (cols == BSDDIALOG_AUTOSIZE)
- *w = widget_min_width(conf, wtext, linelen + 6, &bs);
+ *w = widget_min_width(conf, wtext, linelen + 4, &bs);
if (rows == BSDDIALOG_AUTOSIZE) {
if (*menurows == 0) {
@@ -362,7 +366,7 @@ menu_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
*menurows = MIN(*h - 6 - htext, (int)*menurows);
} else {
if (*menurows == 0)
- *menurows = MIN(rows-6-htext, nitems);
+ *menurows = MIN(*h-6-htext, nitems);
}
return (0);
@@ -376,8 +380,8 @@ menu_checksize(int rows, int cols, const char *text, int menurows, int nitems,
mincols = VBORDERS;
/* buttons */
- mincols += bs.nbuttons * bs.sizebutton;
- mincols += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
+ mincols += buttons_width(bs);
+
/*
* linelen check, comment to allow some hidden col otherwise portconfig
* could not show big menus like www/apache24
@@ -408,16 +412,16 @@ update_menuwin(struct bsddialog_conf *conf, WINDOW *menuwin, int h, int w,
{
draw_borders(conf, menuwin, h, w, LOWERED);
- if (totnitems > (int) menurows) {
- wattron(menuwin, t.menu.arrowcolor);
+ if (totnitems > (int)menurows) {
+ wattron(menuwin, t.dialog.arrowcolor);
if (ymenupad > 0)
mvwprintw(menuwin, 0, 2, "^^^");
- if ((int) (ymenupad + menurows) < totnitems)
+ if ((ymenupad + (int)menurows) < totnitems)
mvwprintw(menuwin, h-1, 2, "vvv");
- wattroff(menuwin, t.menu.arrowcolor);
+ wattroff(menuwin, t.dialog.arrowcolor);
mvwprintw(menuwin, h-1, w-10, "%3d%%",
100 * (ymenupad + menurows) / totnitems);
@@ -440,7 +444,7 @@ do_mixedlist(struct bsddialog_conf *conf, const char *text, int rows, int cols,
shortcut_butts = conf->menu.shortcut_buttons;
- automenurows = menurows == BSDDIALOG_AUTOSIZE ? true : false;
+ automenurows = (menurows == BSDDIALOG_AUTOSIZE) ? true : false;
totnitems = 0;
for (i = 0; i < (int)ngroups; i++) {
@@ -466,7 +470,7 @@ do_mixedlist(struct bsddialog_conf *conf, const char *text, int rows, int cols,
}
pos.maxname = conf->menu.no_name ? 0 : pos.maxname;
pos.maxdesc = conf->menu.no_desc ? 0 : pos.maxdesc;
- pos.maxdepth *= DEPTHSPACE;
+ pos.maxdepth = DEPTH * pos.maxdepth;
pos.xselector = pos.maxprefix + (pos.maxprefix != 0 ? 1 : 0);
pos.xname = pos.xselector + pos.selectorlen +
@@ -530,6 +534,8 @@ do_mixedlist(struct bsddialog_conf *conf, const char *text, int rows, int cols,
abs++;
}
}
+ drawseparators(conf, menupad, MIN((int)pos.line, w-6), totnitems,
+ pritems);
abs = getfirst_with_default(totnitems, pritems, ngroups, groups,
focuslist, focusitem);
if (abs >= 0)
@@ -596,7 +602,8 @@ do_mixedlist(struct bsddialog_conf *conf, const char *text, int rows, int cols,
}
break;
case KEY_F(1):
- if (conf->f1_file == NULL && conf->f1_message == NULL)
+ if (conf->key.f1_file == NULL &&
+ conf->key.f1_message == NULL)
break;
if (f1help(conf) != 0)
return (BSDDIALOG_ERROR);
@@ -644,6 +651,9 @@ do_mixedlist(struct bsddialog_conf *conf, const char *text, int rows, int cols,
xe = xs + w - 5;
}
+ drawseparators(conf, menupad, MIN((int)pos.line, w-6),
+ totnitems, pritems);
+
if ((int)(ymenupad + menurows) - 1 < abs)
ymenupad = abs - menurows + 1;
prefresh(menupad, ymenupad, 0, ys, xs, ye, xe);
@@ -695,7 +705,7 @@ do_mixedlist(struct bsddialog_conf *conf, const char *text, int rows, int cols,
drawitem(conf, menupad, i, pos,
&pritems[i], false);
}
- }
+ }
pritems[abs].on = !pritems[abs].on;
}
drawitem(conf, menupad, abs, pos, &pritems[abs], true);
@@ -806,4 +816,4 @@ bsddialog_radiolist(struct bsddialog_conf *conf, const char *text, int rows,
1, &group, &focuslist, focusitem);
return (output);
-} \ No newline at end of file
+}
diff --git a/lib/messagebox.c b/lib/messagebox.c
index edea7c41c18d..24b34ccbce97 100644
--- a/lib/messagebox.c
+++ b/lib/messagebox.c
@@ -31,11 +31,8 @@
#include <string.h>
#include "bsddialog.h"
-#include "bsddialog_theme.h"
#include "lib_util.h"
-extern struct bsddialog_theme t;
-
static int
message_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h,
int *w, const char *text, struct buttons bs)
@@ -62,8 +59,7 @@ static int message_checksize(int rows, int cols, struct buttons bs)
int mincols;
mincols = VBORDERS;
- mincols += bs.nbuttons * bs.sizebutton;
- mincols += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
+ mincols += buttons_width(bs);
if (cols < mincols)
RETURN_ERROR("Few cols, Msgbox and Yesno need at least width "
@@ -153,7 +149,8 @@ do_message(struct bsddialog_conf *conf, const char *text, int rows, int cols,
}
break;
case KEY_F(1):
- if (conf->f1_file == NULL && conf->f1_message == NULL)
+ if (conf->key.f1_file == NULL &&
+ conf->key.f1_message == NULL)
break;
if (f1help(conf) != 0)
return (BSDDIALOG_ERROR);
diff --git a/lib/textbox.c b/lib/textbox.c
index 9e242b9fb5ab..69eff7c0bc2e 100644
--- a/lib/textbox.c
+++ b/lib/textbox.c
@@ -34,8 +34,6 @@
#include "bsddialog_theme.h"
#include "lib_util.h"
-extern struct bsddialog_theme t;
-
static void
textbox_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h,
int *w, int hpad, int wpad, struct buttons bs)
@@ -177,7 +175,8 @@ bsddialog_textbox(struct bsddialog_conf *conf, const char* file, int rows,
ypad = ypad + printrows <= hpad -1 ? ypad + 1 : ypad;
break;
case KEY_F(1):
- if (conf->f1_file == NULL && conf->f1_message == NULL)
+ if (conf->key.f1_file == NULL &&
+ conf->key.f1_message == NULL)
break;
if (f1help(conf) != 0)
return (BSDDIALOG_ERROR);
diff --git a/lib/theme.c b/lib/theme.c
index 48eed6a8e598..20b1e35428dd 100644
--- a/lib/theme.c
+++ b/lib/theme.c
@@ -50,13 +50,14 @@ static struct bsddialog_theme bsddialogtheme = {
.dialog.linelowercolor = GET_COLOR(COLOR_BLACK, bgwidget),
.dialog.color = GET_COLOR(COLOR_BLACK, bgwidget),
.dialog.bottomtitlecolor = GET_COLOR(COLOR_BLACK, bgwidget),
+ .dialog.arrowcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
- .menu.arrowcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
- .menu.selectorcolor = GET_COLOR(COLOR_BLACK, bgwidget) | A_BOLD,
+ .menu.f_selectorcolor = GET_COLOR(COLOR_BLACK, bgcurr),
+ .menu.selectorcolor = GET_COLOR(COLOR_BLACK, bgwidget),
.menu.f_desccolor = GET_COLOR(COLOR_WHITE, bgcurr),
.menu.desccolor = GET_COLOR(COLOR_BLACK, bgwidget),
.menu.f_namecolor = GET_COLOR(COLOR_BLACK, bgcurr),
- .menu.namecolor = GET_COLOR(COLOR_YELLOW, bgwidget),
+ .menu.namecolor = GET_COLOR(COLOR_BLACK, bgwidget),
.menu.namesepcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
.menu.descsepcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
.menu.f_shortcutcolor = GET_COLOR(COLOR_RED, bgcurr),
@@ -69,15 +70,15 @@ static struct bsddialog_theme bsddialogtheme = {
.bar.f_color = GET_COLOR(COLOR_WHITE, COLOR_BLUE),
.bar.color = GET_COLOR(COLOR_BLUE, COLOR_WHITE),
- .button.space = 3,
- .button.leftch = '[',
- .button.rightch = ']',
- .button.f_delimcolor = GET_COLOR(COLOR_WHITE, bgcurr),
+ .button.hmargin = 3,
+ .button.leftdelim = '[',
+ .button.rightdelim = ']',
+ .button.f_delimcolor = GET_COLOR(COLOR_BLACK, bgwidget),
.button.delimcolor = GET_COLOR(COLOR_BLACK, bgwidget),
- .button.f_color = GET_COLOR(COLOR_WHITE, bgcurr) | A_UNDERLINE,
- .button.color = GET_COLOR(COLOR_BLACK, bgwidget) | A_UNDERLINE,
- .button.f_shortcutcolor = GET_COLOR(COLOR_BLACK, bgcurr) | A_UNDERLINE,
- .button.shortcutcolor = GET_COLOR(COLOR_YELLOW, bgwidget) | A_UNDERLINE
+ .button.f_color = GET_COLOR(COLOR_BLACK, bgcurr) | A_UNDERLINE,
+ .button.color = GET_COLOR(COLOR_BLACK, bgwidget) | A_UNDERLINE,
+ .button.f_shortcutcolor = GET_COLOR(COLOR_RED, bgcurr) | A_UNDERLINE,
+ .button.shortcutcolor = GET_COLOR(COLOR_RED, bgwidget) | A_UNDERLINE
};
static struct bsddialog_theme blackwhite = {
@@ -95,8 +96,9 @@ static struct bsddialog_theme blackwhite = {
.dialog.linelowercolor = GET_COLOR(fg, bk),
.dialog.color = GET_COLOR(fg, bk),
.dialog.bottomtitlecolor = GET_COLOR(fg, bk),
+ .dialog.arrowcolor = GET_COLOR(fg, bk),
- .menu.arrowcolor = GET_COLOR(fg, bk),
+ .menu.f_selectorcolor = GET_COLOR(fg, bk) | A_REVERSE,
.menu.selectorcolor = GET_COLOR(fg, bk),
.menu.f_desccolor = GET_COLOR(fg, bk) | A_REVERSE,
.menu.desccolor = GET_COLOR(fg, bk),
@@ -114,9 +116,9 @@ static struct bsddialog_theme blackwhite = {
.bar.f_color = GET_COLOR(fg, bk) | A_REVERSE,
.bar.color = GET_COLOR(fg, bk),
- .button.space = 3,
- .button.leftch = '[',
- .button.rightch = ']',
+ .button.hmargin = 3,
+ .button.leftdelim = '[',
+ .button.rightdelim = ']',
.button.f_delimcolor = GET_COLOR(fg, bk),
.button.delimcolor = GET_COLOR(fg, bk),
.button.f_color = GET_COLOR(fg, bk) | A_UNDERLINE | A_REVERSE,
@@ -138,12 +140,13 @@ static struct bsddialog_theme dialogtheme = {
.dialog.linelowercolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
.dialog.color = GET_COLOR(COLOR_BLACK, COLOR_WHITE),
.dialog.bottomtitlecolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
+ .dialog.arrowcolor = GET_COLOR(COLOR_GREEN, COLOR_WHITE),
- .menu.arrowcolor = GET_COLOR(COLOR_GREEN, COLOR_WHITE),
+ .menu.f_selectorcolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE),
.menu.selectorcolor = GET_COLOR(COLOR_BLACK, bgwidget),
.menu.f_desccolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE),
.menu.desccolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE),
- .menu.f_namecolor = GET_COLOR(COLOR_YELLOW, COLOR_BLUE),
+ .menu.f_namecolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE),
.menu.namecolor = GET_COLOR(COLOR_BLUE, COLOR_WHITE),
.menu.namesepcolor = GET_COLOR(COLOR_RED, COLOR_WHITE),
.menu.descsepcolor = GET_COLOR(COLOR_RED, COLOR_WHITE),
@@ -157,9 +160,9 @@ static struct bsddialog_theme dialogtheme = {
.bar.f_color = GET_COLOR(COLOR_WHITE, COLOR_BLUE) | A_BOLD,
.bar.color = GET_COLOR(COLOR_BLUE, COLOR_WHITE) | A_BOLD,
- .button.space = 3,
- .button.leftch = '<',
- .button.rightch = '>',
+ .button.hmargin = 3,
+ .button.leftdelim = '<',
+ .button.rightdelim = '>',
.button.f_delimcolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE) | A_BOLD,
.button.delimcolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE),
.button.f_color = GET_COLOR(COLOR_YELLOW, COLOR_BLUE) | A_BOLD,
@@ -183,8 +186,9 @@ set_theme(struct bsddialog_theme *dst, struct bsddialog_theme *src)
dst->dialog.linelowercolor = src->dialog.linelowercolor;
dst->dialog.color = src->dialog.color;
dst->dialog.bottomtitlecolor = src->dialog.bottomtitlecolor;
+ dst->dialog.arrowcolor = src->dialog.arrowcolor;
- dst->menu.arrowcolor = src->menu.arrowcolor;
+ dst->menu.f_selectorcolor = src->menu.f_selectorcolor;
dst->menu.selectorcolor = src->menu.selectorcolor;
dst->menu.f_desccolor = src->menu.f_desccolor;
dst->menu.desccolor = src->menu.desccolor;
@@ -202,9 +206,9 @@ set_theme(struct bsddialog_theme *dst, struct bsddialog_theme *src)
dst->bar.f_color = src->bar.f_color;
dst->bar.color = src->bar.color;
- dst->button.space = src->button.space;
- dst->button.leftch = src->button.leftch;
- dst->button.rightch = src->button.rightch;
+ dst->button.hmargin = src->button.hmargin;
+ dst->button.leftdelim = src->button.leftdelim;
+ dst->button.rightdelim = src->button.rightdelim;
dst->button.f_delimcolor = src->button.f_delimcolor;
dst->button.delimcolor = src->button.delimcolor;
dst->button.f_color = src->button.f_color;
@@ -244,12 +248,12 @@ int bsddialog_set_theme(struct bsddialog_theme *theme)
int bsddialog_set_default_theme(enum bsddialog_default_theme newtheme)
{
- if (newtheme == BSDDIALOG_THEME_DEFAULT) {
+ if (newtheme == BSDDIALOG_THEME_FLAT) {
bsddialog_set_theme(&dialogtheme);
t.dialog.lineraisecolor = t.dialog.linelowercolor;
t.dialog.delimtitle = true;
- t.button.leftch = '[';
- t.button.rightch = ']';
+ t.button.leftdelim = '[';
+ t.button.rightdelim = ']';
}
else if (newtheme == BSDDIALOG_THEME_BSDDIALOG)
bsddialog_set_theme(&bsddialogtheme);
@@ -277,4 +281,4 @@ bsddialog_color(enum bsddialog_color foreground,
cursesflags |= A_UNDERLINE;
return (GET_COLOR(foreground, background) | cursesflags);
-} \ No newline at end of file
+}
diff --git a/lib/timebox.c b/lib/timebox.c
index db1d4377d007..7d69666c32b8 100644
--- a/lib/timebox.c
+++ b/lib/timebox.c
@@ -32,14 +32,11 @@
#include <string.h>
#include "bsddialog.h"
-#include "bsddialog_theme.h"
#include "lib_util.h"
#define MINWDATE 23 /* 3 windows and their borders */
#define MINWTIME 14 /* 3 windows and their borders */
-extern struct bsddialog_theme t;
-
static int
datetime_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h,
int *w, int minw, const char *text, struct buttons bs)
@@ -67,8 +64,7 @@ datetime_checksize(int rows, int cols, int minw, struct buttons bs)
int mincols;
mincols = VBORDERS;
- mincols += bs.nbuttons * bs.sizebutton;
- mincols += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
+ mincols += buttons_width(bs);
mincols = MAX(minw, mincols);
if (cols < mincols)
@@ -84,7 +80,7 @@ int
bsddialog_timebox(struct bsddialog_conf *conf, const char* text, int rows,
int cols, unsigned int *hh, unsigned int *mm, unsigned int *ss)
{
- bool loop;
+ bool loop, focusbuttons;
int i, input, output, y, x, h, w, sel;
WINDOW *widget, *textpad, *shadow;
struct buttons bs;
@@ -135,27 +131,25 @@ bsddialog_timebox(struct bsddialog_conf *conf, const char* text, int rows,
wrefresh(widget);
- sel = 0;
- curs_set(2);
- loop = true;
+ loop = focusbuttons = true;
while (loop) {
for (i = 0; i < 3; i++) {
mvwprintw(c[i].win, 1, 1, "%2d", c[i].value);
wrefresh(c[i].win);
}
- wmove(c[sel].win, 1, 2);
- wrefresh(c[sel].win);
+
+ if (focusbuttons == false) {
+ wmove(c[sel].win, 1, 2);
+ wrefresh(c[sel].win);
+ }
input = getch();
switch(input) {
case KEY_ENTER:
case 10: /* Enter */
+ if (focusbuttons == false)
+ break;
output = bs.value[bs.curr];
- if (output == BSDDIALOG_OK) {
- *hh = c[0].value;
- *mm = c[1].value;
- *ss = c[2].value;
- }
loop = false;
break;
case 27: /* Esc */
@@ -164,32 +158,66 @@ bsddialog_timebox(struct bsddialog_conf *conf, const char* text, int rows,
loop = false;
}
break;
+ case KEY_RIGHT:
case '\t': /* TAB */
- bs.curr = (bs.curr + 1) % bs.nbuttons;
+ if (focusbuttons) {
+ bs.curr++;
+ focusbuttons = bs.curr < (int)bs.nbuttons ?
+ true : false;
+ if (focusbuttons == false) {
+ curs_set(1);
+ sel = 0;
+ }
+ } else {
+ sel++;
+ focusbuttons = sel > 2 ? true : false;
+ if (focusbuttons) {
+ curs_set(0);
+ bs.curr = 0;
+ }
+ }
draw_buttons(widget, bs, true);
wrefresh(widget);
break;
case KEY_LEFT:
- sel = sel == 0 ? 2 : (sel - 1);
- break;
- case KEY_RIGHT:
- sel = (sel + 1) % 3;
+ if (focusbuttons) {
+ bs.curr--;
+ focusbuttons = bs.curr < 0 ? false : true;
+ if (focusbuttons == false) {
+ curs_set(1);
+ sel = 2;
+ }
+ } else {
+ sel--;
+ focusbuttons = sel < 0 ? true : false;
+ if (focusbuttons) {
+ curs_set(0);
+ bs.curr = (int)bs.nbuttons - 1;
+ }
+ }
+ draw_buttons(widget, bs, true);
+ wrefresh(widget);
break;
case KEY_UP:
- c[sel].value = c[sel].value < c[sel].max ?
- c[sel].value + 1 : 0;
- break;
- case KEY_DOWN:
+ if (focusbuttons)
+ break;
c[sel].value = c[sel].value > 0 ?
c[sel].value - 1 : c[sel].max;
break;
+ case KEY_DOWN:
+ if (focusbuttons)
+ break;
+ c[sel].value = c[sel].value < c[sel].max ?
+ c[sel].value + 1 : 0;
+ break;
case KEY_F(1):
- if (conf->f1_file == NULL && conf->f1_message == NULL)
+ if (conf->key.f1_file == NULL &&
+ conf->key.f1_message == NULL)
break;
curs_set(0);
if (f1help(conf) != 0)
return (BSDDIALOG_ERROR);
- curs_set(2);
+ curs_set(1);
/* No break, screen size can change */
case KEY_RESIZE:
/* Important for decreasing screen */
@@ -244,6 +272,12 @@ bsddialog_timebox(struct bsddialog_conf *conf, const char* text, int rows,
}
}
+ if (output == BSDDIALOG_OK) {
+ *hh = c[0].value;
+ *mm = c[1].value;
+ *ss = c[2].value;
+ }
+
curs_set(0);
for (i = 0; i < 3; i++)
@@ -257,7 +291,7 @@ int
bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd)
{
- bool loop;
+ bool loop, focusbuttons;
int i, input, output, y, x, h, w, sel;
WINDOW *widget, *textpad, *shadow;
struct buttons bs;
@@ -268,7 +302,7 @@ bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
unsigned int x;
};
struct month {
- char *name;
+ const char *name;
unsigned int days;
};
@@ -329,9 +363,7 @@ bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
wrefresh(widget);
- sel = 2;
- curs_set(2);
- loop = true;
+ loop = focusbuttons = true;
while (loop) {
mvwprintw(c[0].win, 1, 1, "%4d", c[0].value);
mvwprintw(c[1].win, 1, 1, "%9s", m[c[1].value-1].name);
@@ -339,19 +371,18 @@ bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
for (i = 0; i < 3; i++) {
wrefresh(c[i].win);
}
- wmove(c[sel].win, 1, c[sel].x);
- wrefresh(c[sel].win);
+ if (focusbuttons == false) {
+ wmove(c[sel].win, 1, c[sel].x);
+ wrefresh(c[sel].win);
+ }
input = getch();
switch(input) {
case KEY_ENTER:
case 10: /* Enter */
+ if (focusbuttons == false)
+ break;
output = bs.value[bs.curr];
- if (output == BSDDIALOG_OK) {
- *yy = c[0].value;
- *mm = c[1].value;
- *dd = c[2].value;
- }
loop = false;
break;
case 27: /* Esc */
@@ -360,18 +391,49 @@ bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
loop = false;
}
break;
+ case KEY_RIGHT:
case '\t': /* TAB */
- bs.curr = (bs.curr + 1) % bs.nbuttons;
+ if (focusbuttons) {
+ bs.curr++;
+ focusbuttons = bs.curr < (int)bs.nbuttons ?
+ true : false;
+ if (focusbuttons == false) {
+ curs_set(1);
+ sel = 0;
+ }
+ } else {
+ sel++;
+ focusbuttons = sel > 2 ? true : false;
+ if (focusbuttons) {
+ curs_set(0);
+ bs.curr = 0;
+ }
+ }
draw_buttons(widget, bs, true);
wrefresh(widget);
break;
case KEY_LEFT:
- sel = sel == 0 ? 2 : (sel - 1);
- break;
- case KEY_RIGHT:
- sel = (sel + 1) % 3;
+ if (focusbuttons) {
+ bs.curr--;
+ focusbuttons = bs.curr < 0 ? false : true;
+ if (focusbuttons == false) {
+ curs_set(1);
+ sel = 2;
+ }
+ } else {
+ sel--;
+ focusbuttons = sel < 0 ? true : false;
+ if (focusbuttons) {
+ curs_set(0);
+ bs.curr = (int)bs.nbuttons - 1;
+ }
+ }
+ draw_buttons(widget, bs, true);
+ wrefresh(widget);
break;
case KEY_UP:
+ if (focusbuttons)
+ break;
c[sel].value = c[sel].value > 1 ?
c[sel].value - 1 : c[sel].max ;
/* if mount change */
@@ -384,6 +446,8 @@ bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
c[2].value = c[2].max;
break;
case KEY_DOWN:
+ if (focusbuttons)
+ break;
c[sel].value = c[sel].value < c[sel].max ?
c[sel].value + 1 : 1;
/* if mount change */
@@ -396,12 +460,13 @@ bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
c[2].value = c[2].max;
break;
case KEY_F(1):
- if (conf->f1_file == NULL && conf->f1_message == NULL)
+ if (conf->key.f1_file == NULL &&
+ conf->key.f1_message == NULL)
break;
curs_set(0);
if (f1help(conf) != 0)
return (BSDDIALOG_ERROR);
- curs_set(2);
+ curs_set(1);
/* No break, screen size can change */
case KEY_RESIZE:
/* Important for decreasing screen */
@@ -455,6 +520,12 @@ bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
}
}
+ if (output == BSDDIALOG_OK) {
+ *yy = c[0].value;
+ *mm = c[1].value;
+ *dd = c[2].value;
+ }
+
curs_set(0);
for (i = 0; i < 3; i++)
@@ -462,4 +533,4 @@ bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
end_dialog(conf, shadow, widget, textpad);
return (output);
-} \ No newline at end of file
+}