diff options
Diffstat (limited to 'contrib/bsddialog/utility')
-rw-r--r-- | contrib/bsddialog/utility/bsddialog.1 | 88 | ||||
-rw-r--r-- | contrib/bsddialog/utility/bsddialog.c | 6 | ||||
-rw-r--r-- | contrib/bsddialog/utility/util_builders.c | 79 | ||||
-rw-r--r-- | contrib/bsddialog/utility/util_cli.c | 6 | ||||
-rw-r--r-- | contrib/bsddialog/utility/util_theme.c | 12 |
5 files changed, 134 insertions, 57 deletions
diff --git a/contrib/bsddialog/utility/bsddialog.1 b/contrib/bsddialog/utility/bsddialog.1 index 653f91a3f122..4586ba16020c 100644 --- a/contrib/bsddialog/utility/bsddialog.1 +++ b/contrib/bsddialog/utility/bsddialog.1 @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 2021-2023 Alfonso Sabato Siciliano +.\" Copyright (c) 2021-2024 Alfonso Sabato Siciliano .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 25, 2023 +.Dd May 25, 2024 .Dt BSDDIALOG 1 .Os .Sh NAME @@ -438,6 +438,21 @@ timeout. .It Fl Fl title Ar title Dialog title. .El +.Ss Keys +The following keys are available at runtime: +.Bl -tag -width Ds +.It Ctrl-l +Redraw the dialog. +.It F1 +See +.Fl Fl hfile +and +.Fl Fl hmsg . +.It SPACE +Select menu item. +.It UP DOWN LEFT RIGHT - + HOME END PAGEUP PAGEDOWN Ctrl-p Ctrl-n TAB +Navigate elements and set value, depending on the dialog. +.El .Ss Dialogs The following dialogs are available: .Bl -tag -width Ds @@ -472,20 +487,22 @@ and a field to get the input at the position .Ar yfield and -.Ar xfield -with graphical length -.Ar fieldlen , -.Ar maxletters -is the maximum input length. -The field can be customized, if +.Ar xfield . .Ar fieldlen -is negative the field is read only and its absolute value is the field length. -If +is the field width, if negative is readonly and the width is the absolute value, +if +.Dv 0 +the field becomes readonly and its value is the +.Ar init +width. +The field input is not printed to output if it is readonly. .Ar maxletters -is 0 it is the absolute value of +is the maximum input length, if is +.Dv 0 +its value is .Ar fieldlen . .Ar init -is a default value. +is the default value in the field. .Ar formrows is the graphical height of the list, .Dv 0 @@ -509,7 +526,7 @@ Dialog to get a string in input, .Ar init is the default value. .It Fl Fl menu Ar text Ar rows Ar cols Ar menurows Oo Ar name desc Oc ... -Builds a menu to select an item from a list, Space key is equivalent to Enter. +Builds a menu to select an item from a list, SPACE key is equivalent to ENTER. An item has a .Ar name and a @@ -526,19 +543,37 @@ at the position .Ar ylabel and .Ar xlabel , -a field to get the input with graphical length -.Ar fieldlen -at the position +a field to get the input at the position .Ar yfield and -.Ar xfield , +.Ar xfield . +.Ar fieldlen +is the field width, if negative is readonly and the width is the absolute value, +if +.Dv 0 +the field becomes readonly and its value is the +.Ar init +width. +The field input is not printed to output if +.Ar fieldlen +is less than or equal to +.Dv 0 . .Ar maxletters -is the maximum input length, +is the maximum input length, if is +.Dv 0 +its value is +.Ar fieldlen . .Ar init -is a default value, +is the default value in the field. .Ar flag -can be 0 for normal field, 1 to hide the typed characters and 2 to set the -field read only. +can customize +.Ar field : +.Dv 0 +normal, +.Dv 1 +hide typed characters, +.Dv 2 +readonly. .Ar formrows is the graphical height of the list, .Dv 0 @@ -581,7 +616,6 @@ otherwise Dialog to diplay a message without the .Dq Cancel button. -UP, DOWN, HOME, END, PAGEUP and PAGEDOWN keys are availble to scroll the text. .It Fl Fl passwordbox Ar text Ar rows Ar cols Op Ar init Dialog to get a password, .Ar init @@ -617,13 +651,12 @@ Dialog to select a value between and .Ar max , .Ar init -is the default value, the keys UP, DOWN, HOME, END, PAGEUP and PAGEDOWN can -change it. +is the default value. .It Fl Fl textbox Ar file Ar rows Ar cols Opens and prints .Ar file . -UP, DOWN, LEFT, RIGHT, HOME, END, PAGEUP and PAGEDOWN keys are available to -navigate the file, TAB changes button. +TAB changes button. +Extra keys 0, h, l, k, j are available to navigate the text. .Dq OK button is renamed .Dq EXIT . @@ -644,7 +677,6 @@ buttons are renamed .Dq Yes and .Dq \&No . -UP, DOWN, HOME, END, PAGEUP and PAGEDOWN keys are availble to scroll the text. .El .Sh ENVIRONMENT The following environment variables take effect only on startup, other options @@ -872,6 +904,8 @@ Options: .Fl Fl version , .Fl Fl yes-label . .Pp +Keys: Ctrl-l, F1. +.Pp Dialogs: .Fl Fl calendar , .Fl Fl checklist , diff --git a/contrib/bsddialog/utility/bsddialog.c b/contrib/bsddialog/utility/bsddialog.c index d4d1fc3e0f3a..3ba21eadf7a3 100644 --- a/contrib/bsddialog/utility/bsddialog.c +++ b/contrib/bsddialog/utility/bsddialog.c @@ -1,7 +1,7 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2021-2023 Alfonso Sabato Siciliano + * Copyright (c) 2021-2024 Alfonso Sabato Siciliano * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -140,7 +140,7 @@ static void getenv_exitcodes(void) value = (int)strtol(envvalue, NULL, 10); exitcodes[i].value = value; /* ITEM_HELP follows HELP without explicit setting */ - if(i == BSDDIALOG_HELP + 1) + if (i == BSDDIALOG_HELP + 1) exitcodes[BSDDIALOG_ITEM_HELP + 1].value = value; } } @@ -242,7 +242,7 @@ int main(int argc, char *argv[argc]) if (opt.dialogbuilder == NULL) break; if (opt.backtitle != NULL) - if(bsddialog_backtitle(&conf, opt.backtitle)) + if (bsddialog_backtitle(&conf, opt.backtitle)) exit_error(false, bsddialog_geterror()); retval = opt.dialogbuilder(&conf, text, rows, cols, argc, argv, &opt); diff --git a/contrib/bsddialog/utility/util_builders.c b/contrib/bsddialog/utility/util_builders.c index 2dfa20cb0f86..2e69994a0ec0 100644 --- a/contrib/bsddialog/utility/util_builders.c +++ b/contrib/bsddialog/utility/util_builders.c @@ -1,7 +1,7 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2021-2023 Alfonso Sabato Siciliano + * Copyright (c) 2021-2024 Alfonso Sabato Siciliano * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,6 +30,7 @@ #include <string.h> #include <time.h> #include <unistd.h> +#include <wchar.h> #include <bsddialog.h> #include <bsddialog_theme.h> @@ -532,6 +533,29 @@ int treeview_builder(BUILDER_ARGS) } /* form */ +static unsigned int strcols(const char *string) +{ + int w; + unsigned int ncol; + size_t charlen, mb_cur_max; + wchar_t wch; + mbstate_t mbs; + + mb_cur_max = MB_CUR_MAX; + ncol = 0; + memset(&mbs, 0, sizeof(mbs)); + while ((charlen = mbrlen(string, mb_cur_max, &mbs)) != 0 && + charlen != (size_t)-1 && charlen != (size_t)-2) { + if (mbtowc(&wch, string, mb_cur_max) < 0) + return (0); + if ((w = wcwidth(wch)) > 0) + ncol += w; + string += charlen; + } + + return (ncol); +} + static void print_form_items(int output, int nitems, struct bsddialog_formitem *items, int focusitem, struct options *opt) @@ -551,20 +575,21 @@ print_form_items(int output, int nitems, struct bsddialog_formitem *items, helpname = items[focusitem].bottomdesc; dprintf(opt->output_fd, " %s", helpname); } - if(opt->help_print_items == false) + if (opt->help_print_items == false) return; dprintf(opt->output_fd, "\n"); } for (i = 0; i < nitems; i++) { - dprintf(opt->output_fd, "%s\n", items[i].value); + if (!(items[i].flags & BSDDIALOG_FIELDREADONLY)) + dprintf(opt->output_fd, "%s\n", items[i].value); free(items[i].value); } } int form_builder(BUILDER_ARGS) { - int output, fieldlen, valuelen, focusitem; + int output, fieldlen, focusitem; unsigned int i, j, flags, formheight, nitems, sizeitem; struct bsddialog_formitem *items; @@ -591,12 +616,16 @@ int form_builder(BUILDER_ARGS) items[i].xfield = (u_int)strtoul(argv[j++], NULL, 10); fieldlen = (int)strtol(argv[j++], NULL, 10); - items[i].fieldlen = abs(fieldlen); + if (fieldlen == 0) + items[i].fieldlen = strcols(items[i].init); + else + items[i].fieldlen = abs(fieldlen); - valuelen = (int)strtol(argv[j++], NULL, 10); - items[i].maxvaluelen = valuelen == 0 ? abs(fieldlen) : valuelen; + items[i].maxvaluelen = (u_int)strtoul(argv[j++], NULL, 10); + if (items[i].maxvaluelen == 0) + items[i].maxvaluelen = items[i].fieldlen; - flags = (fieldlen < 0 ? BSDDIALOG_FIELDREADONLY : 0); + flags = (fieldlen <= 0) ? BSDDIALOG_FIELDREADONLY : 0; items[i].flags = flags; items[i].bottomdesc = opt->item_bottomdesc ? argv[j++] : ""; @@ -643,7 +672,7 @@ int inputbox_builder(BUILDER_ARGS) int mixedform_builder(BUILDER_ARGS) { - int output, focusitem; + int output, fieldlen, focusitem; unsigned int i, j, formheight, nitems, sizeitem; struct bsddialog_formitem *items; @@ -662,21 +691,35 @@ int mixedform_builder(BUILDER_ARGS) exit_error(false, "cannot allocate memory for form items"); j = 0; for (i = 0; i < nitems; i++) { - items[i].label = argv[j++]; - items[i].ylabel = (u_int)strtoul(argv[j++], NULL, 10); - items[i].xlabel = (u_int)strtoul(argv[j++], NULL, 10); - items[i].init = argv[j++]; - items[i].yfield = (u_int)strtoul(argv[j++], NULL, 10); - items[i].xfield = (u_int)strtoul(argv[j++], NULL, 10); - items[i].fieldlen = (u_int)strtoul(argv[j++], NULL, 10); + items[i].label = argv[j++]; + items[i].ylabel = (u_int)strtoul(argv[j++], NULL, 10); + items[i].xlabel = (u_int)strtoul(argv[j++], NULL, 10); + items[i].init = argv[j++]; + items[i].yfield = (u_int)strtoul(argv[j++], NULL, 10); + items[i].xfield = (u_int)strtoul(argv[j++], NULL, 10); + fieldlen = (int)strtol(argv[j++], NULL, 10); + if (fieldlen == 0) + items[i].fieldlen = strcols(items[i].init); + else + items[i].fieldlen = abs(fieldlen); items[i].maxvaluelen = (u_int)strtoul(argv[j++], NULL, 10); - items[i].flags = (u_int)strtoul(argv[j++], NULL, 10); - items[i].bottomdesc = opt->item_bottomdesc ? argv[j++] : ""; + if (items[i].maxvaluelen == 0) + items[i].maxvaluelen = items[i].fieldlen; + + items[i].flags = (u_int)strtoul(argv[j++], NULL, 10); + if (fieldlen <= 0) + items[i].flags |= BSDDIALOG_FIELDREADONLY; + + items[i].bottomdesc = opt->item_bottomdesc ? argv[j++] : ""; } focusitem = -1; output = bsddialog_form(conf, text, rows, cols, formheight, nitems, items, &focusitem); + for (i = 0; i < nitems; i++) { + if ((int)strtol(argv[i * sizeitem + 6], NULL, 10) > 0) + items[i].flags &= ~ BSDDIALOG_FIELDREADONLY; + } print_form_items(output, nitems, items, focusitem, opt); free(items); diff --git a/contrib/bsddialog/utility/util_cli.c b/contrib/bsddialog/utility/util_cli.c index 22bed6550fb5..a70de36a699e 100644 --- a/contrib/bsddialog/utility/util_cli.c +++ b/contrib/bsddialog/utility/util_cli.c @@ -85,7 +85,7 @@ enum OPTS { LEFT3_BUTTON, LEFT3_EXIT_CODE, LOAD_THEME, - MAX_INPUT, + MAX_INPUT_FORM, NO_CANCEL, NO_DESCRIPTIONS, NO_LINES, @@ -202,7 +202,7 @@ static struct option longopts[] = { {"left3-button", required_argument, NULL, LEFT3_BUTTON}, {"left3-exit-code", required_argument, NULL, LEFT3_EXIT_CODE}, {"load-theme", required_argument, NULL, LOAD_THEME}, - {"max-input", required_argument, NULL, MAX_INPUT}, + {"max-input", required_argument, NULL, MAX_INPUT_FORM}, {"no-cancel", no_argument, NULL, NO_CANCEL}, {"nocancel", no_argument, NULL, NO_CANCEL}, {"no-descriptions", no_argument, NULL, NO_DESCRIPTIONS}, @@ -546,7 +546,7 @@ parseargs(int argc, char **argv, struct bsddialog_conf *conf, case LOAD_THEME: opt->loadthemefile = optarg; break; - case MAX_INPUT: + case MAX_INPUT_FORM: opt->max_input_form = (u_int)strtoul(optarg, NULL, 10); break; case NO_CANCEL: diff --git a/contrib/bsddialog/utility/util_theme.c b/contrib/bsddialog/utility/util_theme.c index c313d743252b..a95cadacc1b0 100644 --- a/contrib/bsddialog/utility/util_theme.c +++ b/contrib/bsddialog/utility/util_theme.c @@ -1,7 +1,7 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2022-2023 Alfonso Sabato Siciliano + * Copyright (c) 2022-2024 Alfonso Sabato Siciliano * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -166,7 +166,7 @@ void savetheme(const char *file) exit_error(false, "cannot save theme: %s", bsddialog_geterror()); - if(time(&clock) < 0) + if (time(&clock) < 0) exit_error(false, "cannot save profile getting current time"); if ((fp = fopen(file, "w")) == NULL) exit_error(false, "cannot open %s to save profile", file); @@ -235,11 +235,11 @@ void loadtheme(const char *file, bool compatibility) exit_error(false, "Cannot get current theme: %s", bsddialog_geterror()); - if((fp = fopen(file, "r")) == NULL) + if ((fp = fopen(file, "r")) == NULL) exit_error(false, "Cannot open theme \"%s\" file", file); - while(fgets(line, BUFSIZ, fp) != NULL) { - if(line[0] == '#' || line[0] == '\n') + while (fgets(line, BUFSIZ, fp) != NULL) { + if (line[0] == '#' || line[0] == '\n') continue; /* superfluous, only for efficiency */ sscanf(line, "%s", name); value = NULL; /* useless init, fix compiler warning */ @@ -322,7 +322,7 @@ void loadtheme(const char *file, bool compatibility) fclose(fp); - if(bsddialog_set_theme(&t) != BSDDIALOG_OK) + if (bsddialog_set_theme(&t) != BSDDIALOG_OK) exit_error(false, bsddialog_geterror()); } |