Skip to content

Commit

Permalink
contrib/bsddialog: Import version 1.0.2
Browse files Browse the repository at this point in the history
Implicitly import also 1.0.1, both versions are for fixing and
feature requests.

Fixing:
Change --mixedform behavior to fix a bsdinstall fault avoiding
to change the command line in wlanconfig.

Feature requests:
 * Add keys to navigate menus.
 * Add key to redraw dialogs.
 * Avoid to handle env NCURSES_NO_UTF8_ACS in PuTTY.

See '2024-04-11 Version 1.0.2' and '2023-11-16 Version 1.0.1' in
/usr/src/contrib/bsddialog/CHANGELOG for more detailed information.

PR:			274472
Differential Revision:	D42380

Merge commit 'be8846bd9e069f4a6bea3d769005bea96cf43990'
  • Loading branch information
alfonsosiciliano committed May 16, 2024
2 parents abb1a13 + be8846b commit a6d8be4
Show file tree
Hide file tree
Showing 22 changed files with 469 additions and 224 deletions.
32 changes: 32 additions & 0 deletions contrib/bsddialog/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
2024-04-11 Version 1.0.2

Utility:
improvements and changes for --form and --mixedform:
* add: <maxletters> 0 sets <maxletters> like <fieldlen>.
* add: <fieldlen> 0 sets <fieldlen> like <init> width and readonly.
* change: <maxletters> 0 was an error (remains error in lib).
* change: <fieldlen> 0 was an error (remains error in lib)
(<fieldlen> 0 and <init> "" is still an error.).

Library and implicitly utility:
* add: Ctrl-l to redraw dialog.
Request stable@freebsd.org January 2024.
* add: -, +, Ctrl-p, Ctrl-n for several dialogs.
+, - request for menus, private feature request.
Ctrl-p, Ctrl-n for menu, request hackers@freebsd.org February 2024.
* fix: escaped text ending with an escape symbol.
* change: truncate mixedgauge long (over the screen/minibars)
minilabels adding "...". As a result, avoid check-size error.
https://gitlab.com/alfix/bsddialog/-/issues/6.
* change: invert UP/DOWN keys to set a rangebox value.


2023-11-16 Version 1.0.1

Library Internal Refactoring:
* add: arrow macro handlers.
* change: Box-drawing characters, from utf8 to wide chars to avoid to
handle "env NCURSES_NO_UTF8_ACS=1".
Request https://bugs.freebsd.org/274472,
Rationale https://reviews.freebsd.org/D42380.

2023-08-01 Version 1.0

Utility:
Expand Down
2 changes: 1 addition & 1 deletion contrib/bsddialog/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

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 are met:
Expand Down
12 changes: 6 additions & 6 deletions contrib/bsddialog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#
# Written in 2023 by Alfonso Sabato Siciliano

OUTPUT = bsddialog
export VERSION=1.0
OUTPUT = bsddialog
export VERSION=1.0.2
.CURDIR ?= ${CURDIR}
LIBPATH = ${.CURDIR}/lib
LIBBSDDIALOG = ${LIBPATH}/libbsddialog.so
Expand All @@ -13,14 +13,14 @@ UTILITYPATH = ${.CURDIR}/utility
RM= rm -f
LN = ln -s -f

### cli options ###
# port/pkg Makefile: 'MAKE_ARGS = -DNORPATH'
### command-line options ###
# FreeBSD port Makefile: 'MAKE_ARGS = -DNORPATH'
NORPATH ?=
export DISABLERPATH=${NORPATH}
# `make -DDEBUG`
# `gmake DEBUG=1`
# Debug: `make -DDEBUG` or `gmake DEBUG=1`
DEBUG ?=
export ENABLEDEBUG=${DEBUG}
###################

all : ${OUTPUT}

Expand Down
27 changes: 18 additions & 9 deletions contrib/bsddialog/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# BSDDialog 1.0
# BSDDialog 1.0.2

This project provides **bsddialog** and **libbsddialog**, an utility
and a library to build scripts and tools with TUI dialogs and widgets.
Expand Down Expand Up @@ -114,18 +114,27 @@ in the _Public Domain_ to build new projects:

## TODO and Ideas

- menubar feature
- key callback
- Right-To-Left text
- menubar feature.
- key callback.
- Right-To-Left text.
- some terminal does not hide the cursor, move it bottom-right before to getch.
- refactor backtitle: multiline, conf.backtitle, WINDOW \*dialog.backtitle.
- refactor bottomdesc: WINDOW \*dialog.bottomdesc -> fix expandig screen.
- accessibility https://wiki.freebsd.org/Accessibility/Wishlist/Base
- refactor backtitle: add WINDOW \*dialog.backtitle for multiline and fix expanding screen.
- refactor bottomdesc: add WINDOW \*dialog.bottomdesc to fix expandig screen.
- accessibility https://wiki.freebsd.org/Accessibility/Wishlist/Base.
- add bool conf.menu.depthlines.
- implement custom getopt\_long().
- refactor/redesign gauge().
- improve grey lines expanding terminal (maybe redrawwin() in hide\_dialog()).
- more restrictive strtol() and strtoul().
- implement global buttons handler.
- add/move external tutorial.
- implement menutype.min_on.
- doc: external tutorial, theming guide.
- implement menutype.min\_on.
- improve refresh at startup, avoid dialog refresh before drawing text.
- add debug API: bsddialog\_debug(y,x,refresh,"fmt",...).
- add mouse support.
- use alarm(2) for bsddialog\_pause.
- delete form fieldlen constraint, hide or truncate long field in little screens.
- improve --inputbox autosizing, consider also input length.
- fix --form "" 0 0 0 Label 1 0 Init 1 12 0 0 (with 0 editable field).
- fix --mixedform "" 0 0 0 Label 1 0 Init 1 12 0 0 2 (with 0 editable field).
- add *text* customization to --hmsg *help-message*
2 changes: 1 addition & 1 deletion contrib/bsddialog/examples_library/gauge.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main()
conf.title = "gauge";
rv = bsddialog_gauge(&conf, "Example", 7, 30, 0, fd[0], "SEP", "EOF");
bsddialog_end();
if(rv == BSDDIALOG_ERROR)
if (rv == BSDDIALOG_ERROR)
printf("Error: %s\n", bsddialog_geterror());

return (0);
Expand Down
2 changes: 1 addition & 1 deletion contrib/bsddialog/examples_library/mixedgauge.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int main()
minipercs[12] = i * 10;
retval= bsddialog_mixedgauge(&conf, "Example", 20, 40,
50 + i * 5, NMINIBAR, minilabels, minipercs);
if(retval == BSDDIALOG_ERROR)
if (retval == BSDDIALOG_ERROR)
exit_error();
sleep(1);
}
Expand Down
86 changes: 68 additions & 18 deletions contrib/bsddialog/lib/barbox.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,11 +36,11 @@
#include "bsddialog_theme.h"
#include "lib_util.h"

#define BARPADDING 2 /* widget border | BARPADDING | box bar */
#define BARPADDING 2 /* Dialog border | BARPADDING | box bar */
#define BOXBORDERS 2
#define MIN_WBAR 15
#define MIN_WBOX (BARPADDING + BOXBORDERS + MIN_WBAR + BARPADDING)
#define MIN_WMGBAR 18
#define MIN_WMGBAR 18 /* Mixedgauge main bar */
#define MIN_WMGBOX (BARPADDING + BOXBORDERS + MIN_WMGBAR + BARPADDING)
#define HBOX 3
#define WBOX(d) ((d)->w - BORDERS - BARPADDING - BARPADDING)
Expand Down Expand Up @@ -206,12 +206,64 @@ bsddialog_gauge(struct bsddialog_conf *conf, const char *text, int rows,
}

/* Mixedgauge */
static void
mvwaddcstr(WINDOW *win, int y, int x, const char *mbstring, unsigned int cols)
{
size_t charlen, n, w;
mbstate_t mbs;
const char *pmbstring;
wchar_t wch;

w = n = 0;
pmbstring = mbstring;
memset(&mbs, 0, sizeof(mbs));
while ((charlen = mbrlen(pmbstring, MB_CUR_MAX, &mbs)) != 0 &&
charlen != (size_t)-1 && charlen != (size_t)-2) {
mbtowc(&wch, pmbstring, charlen);
w += (wch == L'\t') ? TABSIZE : wcwidth(wch);
if (w > cols)
break;
pmbstring += charlen;
n += charlen;
}
mvwaddnstr(win, y, x, mbstring, n);
if(w > cols)
mvwaddstr(win, y, (x + cols) - 3, "...");
}

static int
mixedgauge_size_position(struct dialog *d, int nminibars,
const char **minilabels, int *htext)
{
int i, max_minibarlen;

max_minibarlen = 0;
for (i = 0; i < (int)nminibars; i++)
max_minibarlen = MAX(max_minibarlen,
(int)strcols(CHECK_STR(minilabels[i])));
max_minibarlen += 18; /* ' '<max_minibarlen>' ['13'] ' */
max_minibarlen = MAX(max_minibarlen, MIN_WMGBOX); /* mainbar */

if (set_widget_size(d->conf, d->rows, d->cols, &d->h, &d->w) != 0)
return (BSDDIALOG_ERROR);
if (set_widget_autosize(d->conf, d->rows, d->cols, &d->h, &d->w,
d->text, htext, &d->bs, nminibars + HBOX, max_minibarlen) != 0)
return (BSDDIALOG_ERROR);
if (widget_checksize(d->h, d->w, &d->bs, nminibars + HBOX,
MIN_WMGBOX) != 0)
return (BSDDIALOG_ERROR);
if (set_widget_position(d->conf, &d->y, &d->x, d->h, d->w) != 0)
return (BSDDIALOG_ERROR);

return (0);
}

static int
do_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows, int cols,
unsigned int mainperc, unsigned int nminibars, const char **minilabels,
int *minipercs, bool color)
{
int i, miniperc, max_minibarlen;
int i, miniperc;
int ystext, htext;
int minicolor, red, green;
struct bar b;
Expand All @@ -223,17 +275,9 @@ do_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows, int cols,
red = bsddialog_color(BSDDIALOG_WHITE,BSDDIALOG_RED, BSDDIALOG_BOLD);
green = bsddialog_color(BSDDIALOG_WHITE,BSDDIALOG_GREEN,BSDDIALOG_BOLD);

max_minibarlen = 0;
for (i = 0; i < (int)nminibars; i++)
max_minibarlen = MAX(max_minibarlen,
(int)strcols(CHECK_STR(minilabels[i])));
max_minibarlen += 3 + 16; /* seps + [...] */
max_minibarlen = MAX(max_minibarlen, MIN_WMGBOX); /* mainbar */

if (prepare_dialog(conf, text, rows, cols, &d) != 0)
return (BSDDIALOG_ERROR);
if (dialog_size_position(&d, nminibars + HBOX, max_minibarlen,
&htext) != 0)
if (mixedgauge_size_position(&d, nminibars, minilabels, &htext) != 0)
return (BSDDIALOG_ERROR);
if (draw_dialog(&d) != 0)
return (BSDDIALOG_ERROR);
Expand All @@ -249,7 +293,7 @@ do_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows, int cols,
/* label */
if (color && miniperc >= 0)
wattron(d.widget, A_BOLD);
mvwaddstr(d.widget, i+1, 2, CHECK_STR(minilabels[i]));
mvwaddcstr(d.widget, i+1, 2, CHECK_STR(minilabels[i]), d.w-20);
if (color && miniperc >= 0)
wattroff(d.widget, A_BOLD);
/* perc */
Expand Down Expand Up @@ -472,10 +516,12 @@ bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
}
break;
case '\t': /* TAB */
case KEY_CTRL('n'):
case KEY_RIGHT:
d.bs.curr = (d.bs.curr + 1) % d.bs.nbuttons;
DRAW_BUTTONS(d);
break;
case KEY_CTRL('p'):
case KEY_LEFT:
d.bs.curr--;
if (d.bs.curr < 0)
Expand All @@ -502,15 +548,17 @@ bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
currvalue = max;
b.toupdate = true;
break;
case '-':
case KEY_UP:
if (currvalue < max) {
currvalue++;
if (currvalue > min) {
currvalue--;
b.toupdate = true;
}
break;
case '+':
case KEY_DOWN:
if (currvalue > min) {
currvalue--;
if (currvalue < max) {
currvalue++;
b.toupdate = true;
}
break;
Expand All @@ -523,6 +571,7 @@ bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
if (rangebox_redraw(&d, &b, &bigchange) != 0)
return (BSDDIALOG_ERROR);
break;
case KEY_CTRL('l'):
case KEY_RESIZE:
if (rangebox_redraw(&d, &b, &bigchange) != 0)
return (BSDDIALOG_ERROR);
Expand Down Expand Up @@ -641,6 +690,7 @@ bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows,
if (pause_redraw(&d, &b) != 0)
return (BSDDIALOG_ERROR);
break;
case KEY_CTRL('l'):
case KEY_RESIZE:
if (pause_redraw(&d, &b) != 0)
return (BSDDIALOG_ERROR);
Expand Down
37 changes: 26 additions & 11 deletions contrib/bsddialog/lib/bsddialog.3
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd July 28, 2023
.Dd March 16, 2024
.Dt BSDDIALOG 3
.Os
.Sh NAME
Expand Down Expand Up @@ -719,9 +719,8 @@ the loop ends reading
builds a dialog without buttons and returns instantly.
.Pp
.Fn bsddialog_menu
builds a dialog to select an item from a list via SPACE or ENTER.
An item is
defined like:
builds a dialog to select an item from a list via SPACE and ENTER.
An item is defined like:
.Pp
.Bd -literal -offset indent -compact
struct bsddialog_menuitem {
Expand Down Expand Up @@ -878,14 +877,13 @@ and
.Fa max .
.Fa value
is the default value on startup and the selected value at exit.
The current value is printed inside a bar, the keys UP, DOWN, HOME, END, PAGEUP
and PAGEDOWN can change it.
The current value is printed inside a bar.
.Pp
.Fn bsddialog_textbox
opens and prints
.Fa file .
UP, DOWN, LEFT, RIGHT, HOME, END, PAGEUP and PAGEDOWN keys are available to
navigate the file, TAB changes button.
TAB key changes button.
Extra keys 0, h, l, k, j are available to navigate the text.
.Dq OK
button is renamed
.Dq EXIT .
Expand All @@ -901,7 +899,24 @@ are default values on startup, selected time at exit.
.Fn bsddialog_yesno
provides a dialog for a
.Dq Yes-No Question ,
the labels on buttons are Yes and No.
the labels on buttons are
.Dq Yes
and
.Dq No .
.Ss Keys
.Bl -tag -width Ds
.It Ctrl-l
Redraw the dialog.
.It F1
Refer to
.Fa conf.key.f1_file
and
.Fa conf.key.f1_message .
.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 Theme
The graphical properties are global to the library.
They are represented by
Expand Down Expand Up @@ -1089,7 +1104,7 @@ case BSDDIALOG_YES:
printf("Yes\\n");
break;
case BSDDIALOG_NO
printf("NO\\n");
printf("No\\n");
break;
case BSDDIALOG_ERROR:
printf("Error: %s\\n", bsddialog_geterror());
Expand Down
Loading

0 comments on commit a6d8be4

Please sign in to comment.