diff --git a/.gitignore b/.gitignore index ee80e5f5a073..557ad3300d1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,26 @@ bsddialog *.o *~ +*.a examples_library/buildlist examples_library/checklist examples_library/datebox examples_library/form examples_library/menu examples_library/mixedlist examples_library/radiolist examples_library/theme examples_library/treeview examples_library/infobox examples_library/msgbox examples_library/pause examples_library/rangebox examples_library/sade examples_library/timebox examples_library/yesno *.gz lib/libbsddialog.so* BSDDIALOG.geany BSDDIALOG.tags *.core -bsdinstall/* +freebsd-lab/ diff --git a/bsddialog.1 b/bsddialog.1 index 2846b77547a9..bfee3229bd1f 100644 --- a/bsddialog.1 +++ b/bsddialog.1 @@ -1,52 +1,66 @@ .\" .\" Copyright (c) 2021 Alfonso Sabato Siciliano .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .Dd December 11, 2021 .Dt BSDDIALOG 1 .Os .Sh NAME .Nm bsddialog -.Nd build dialogs and widgets with a TUI +.Nd terminal dialogs and widgets .Sh SYNOPSIS .Nm bsddialog -.Op Fl options -.Ar +.Fl -help +.Nm bsddialog +.Fl -version +.Nm bsddialog +.Op Fl Ar -common-opts +.Fl Ar -widget +.Fl Artext +.Fl Arheight +.Fl Arwidth +.Op Fl Ar -widget-opts .Sh DESCRIPTION The -.Nm -utility processes files ... +.Nm BSDDialog +is an utility to write a script with a Text User Interface. It can build +dialogs and widgets: to show messages, to get input and to inform about a +computation status. .\" .Sh ENVIRONMENT .\" For sections 1, 6, 7, and 8 only. .\" .Sh FILES .\" .Sh EXIT STATUS .\" For sections 1, 6, and 8 only. .\" .Sh EXAMPLES .\" .Sh DIAGNOSTICS .\" For sections 1, 4, 6, 7, 8, and 9 printf/stderr messages only. -.\" .Sh SEE ALSO -.\" .Xr foobar 1 +.Sh SEE ALSO +.Xr bsddialog 3 .\" .Sh HISTORY .\" .Sh AUTHORS -.\" .Sh CAVEATS -.\" .Sh BUGS +.Sh CAVEATS +autosize +compatibility text +.Sh BUGS +buildlist +forms diff --git a/bsddialog.c b/bsddialog.c index 6fc0d834a1ad..aa87dec2962b 100644 --- a/bsddialog.c +++ b/bsddialog.c @@ -1,1349 +1,1363 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2021 Alfonso Sabato Siciliano * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #define BSDDIALOG_VERSION "0.0.1" enum OPTS { /* Common options */ ASCII_LINES = '?' + 1, ASPECT_RATIO, BACKTITLE, BEGIN_X, BEGIN_Y, CANCEL_LABEL, CLEAR, COLORS, CR_WRAP, DATE_FORMAT, DEFAULTNO, DEFAULT_BUTTON, DEFAULT_ITEM, EXIT_LABEL, EXTRA_BUTTON, EXTRA_LABEL, HELP, HELP_BUTTON, HELP_LABEL, HELP_STATUS, HELP_TAGS, HFILE, HLINE, IGNORE, INSECURE, + ITEM_DEPTH, ITEM_HELP, ITEM_PREFIX, MAX_INPUT, NO_CANCEL, NOCANCEL, NO_COLLAPSE, NO_ITEMS, NO_LABEL, NO_LINES, NO_NL_EXPAND, NO_OK, NOOK, NO_TAGS, NO_SHADOW, OK_LABEL, OUTPUT_FD, OUTPUT_SEPARATOR, PRINT_MAXSIZE, PRINT_SIZE, PRINT_VERSION, QUOTED, SEPARATE_OUTPUT, SEPARATOR, SHADOW, SINGLE_QUOTED, SLEEP, STDERR, STDOUT, THEME, TIME_FORMAT, TITLE, TRIM, VERSION, YES_LABEL, /* Widgets */ BUILDLIST, CHECKLIST, DATEBOX, FORM, GAUGE, INFOBOX, INPUTBOX, MENU, MIXEDFORM, MIXEDGAUGE, MSGBOX, PASSWORDBOX, PASSWORDFORM, PAUSE, RADIOLIST, RANGEBOX, TEXTBOX, TIMEBOX, TREEVIEW, YESNO, }; /* libbsddialog does not support NULL string for now */ static char *nostring = ""; /* Menus flags and options */ static bool item_prefix_flag, item_bottomdesc_flag, item_output_sepnl_flag; static bool item_singlequote_flag, list_items_on_flag, item_tag_help_flag; -static bool item_always_quote_flag; +static bool item_always_quote_flag, item_depth_flag; static char *item_output_sep_flag; /* Time and calendar options */ static char *date_fmt_flag, *time_fmt_flag; /* Forms */ static int max_input_form_flag; /* General flags and options */ static int output_fd_flag; void usage(void); /* widgets */ #define BUILDER_ARGS struct bsddialog_conf conf, char* text, int rows, \ int cols, int argc, char **argv, char *errbuf int buildlist_builder(BUILDER_ARGS); int checklist_builder(BUILDER_ARGS); int datebox_builder(BUILDER_ARGS); int form_builder(BUILDER_ARGS); int gauge_builder(BUILDER_ARGS); int infobox_builder(BUILDER_ARGS); int inputbox_builder(BUILDER_ARGS); int menu_builder(BUILDER_ARGS); int mixedform_builder(BUILDER_ARGS); int mixedgauge_builder(BUILDER_ARGS); int msgbox_builder(BUILDER_ARGS); int passwordbox_builder(BUILDER_ARGS); int passwordform_builder(BUILDER_ARGS); int pause_builder(BUILDER_ARGS); int radiolist_builder(BUILDER_ARGS); int rangebox_builder(BUILDER_ARGS); int textbox_builder(BUILDER_ARGS); int timebox_builder(BUILDER_ARGS); int treeview_builder(BUILDER_ARGS); int yesno_builder(BUILDER_ARGS); static void custom_text(bool cr_wrap, bool no_collapse, bool no_nl_expand, bool trim, char *text, char *buf) { int i, j; i = j = 0; while (text[i] != '\0') { switch (text[i]) { case '\\': buf[j] = '\\'; switch (text[i+1]) { case '\\': i++; break; case 'n': if (no_nl_expand) { j++; buf[j] = 'n'; } else buf[j] = '\n'; i++; break; case 't': if (no_collapse) { j++; buf[j] = 't'; } else buf[j] = '\t'; i++; break; } break; case '\n': buf[j] = cr_wrap ? ' ' : '\n'; break; case '\t': buf[j] = no_collapse ? '\t' : ' '; break; default: buf[j] = text[i]; } i++; j += (buf[j] == ' ' && trim && j > 0 && buf[j-1] == ' ') ? 0 : 1; } buf[j] = '\0'; } void usage(void) { printf("usage: bsddialog --help\n" " bsddialog --version\n" " bsddialog [--] -- " " [--]\n"); printf("\n"); printf("Common Options:\n"); printf("--ascii-lines, --aspect , --backtitle , " "--begin-x , --begin-y , --cancel-label , " "--clear, --colors, --date-format , " "--default-button