bsddialog: import version 0.1
This commit is contained in:
parent
77a55d2c3b
commit
02db4a1234
@ -1,14 +1,14 @@
|
||||
# PUBLIC DOMAIN - NO WARRANTY, see:
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
#
|
||||
# Written by Alfonso Sabato Siciliano
|
||||
# Written in 2021 by Alfonso Sabato Siciliano
|
||||
|
||||
OUTPUT= bsddialog
|
||||
SOURCES= bsddialog.c
|
||||
OBJECTS= $(SOURCES:.c=.o)
|
||||
LIBPATH= ./lib
|
||||
LIBBSDDIALOG= $(LIBPATH)/libbsddialog.so
|
||||
CFLAGS= -g -Wall -I$(LIBPATH)
|
||||
CFLAGS= -Wall -I$(LIBPATH)
|
||||
LDFLAGS= -Wl,-rpath=$(LIBPATH) -L$(LIBPATH) -lbsddialog
|
||||
RM = rm -f
|
||||
|
||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2021, Alfonso Sabato Siciliano
|
||||
Copyright (c) 2021-2022, Alfonso Sabato Siciliano
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
25
Makefile
25
Makefile
@ -1,7 +1,7 @@
|
||||
# Any copyright is dedicated to the Public Domain, see:
|
||||
# PUBLIC DOMAIN - NO WARRANTY, see:
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
#
|
||||
# Written by Alfonso Sabato Siciliano
|
||||
# Written in 2021 by Alfonso Sabato Siciliano
|
||||
|
||||
OUTPUT= bsddialog
|
||||
SOURCES= bsddialog.c
|
||||
@ -9,8 +9,19 @@ OBJECTS= ${SOURCES:.c=.o}
|
||||
LIBPATH= ${.CURDIR}/lib
|
||||
LIBBSDDIALOG= ${LIBPATH}/libbsddialog.so
|
||||
|
||||
CFLAGS= -Wall -I${LIBPATH}
|
||||
LDFLAGS= -Wl,-rpath=${LIBPATH} -L${LIBPATH} -lbsddialog
|
||||
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
|
||||
# `make -DDEBUG`
|
||||
.if defined(DEBUG)
|
||||
CFLAGS= -g -Wall -I${LIBPATH}
|
||||
LIBDEBUG= -DDEBUG
|
||||
.endif
|
||||
LDFLAGS+= -Wl,-rpath=${LIBPATH} -L${LIBPATH} -lbsddialog
|
||||
|
||||
BINDIR= /usr/local/bin
|
||||
MAN= ${OUTPUT}.1
|
||||
@ -26,11 +37,7 @@ ${OUTPUT}: ${LIBBSDDIALOG} ${OBJECTS}
|
||||
${CC} ${LDFLAGS} ${OBJECTS} -o ${.PREFIX}
|
||||
|
||||
${LIBBSDDIALOG}:
|
||||
.if defined(PORTNCURSES)
|
||||
make -C ${LIBPATH} -DPORTNCURSES
|
||||
.else
|
||||
make -C ${LIBPATH}
|
||||
.endif
|
||||
make -C ${LIBPATH} ${LIBDEBUG}
|
||||
|
||||
.c.o:
|
||||
${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
|
||||
|
159
README.md
159
README.md
@ -1,13 +1,21 @@
|
||||
# BSDDialog
|
||||
# BSDDialog 0.1
|
||||
|
||||
**Work In Progress!**
|
||||
|
||||
This project provides **bsddialog** and **libbsddialog**, an utility and a
|
||||
library to build scripts and tools with *TUI Widgets*.
|
||||
library to build scripts and tools with TUI dialogs and widgets.
|
||||
|
||||
Description:
|
||||
|
||||
## Intro
|
||||
|
||||
Briefly:
|
||||
<https://www.freebsd.org/status/report-2021-04-2021-06/#_bsddialog_tui_widgets>
|
||||
|
||||
Utility:
|
||||
<https://alfonsosiciliano.gitlab.io/posts/2021-12-07-bsddialog.html>
|
||||
|
||||
Library:
|
||||
<https://alfonsosiciliano.gitlab.io/posts/2022-01-16-libbsddialog.html>
|
||||
|
||||
Screenshots:
|
||||
<https://www.flickr.com/photos/alfonsosiciliano/albums/72157720215006074>
|
||||
|
||||
@ -23,35 +31,39 @@ FreeBSD:
|
||||
% ./bsddialog --msgbox "Hello World!" 8 20
|
||||
```
|
||||
|
||||
If you are using XFCE install
|
||||
[devel/ncurses](https://www.freshports.org/devel/ncurses/)
|
||||
|
||||
```
|
||||
% sudo pkg install ncurses
|
||||
% git clone https://gitlab.com/alfix/bsddialog.git
|
||||
% cd bsddialog
|
||||
% make -DPORTNCURSES
|
||||
% ./bsddialog --msgbox "Hello World!" 8 20
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
![screenshot](screenshot.png)
|
||||
|
||||
|
||||
Examples utility:
|
||||
## Utility
|
||||
|
||||
**Dialogs:**
|
||||
|
||||
--checklist, --datebox, --form, --gauge, --inputbox, --menu, --mixedform,
|
||||
--mixedgauge, --msgbox, --passwordbox, --passwordform, --pause, --radiolist,
|
||||
--rangebox, --textbox, --timebox, --treeview, --yesno.
|
||||
|
||||
**Manual**
|
||||
|
||||
- [bsddialog(1)](https://alfonsosiciliano.gitlab.io/posts/2022-01-26-manual-bsddialog.html)
|
||||
|
||||
|
||||
**Examples**:
|
||||
|
||||
```
|
||||
% ./bsddialog --title msgbox --msgbox "Hello World!" 5 30
|
||||
% ./bsddialog --theme default --title msgbox --msgbox "Hello World!" 5 30
|
||||
% ./bsddialog --begin-y 2 --title yesno --yesno "Hello World!" 5 30
|
||||
% ./bsddialog --ascii-lines --pause "Hello World!" 8 50 5
|
||||
% ./bsddialog --checklist "Space to select" 0 0 0 Name1 Desc1 off Name2 Desc2 on Name3 Desc3 off
|
||||
% ./bsddialog --backtitle "TITLE" --title yesno --hline "bsddialog" --yesno "Hello World!" 5 25
|
||||
% ./bsddialog --extra-button --help-button --defaultno --yesno "Hello World!" 0 0
|
||||
% ./bsddialog --backtitle "TITLE" --title msgbox --msgbox "Hello World!" 5 30
|
||||
% ./bsddialog --theme blackwhite --title msgbox --msgbox "Hello World!" 5 30
|
||||
% ./bsddialog --begin-y 2 --default-no --title yesno --yesno "Hello World!" 5 30
|
||||
% ./bsddialog --ascii-lines --pause "Hello World!" 8 50 10
|
||||
% ./bsddialog --checklist "Space to select" 0 0 0 Name1 Desc1 off Name2 Desc2 on
|
||||
% ./bsddialog --title yesno --hline "bsddialog" --yesno "Hello World!" 5 25
|
||||
% ./bsddialog --extra-button --help-button --yesno "Hello World!" 0 0
|
||||
```
|
||||
and
|
||||
|
||||
and [Examples](https://gitlab.com/alfix/bsddialog/-/tree/main/examples_utility)
|
||||
in the _Public Domain_ to build new projects:
|
||||
```
|
||||
% sh ./examples_utility/buildlist.sh
|
||||
% sh ./examples_utility/checklist.sh
|
||||
% sh ./examples_utility/form.sh
|
||||
% sh ./examples_utility/gauge.sh
|
||||
@ -68,12 +80,26 @@ and
|
||||
% sh ./examples_utility/yesno.sh
|
||||
```
|
||||
|
||||
Examples library:
|
||||
## Library
|
||||
|
||||
**API**
|
||||
|
||||
- [bsddialog.h](https://gitlab.com/alfix/bsddialog/-/blob/main/lib/bsddialog.h)
|
||||
- [bsddialog\_theme.h](https://gitlab.com/alfix/bsddialog/-/blob/main/lib/bsddialog_theme.h)
|
||||
|
||||
|
||||
**Manual**
|
||||
|
||||
- [bsddialog(3)](https://alfonsosiciliano.gitlab.io/posts/2022-01-15-manual-libbsddialog.html)
|
||||
|
||||
|
||||
**Examples**:
|
||||
|
||||
[Examples](https://gitlab.com/alfix/bsddialog/-/tree/main/examples_library)
|
||||
in the _Public Domain_ to build new projects:
|
||||
```
|
||||
% cd examples_library
|
||||
% sh compile
|
||||
% ./buildlist
|
||||
% ./compile
|
||||
% ./datebox
|
||||
% ./form
|
||||
% ./infobox
|
||||
@ -83,85 +109,8 @@ Examples library:
|
||||
% ./pause
|
||||
% ./radiolist
|
||||
% ./rangebox
|
||||
% ./sade
|
||||
% ./theme
|
||||
% ./timebox
|
||||
% ./treeview
|
||||
% ./yesno
|
||||
```
|
||||
|
||||
Use Cases:
|
||||
|
||||
- [portconfig](https://gitlab.com/alfix/portconfig)
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
**Common Options:**
|
||||
|
||||
--ascii-lines, --aspect *ratio* (for infobox, msgbox and yesno),
|
||||
--backtitle *backtitle*, --begin-x *x* (--begin *y y*),
|
||||
(--begin *y x*), --cancel-label *string*, -clear (test with multiple widgets),
|
||||
--colors, --date-format *format*, --default-button *string*, --defaultno,
|
||||
--default-item *string*,
|
||||
--exit-label *string*, --extra-button, --extra-label *string*,
|
||||
--hfile *filename* (for completed widgets), --help, --help-button,
|
||||
--help-label *string*, --help-status, --help-tags, --hline *string*, --ignore,
|
||||
--insecure, --item-help, --max-input *size*, --no-cancel, --nocancel,
|
||||
--no-label *string*, --no-items, --no-lines, --no-ok,
|
||||
--nook, --no-shadow, --no-tags, --ok-label *string*, --output-fd *fd*,
|
||||
--output-separator *string*, --print-version,
|
||||
--print-size (todo move lib -> utility), --quoted (quotes all != dialog),
|
||||
--print-maxsize, --shadow, --single-quoted (add --quote-with *ch*?),
|
||||
--separator *string* (alias --output-separator *string*),
|
||||
--separate-output (rename --separate-output-withnl?), --sleep *secs*, --stderr,
|
||||
--stdout, --theme *string* ("bsddialog", "dialog", "blackwhite"),
|
||||
--time-format *format*, --title *title*, --version, --yes-label *string*.
|
||||
|
||||
**Widgets:**
|
||||
|
||||
infobox (do not clear the screen), msgbox,
|
||||
yesno (dialog renames "yes/no" -> "ok/cancel" with --extra-button --help-button).
|
||||
checklist, radiolist, menu, mixedlist, treeview, textbox, mixedgauge, datebox,
|
||||
timebox, gauge, rangebox, pause.
|
||||
|
||||
|
||||
Without resize:
|
||||
|
||||
form, inputbox, mixedform, passwordbox, passwordform.
|
||||
|
||||
|
||||
Without autosize, resize, F1:
|
||||
|
||||
buildlist
|
||||
|
||||
|
||||
|
||||
## TODO
|
||||
|
||||
|
||||
**Common Options:**
|
||||
|
||||
| Option | Status | Note |
|
||||
| ---------------------------- | ----------- | ------------------------------- |
|
||||
| --cr-wrap | In progress | text |
|
||||
| --no-collapse | In progress | text |
|
||||
| --no-nl-expand | In progress | text |
|
||||
| --trim | In progress | text |
|
||||
|
||||
|
||||
To evaluate / Not planned in the short term / not in bsdinstall:
|
||||
|
||||
--create-rc *file*, --iso-week, --no-mouse, --print-text-only *str h w*,
|
||||
--print-text-size *str h w*, --reorder, -scrollbar, --separate-widget *string*,
|
||||
--size-err, --timeout *secs*,--trace *filename*, --visit-items,
|
||||
--week-start *day*, --keep-tite, --keep-window, --last-key, --no-kill,
|
||||
--column-separator *string*, --input-fd *fd*, --tab-correct, --tab-len *n*
|
||||
|
||||
|
||||
**Widgets:**
|
||||
|
||||
To evaluate / Not planned in the short term:
|
||||
|
||||
tailbox (textbox/fseek), tailboxbg, dselect, fselect, inputmenu, editbox,
|
||||
calendar (use datebox), prgbox, programbox, progressbox.
|
||||
|
590
bsddialog.1
590
bsddialog.1
@ -1,5 +1,5 @@
|
||||
.\"
|
||||
.\" Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
.\" Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
@ -22,45 +22,569 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd December 11, 2021
|
||||
.Dd January 26, 2022
|
||||
.Dt BSDDIALOG 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm bsddialog
|
||||
.Nd terminal dialogs and widgets
|
||||
.Nd TUI dialogs
|
||||
.Sh SYNOPSIS
|
||||
.Nm bsddialog
|
||||
.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
|
||||
.Nm
|
||||
.Fl Fl help
|
||||
.Nm
|
||||
.Fl Fl version
|
||||
.Nm
|
||||
.Op Fl Fl common-opts
|
||||
.Fl Fl dialog
|
||||
.Ar text
|
||||
.Ar rows
|
||||
.Ar cols
|
||||
.Op Ar dialog-opts
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.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.
|
||||
.Nm bsddialog
|
||||
utility builds Text User Interface dialogs and widgets: to display messages,
|
||||
to get input and to inform about a computation status.
|
||||
.Pp
|
||||
The options
|
||||
.Fl Fl help
|
||||
and
|
||||
.Fl Fl version
|
||||
print the list of options and the version, respectively, then exit.
|
||||
.Pp
|
||||
The following options are available for each dialog.
|
||||
.Ar text
|
||||
is a message printed inside the dialog, except for
|
||||
.Fl Fl textbox
|
||||
described later.
|
||||
.Ar rows
|
||||
and
|
||||
.Ar cols
|
||||
are the height and width, 0 for autosize and -1 for fullscreen.
|
||||
The possible input got from the user interface is printed to standard error.
|
||||
.Ss Common options
|
||||
The following options can change the default behavior of the utility and are
|
||||
common to some dialog.
|
||||
.Bl -tag -width Ds
|
||||
.It Fl Fl ascii-lines
|
||||
Ascii characters to draw lines.
|
||||
.It Fl Fl backtitle Ar backtitle
|
||||
Title on the top side of the screen.
|
||||
.It Fl Fl begin-x Ar x
|
||||
Dialog horizontal position, 0 is the left screen side, -1 center.
|
||||
.It Fl Fl begin-y Ar y
|
||||
Dialog vertical position, 0 is the top screen side, -1 center.
|
||||
.It Fl Fl cancel-label Ar label
|
||||
Label for the
|
||||
.Dq Cancel
|
||||
button.
|
||||
.It Fl Fl clear
|
||||
Hide the dialog at exit.
|
||||
.It Fl Fl colors
|
||||
Enable highlights for text, the following sequences are considered escapes:
|
||||
.Bl -column -compact
|
||||
.It Dq \eZ0
|
||||
black.
|
||||
.It Dq \eZ1
|
||||
red.
|
||||
.It Dq \eZ2
|
||||
green.
|
||||
.It Dq \eZ3
|
||||
yellow.
|
||||
.It Dq \eZ4
|
||||
blue.
|
||||
.It Dq \eZ5
|
||||
magenta.
|
||||
.It Dq \eZ6
|
||||
cyan.
|
||||
.It Dq \eZ7
|
||||
white.
|
||||
.It Dq \eZr
|
||||
reverse foreground and background colors.
|
||||
.It Dq \eZR
|
||||
disable reverse.
|
||||
.It Dq \eZb
|
||||
bold.
|
||||
.It Dq \eZB
|
||||
disable bold.
|
||||
.It Dq \eZu
|
||||
underline.
|
||||
.It Dq \eZU
|
||||
disable underline.
|
||||
.It Dq \eZn
|
||||
restore to normal text.
|
||||
.El
|
||||
.It Fl Fl cr-wrap
|
||||
Replace new line with a space in
|
||||
.Ar text .
|
||||
.It Fl Fl date-format Ar format
|
||||
String accepted by
|
||||
.Xr strftime 3
|
||||
to customize the output of
|
||||
.Fl Fl datebox .
|
||||
.It Fl Fl default-button Ar label
|
||||
Focus on the button with
|
||||
.Ar label
|
||||
on startup.
|
||||
.It Fl Fl default-item Ar name
|
||||
Focus on the item with
|
||||
.Ar name ,
|
||||
for Checklist, Menu, Radiolist and Treeview.
|
||||
.It Fl Fl default-no
|
||||
Focus on
|
||||
.Dq Cancel
|
||||
or
|
||||
.Dq \&No
|
||||
button on startup.
|
||||
.It Fl Fl defaultno
|
||||
Equivalent to
|
||||
.Fl Fl default-no .
|
||||
.It Fl Fl disable-esc
|
||||
Disable ESC key to quit.
|
||||
.It Fl Fl esc-cancelvalue
|
||||
Exits with the
|
||||
.Dq Cancel
|
||||
button value if the ESC key is pressed.
|
||||
.It Fl Fl exit-label Ar label
|
||||
Equivalent to
|
||||
.Fl Fl ok-label .
|
||||
.It Fl Fl extra-button
|
||||
Add a button with
|
||||
.Dq Extra
|
||||
label.
|
||||
.It Fl Fl extra-label Ar label
|
||||
Set
|
||||
.Ar label
|
||||
for the
|
||||
.Dq Extra
|
||||
button.
|
||||
.It Fl Fl generic-button1 Ar label
|
||||
Add a button with
|
||||
.Ar label .
|
||||
.It Fl Fl generic-button2 Ar label
|
||||
Add a button with
|
||||
.Ar label .
|
||||
.It Fl Fl help-button
|
||||
Add a button with
|
||||
.Dq Help
|
||||
label.
|
||||
.It Fl Fl help-label Ar label
|
||||
Set
|
||||
.Ar label
|
||||
for
|
||||
.Dq Help
|
||||
button.
|
||||
.It Fl Fl help-status
|
||||
Print also the selected items if the
|
||||
.Dq Help
|
||||
button is pressed.
|
||||
.It Fl Fl help-tags
|
||||
Print the name of the focused item if the Help button is pressed also
|
||||
with
|
||||
.Fl Fl item-help .
|
||||
.It Fl Fl hfile Ar filename
|
||||
Open
|
||||
.Ar filename
|
||||
in a Textbox if F1 key is pressed,
|
||||
.It Fl Fl hline Ar string
|
||||
Dialog subtitle.
|
||||
.It Fl Fl hmsg Ar string
|
||||
Open a Msgbox with
|
||||
.Ar string
|
||||
if the F1 key is pressed.
|
||||
.It Fl Fl ignore
|
||||
Do not exit with unknown options.
|
||||
.It Fl Fl insecure
|
||||
Print
|
||||
.Sq *
|
||||
to hide passwords while typing, default space
|
||||
.Sq " " .
|
||||
.It Fl Fl item-depth
|
||||
Specify a margin for items, available for Checklist, Menu and Radiolist.
|
||||
.It Fl Fl item-help
|
||||
Set a help string for each element of a Checklist, Form, Menu, Mixedform,
|
||||
Passwordform, Radiolist and Treeview to display at the bottom screen side.
|
||||
.It Fl Fl item-prefix
|
||||
Set a string to prefix each item of a Checklist, Menu, Radiolist or Treeview.
|
||||
.It Fl Fl max-input Ar size
|
||||
Maximum length of the input for
|
||||
.Fl Fl input-box
|
||||
ans
|
||||
.Fl Fl passwordbox ,
|
||||
default 2048.
|
||||
.It Fl Fl no-cancel
|
||||
Do not show
|
||||
.Dq Cancel
|
||||
button.
|
||||
.It Fl Fl no-collapse
|
||||
Do not replace a TAB character with a space in
|
||||
.Ar text .
|
||||
.It Fl Fl no-items
|
||||
Do not display items desciption, for Checklist, Menu, Radiolist or Treeview.
|
||||
.It Fl Fl no-label Ar label
|
||||
Equivalent to
|
||||
.Fl Fl cancel-label .
|
||||
.It Fl Fl no-lines
|
||||
Do not draw borders and lines.
|
||||
.It Fl Fl no-nl-expand
|
||||
do not consider the sequence
|
||||
.Dq \en
|
||||
like new line.
|
||||
.It Fl Fl no-ok
|
||||
Do not draw
|
||||
.Dq OK
|
||||
button.
|
||||
.It Fl Fl no-shadow
|
||||
No not draw the shadow of the dialog.
|
||||
.It Fl Fl no-tags
|
||||
Do not display items name, for Checklist, Menu and Radiolist.
|
||||
.It Fl Fl nocancel
|
||||
Equivalent to
|
||||
.Fl Fl no-cancel .
|
||||
.It Fl Fl nook
|
||||
Equivalent to
|
||||
.Fl Fl no-ok .
|
||||
.It Fl Fl ok-label Ar label
|
||||
Set
|
||||
.Ar label
|
||||
for
|
||||
.Dq OK
|
||||
button.
|
||||
.It Fl Fl output-fd Ar fd
|
||||
Print input from user interface to the specified file descriptor.
|
||||
.It Fl Fl output-separator Ar sep
|
||||
Set a sepator for the items in output, default whitespace.
|
||||
.It Fl Fl print-maxsize
|
||||
Screen size.
|
||||
.It Fl Fl print-size
|
||||
Print Dialog height and widget at exit.
|
||||
.It Fl Fl print-version
|
||||
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.
|
||||
.It Fl Fl separator Ar sep
|
||||
Equivalent to
|
||||
.Fl Fl output-separator .
|
||||
.It Fl Fl shadow
|
||||
Show a pseudo shadow for the dialog, enabled by default.
|
||||
.It Fl Fl single-quoted
|
||||
Use single quote for items in output.
|
||||
.It Fl Fl sleep Ar secs
|
||||
Wait
|
||||
.Ar secs
|
||||
seconds to close the dialog.
|
||||
.It Fl Fl stderr
|
||||
Print input from user interface to standand error, default.
|
||||
.It Fl Fl stdout
|
||||
Print input from user interface to standard output.
|
||||
.It Fl Fl tab-len Ar spaces
|
||||
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.
|
||||
.It Fl Fl time-format Ar format
|
||||
String accepted by
|
||||
.Xr strftime 3
|
||||
to customize the output of
|
||||
.Fl Fl timebox .
|
||||
.It Fl Fl title Ar title
|
||||
Dialog title.
|
||||
.It Fl Fl trim
|
||||
remove consecutive spaces in
|
||||
.Ar text .
|
||||
.It Fl Fl yes-label Ar label
|
||||
Equivalent to
|
||||
.Fl Fl ok-label .
|
||||
.El
|
||||
.Ss Dialogs
|
||||
The following dialogs are available:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl Fl checklist Ar text Ar rows Ar cols Ar menurows Oo Ar name Ar desc \
|
||||
Ar status Oc ...
|
||||
Checklist to select some item from a list via the SPACE key.
|
||||
An item has a
|
||||
.Ar name ,
|
||||
.Ar desc
|
||||
and a default
|
||||
.Ar status
|
||||
specified by
|
||||
.Dq on
|
||||
or
|
||||
.Dq off .
|
||||
The names of the selected items are printed to standard error.
|
||||
.Ar menurows
|
||||
is the graphical height of the list, 0 for autosize.
|
||||
.It Fl Fl datebox Ar text Ar rows Ar cols Op Ar year Ar month Ar day
|
||||
Dialog to select a date.
|
||||
.It Fl Fl form Ar text Ar rows Ar cols Ar formrows Oo Ar label Ar ylabel \
|
||||
Ar xlabel Ar init Ar yfield Ar xfield Ar fieldlen Ar maxvaluelen Oc ...
|
||||
Dialog to get a list of strings via forms.
|
||||
A form has a
|
||||
.Ar label
|
||||
at the position
|
||||
.Ar ylabel
|
||||
and
|
||||
.Ar xlabel ,
|
||||
a field to get the input at the position
|
||||
.Ar yfield
|
||||
and
|
||||
.Ar xfield
|
||||
with graphical length
|
||||
.Ar fieldlen ,
|
||||
.Ar maxvaluelen
|
||||
is the maximum input length.
|
||||
The field can be customized, if
|
||||
.Ar fieldlen
|
||||
is 0 its length is the absolute value of
|
||||
.Ar maxvaluelen ,
|
||||
if
|
||||
.Ar maxvaluelen
|
||||
is negative the field is read only,
|
||||
.Ar init
|
||||
is a default value.
|
||||
.Ar formrows
|
||||
is the graphical height of the list, has to be at least the number of forms.
|
||||
.It Fl Fl gauge Ar text Ar rows Ar cols Op Ar percentage
|
||||
Dialog with a bar to shows
|
||||
.Ar percentage ,
|
||||
then it waits to read
|
||||
.Dq XXX
|
||||
from the standard input, then the first string replaces percentage and the
|
||||
following strings replace
|
||||
.Ar text
|
||||
until the next
|
||||
.Dq XXX ,
|
||||
the loop ends reading
|
||||
.Dv EOF .
|
||||
.It Fl Fl infobox Ar text Ar rows Ar cols
|
||||
Dialog without buttons to display a message and to exit immediately.
|
||||
.It Fl Fl inputbox Ar text Ar rows Ar cols Op Ar init
|
||||
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.
|
||||
An item has a
|
||||
.Ar name
|
||||
and a
|
||||
.Ar desc .
|
||||
The name of the selected item is printed to standard error.
|
||||
.Ar menurows
|
||||
is the graphical height of the list, 0 for autosize.
|
||||
.It Fl Fl mixedform Ar text Ar rows Ar cols Ar formrows Oo Ar label Ar ylabel \
|
||||
Ar xlabel Ar init Ar yfield Ar xfield Ar fieldlen Ar maxvaluelen Ar flag Oc ...
|
||||
Dialog to get a list of strings via forms.
|
||||
A form has a
|
||||
.Ar label
|
||||
at the position
|
||||
.Ar ylabel
|
||||
and
|
||||
.Ar xlabel ,
|
||||
a field to get the input with graphical length
|
||||
.Ar fieldlen
|
||||
at the position
|
||||
.Ar yfield
|
||||
and
|
||||
.Ar xfield ,
|
||||
.Ar maxvaluelen
|
||||
is the maximum input length,
|
||||
.Ar init
|
||||
is a default value,
|
||||
.Ar flag
|
||||
can be 0 for normal field, 1 to hide the typed characters and 2 to set the
|
||||
field read only.
|
||||
.Ar formrows
|
||||
is the graphical height of the list, has to be at least the number of forms.
|
||||
.It Fl Fl mixedgauge Ar text Ar rows Ar cols Ar mainperc Oo Ar minilabel \
|
||||
Ar miniperc Oc ...
|
||||
Dialog to show a main bar to represent
|
||||
.Ar mainperc
|
||||
from 0 to 100 and some mini bar with a
|
||||
.Ar minilabel
|
||||
string and a
|
||||
.Ar miniperc
|
||||
with value from 0 and 100 or negative to print a descriptive string: -1
|
||||
.Dq Succeeded ,
|
||||
-2
|
||||
.Dq Failed ,
|
||||
-3
|
||||
.Dq Passed ,
|
||||
-4
|
||||
.Dq Completed ,
|
||||
-5
|
||||
.Dq Checked ,
|
||||
-6
|
||||
.Dq Done ,
|
||||
-7
|
||||
.Dq Skipped ,
|
||||
-8
|
||||
.Dq \&In Progress ,
|
||||
-9
|
||||
a blank line,
|
||||
-10
|
||||
.Dq N/A ,
|
||||
-11
|
||||
.Dq Pending .
|
||||
.It Fl Fl msgbox Ar text Ar rows Ar cols
|
||||
Dialog to diplay a message without the
|
||||
.Dq Cancel
|
||||
button.
|
||||
.It Fl Fl passwordbox Ar text Ar rows Ar cols Op Ar init
|
||||
Dialog to get a password,
|
||||
.Ar init
|
||||
is the default value.
|
||||
.It Fl Fl passwordform Ar text Ar rows Ar cols Ar formrows Oo Ar label \
|
||||
Ar ylabel Ar xlabel Ar init Ar yfield Ar xfield Ar fieldlen Ar valuelen Oc ...
|
||||
Dialog to get a list of passwords, equivalent to
|
||||
.Fl Fl form
|
||||
except typed characters are hidden.
|
||||
.It Fl Fl pause Ar text Ar rows Ar cols Ar seconds
|
||||
Dialog runs until the timeout in
|
||||
.Ar seconds
|
||||
expires or a button is pressed.
|
||||
.It Fl Fl radiolist Ar text Ar rows Ar cols Ar menurows Oo Ar name Ar desc \
|
||||
Ar status Oc ...
|
||||
Radiolist to select at most an item from a list via the SPACE key.
|
||||
An item has a
|
||||
.Ar name ,
|
||||
.Ar desc
|
||||
and a default
|
||||
.Ar status
|
||||
specified by
|
||||
.Dq on
|
||||
or
|
||||
.Dq off .
|
||||
The name of the selected item is printed to standard error.
|
||||
.Ar menurows
|
||||
is the graphical height of the list, 0 for autosize.
|
||||
.It Fl Fl rangebox Ar text Ar rows Ar cols Ar min Ar max Op Ar init
|
||||
Dialog to select a value between
|
||||
.Ar min
|
||||
and
|
||||
.Ar max ,
|
||||
.Ar init
|
||||
is the default value, the keys UP, DOWN, HOME, END, PAGEUP and PAGEDOWN can
|
||||
change it.
|
||||
.It Fl Fl textbox Ar file Ar rows Ar cols
|
||||
Opens and prints
|
||||
.Ar file
|
||||
the UP, DOWN, HOME, END, PAGEUP and PAGEDOWN keys are availble to navigate;
|
||||
.Dq OK
|
||||
button is renamed
|
||||
.Dq EXIT .
|
||||
.It Fl Fl timebox Ar text Ar rows Ar cols Op Ar hour Ar min Ar sec
|
||||
Dialog to select a time.
|
||||
.It Fl Fl treeview Ar text Ar rows Ar cols Ar menurows Oo Ar depth Ar name \
|
||||
Ar desc Ar status Oc ...
|
||||
Equivalent to Radiolist with
|
||||
.Fl Fl item-depth
|
||||
and
|
||||
.Fl Fl no-name .
|
||||
.It Fl Fl yesno Ar text Ar rows Ar cols
|
||||
.Dq Yes-No Question ,
|
||||
.Dq OK
|
||||
and
|
||||
.Dq Cancel
|
||||
buttons are renamed
|
||||
.Dq Yes
|
||||
and
|
||||
.Dq \&No .
|
||||
.El
|
||||
.Sh EXIT STATUS
|
||||
The
|
||||
.Nm
|
||||
utility exits 255 on unsuccessful, otherwise depending on the button or key
|
||||
pressed the following values can be returned:
|
||||
.Bl -column -compact
|
||||
.It 0
|
||||
.Dq OK ,
|
||||
.Dq Yes
|
||||
or
|
||||
.Dq Exit
|
||||
button.
|
||||
.It 1
|
||||
.Dq Cancel
|
||||
or
|
||||
.Dq \&No
|
||||
button.
|
||||
.It 2
|
||||
.Dq Help
|
||||
button.
|
||||
.It 3
|
||||
.Dq Extra
|
||||
button.
|
||||
.It 4
|
||||
Timeout.
|
||||
.It 5
|
||||
ESC key.
|
||||
.It 6
|
||||
Generic 1 button.
|
||||
.It 7
|
||||
Generic 2 button.
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
Backtitle, title and message:
|
||||
.Dl bsddialog --backtitle MESSAGE --title Msgbox --msgbox Message 0 0
|
||||
.Pp
|
||||
Yes-No Question and theme:
|
||||
.Dl bsddialog --theme blackwhite --yesno Question 10 30
|
||||
.Pp
|
||||
Checklist:
|
||||
.Dl bsddialog --checklist Checklist 0 0 3 N1 \&D1 off N2 D2 on N3 D3 off
|
||||
.Pp
|
||||
Mixedgauge:
|
||||
.Dl bsddialog --sleep 3 --mixedgauge Example 10 30 60 L1 "\(dq" -1" L2 30
|
||||
.Pp
|
||||
Form:
|
||||
.Dl bsddialog --form Form 0 0 2 L1: 1 1 X 1 5 20 25 L2: 2 1 X 2 5 20 25
|
||||
.Pp
|
||||
Gauge script:
|
||||
.Bd -literal -offset indent -compact
|
||||
i=1
|
||||
for c in A B C D E F G H
|
||||
do
|
||||
sleep 1
|
||||
echo XXX
|
||||
echo "$(expr $(expr $i "*" 100) "/" 8)"
|
||||
echo "[$i/8] Char: $c"
|
||||
echo XXX
|
||||
if [ $i -eq 8 ]
|
||||
then
|
||||
sleep 1
|
||||
echo EOF
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done | bsddialog --title Gauge --gauge "Starting..." 10 70
|
||||
.Ed
|
||||
.Pp
|
||||
Mixedgauge script:
|
||||
.Bd -literal -offset indent -compact
|
||||
perc=0
|
||||
while [ $perc -le 100 ]
|
||||
do
|
||||
bsddialog --sleep 1 --title Mixedgauge \e
|
||||
--mixedgauge "\enExample...\en" 0 0 $perc \e
|
||||
"Hidden" " -9" \e
|
||||
"Label 1" " -4" \e
|
||||
"Label 2" " -4" \e
|
||||
"Label 3" $perc
|
||||
|
||||
perc=`expr $perc + 20`
|
||||
done
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr bsddialog 3
|
||||
.\" .Sh HISTORY
|
||||
.\" .Sh AUTHORS
|
||||
.Sh CAVEATS
|
||||
autosize
|
||||
compatibility text
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm bsddialog
|
||||
utility first appeared in
|
||||
.Fx 14.0 .
|
||||
.Sh AUTHORS
|
||||
.Nm bsddialog
|
||||
was written by
|
||||
.An Alfonso Sabato Siciliano Aq Mt alf.siciliano@gmail.com .
|
||||
.Sh BUGS
|
||||
buildlist
|
||||
forms
|
||||
The forms do not resize the dialog after a terminal change and does not provides
|
||||
scrolling for items.
|
1568
bsddialog.c
1568
bsddialog.c
File diff suppressed because it is too large
Load Diff
@ -1,44 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*
|
||||
* Written in 2021 by Alfonso Sabato Siciliano.
|
||||
* To the extent possible under law, the author has dedicated all copyright
|
||||
* and related and neighboring rights to this software to the public domain
|
||||
* worldwide. This software is distributed without any warranty, see:
|
||||
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <bsddialog.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, output;
|
||||
struct bsddialog_conf conf;
|
||||
struct bsddialog_menuitem items[5] = {
|
||||
{"", false, 0, "Name 1", "Desc 1", "Bottom Desc 1"},
|
||||
{"", true, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
|
||||
{"", false, 0, "Name 3", "Desc 3", "Bottom Desc 3"},
|
||||
{"", true, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
|
||||
{"", false, 0, "Name 5", "Desc 5", "Bottom Desc 5"}
|
||||
};
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "radiolist";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_buildlist(&conf, "Example", 15, 30, 5, 5, items, NULL);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
printf("Buildlist:\n");
|
||||
for (i=0; i<5; i++)
|
||||
printf(" [%c] %s\n", items[i].on ? 'X' : ' ', items[i].name);
|
||||
|
||||
|
||||
return output;
|
||||
}
|
@ -18,27 +18,38 @@ int main()
|
||||
int i, output;
|
||||
struct bsddialog_conf conf;
|
||||
struct bsddialog_menuitem items[5] = {
|
||||
{"", true, 0, "Name 1", "Desc 1", "Bottom Desc 1"},
|
||||
{"", false, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
|
||||
{"", true, 0, "Name 3", "Desc 3", "Bottom Desc 3"},
|
||||
{"", false, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
|
||||
{"", true, 0, "Name 5", "Desc 5", "Bottom Desc 5"}
|
||||
{"i", true, 0, "Name 1", "Desc 1", "Bottom Desc 1"},
|
||||
{"ii", false, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
|
||||
{"iii", true, 0, "Name 3", "Desc 3", "Bottom Desc 3"},
|
||||
{"iv", false, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
|
||||
{"v", true, 0, "Name 5", "Desc 5", "Bottom Desc 5"}
|
||||
};
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "checklist";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_checklist(&conf, "Example", 15, 30, 5, 5, items, NULL);
|
||||
output = bsddialog_checklist(&conf, "Example", 15, 30, 5, 5, items,
|
||||
NULL);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
if (output == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (output == BSDDIALOG_CANCEL) {
|
||||
printf("Cancel\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
printf("Checklist:\n");
|
||||
for (i=0; i<5; i++)
|
||||
for (i = 0; i < 5; i++)
|
||||
printf(" [%c] %s\n", items[i].on ? 'X' : ' ', items[i].name);
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
return (output);
|
||||
}
|
@ -1,10 +1,19 @@
|
||||
#!/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/>.
|
||||
|
||||
libpath=../lib
|
||||
examples="buildlist menu treeview checklist radiolist mixedlist theme \
|
||||
infobox yesno msgbox datebox form timebox sade rangebox pause"
|
||||
examples="menu checklist radiolist mixedlist theme infobox yesno msgbox \
|
||||
datebox form timebox rangebox pause"
|
||||
|
||||
for e in $examples
|
||||
do
|
||||
cc -g -Wall -I$libpath ${e}.c -o $e -L$libpath -lbsddialog -Wl,-rpath=$libpath
|
||||
cc -g -Wall -Wextra -I$libpath ${e}.c -o $e -L$libpath -lbsddialog \
|
||||
-Wl,-rpath=$libpath
|
||||
done
|
||||
|
@ -28,24 +28,22 @@ int main()
|
||||
mm = localtm->tm_mon + 1;
|
||||
dd = localtm->tm_mday;
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "datebox";
|
||||
conf.bottomtitle = "Press TAB and arrows";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_datebox(&conf, "Example", 10, 50, &yy, &mm, &dd);
|
||||
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
switch (output) {
|
||||
case BSDDIALOG_OK:
|
||||
printf("Date: %u/%u/%u", yy, mm, dd);
|
||||
break;
|
||||
case BSDDIALOG_ESC:
|
||||
printf("ESC\n");
|
||||
break;
|
||||
case BSDDIALOG_CANCEL:
|
||||
printf("Cancel");
|
||||
break;
|
||||
@ -55,5 +53,5 @@ int main()
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return output;
|
||||
}
|
||||
return (output);
|
||||
}
|
@ -23,29 +23,37 @@ 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"}
|
||||
{"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"}
|
||||
};
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "form";
|
||||
conf.form.securech = '*';
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_form(&conf, "Example", 10, 50, 3, 3, items);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
if (output == BSDDIALOG_ERROR)
|
||||
printf("Error: %s", bsddialog_geterror());
|
||||
|
||||
for (i=0; i<3; i++) {
|
||||
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 \"%s\"\n", items[i].label, items[i].value);
|
||||
free(items[i].value);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
return (output);
|
||||
}
|
@ -18,15 +18,22 @@ int main()
|
||||
int output;
|
||||
struct bsddialog_conf conf;
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "infobox";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_infobox(&conf, "Example", 7, 20);
|
||||
conf.sleep = 3;
|
||||
output = bsddialog_infobox(&conf, "Example\n(3 seconds)", 7, 20);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
return output;
|
||||
}
|
||||
if (output == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
return (output);
|
||||
}
|
@ -18,27 +18,37 @@ int main()
|
||||
int i, output;
|
||||
struct bsddialog_conf conf;
|
||||
struct bsddialog_menuitem items[5] = {
|
||||
{"", true, 0, "Name 1", "Desc 1", "Bottom Desc 1"},
|
||||
{"", false, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
|
||||
{"", true, 0, "Name 3", "Desc 3", "Bottom Desc 3"},
|
||||
{"", false, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
|
||||
{"", true, 0, "Name 5", "Desc 5", "Bottom Desc 5"}
|
||||
{"I", true, 0, "Name 1", "Desc 1", "Bottom Desc 1"},
|
||||
{"II", false, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
|
||||
{"III", true, 0, "Name 3", "Desc 3", "Bottom Desc 3"},
|
||||
{"IV", false, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
|
||||
{"V", true, 0, "Name 5", "Desc 5", "Bottom Desc 5"}
|
||||
};
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "menu";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_menu(&conf, "Example", 15, 30, 5, 5, items, NULL);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
if (output == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (output == BSDDIALOG_CANCEL) {
|
||||
printf("Cancel\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
printf("Menu:\n");
|
||||
for (i=0; i<5; i++)
|
||||
for (i = 0; i < 5; i++)
|
||||
printf(" [%c] %s\n", items[i].on ? 'X' : ' ', items[i].name);
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
return (output);
|
||||
}
|
@ -15,7 +15,8 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, j, output;
|
||||
int output;
|
||||
unsigned int i, j;
|
||||
struct bsddialog_conf conf;
|
||||
struct bsddialog_menuitem item;
|
||||
struct bsddialog_menuitem check[5] = {
|
||||
@ -41,30 +42,42 @@ int main()
|
||||
{ BSDDIALOG_RADIOLIST, 5, radio }
|
||||
};
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "mixedmenu";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
output = bsddialog_mixedlist(&conf, "dialog4ports", 20, 30, 11, 3, group,
|
||||
NULL,NULL);
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "mixedlist";
|
||||
output = bsddialog_mixedlist(&conf, "Example", 20, 30, 11, 3, group,
|
||||
NULL, NULL);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
if (output == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (output == BSDDIALOG_CANCEL) {
|
||||
printf("Cancel\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
printf("Mixedlist:\n");
|
||||
for (i=0; i<3; i++) {
|
||||
for (j=0; j<group[i].nitems; j++) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < group[i].nitems; j++) {
|
||||
item = group[i].items[j];
|
||||
if (group[i].type == BSDDIALOG_SEPARATOR)
|
||||
printf("----- %s -----\n", item.name);
|
||||
else if (group[i].type == BSDDIALOG_RADIOLIST)
|
||||
printf(" (%c) %s\n", item.on ? '*' : ' ', item.name);
|
||||
else /* BSDDIALOG_PORTCHECKLIST */
|
||||
printf(" [%c] %s\n", item.on ? 'X' : ' ', item.name);
|
||||
printf(" (%c) %s\n",
|
||||
item.on ? '*' : ' ', item.name);
|
||||
else /* BSDDIALOG_CHECKLIST */
|
||||
printf(" [%c] %s\n",
|
||||
item.on ? 'X' : ' ', item.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
return (output);
|
||||
}
|
@ -15,28 +15,28 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
int input;
|
||||
int output;
|
||||
struct bsddialog_conf conf;
|
||||
|
||||
/* Configuration */
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "msgbox";
|
||||
|
||||
/* Run BSDDialog */
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return -1;
|
||||
return (1);
|
||||
}
|
||||
input = bsddialog_msgbox(&conf, "Example", 7, 20);
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "msgbox";
|
||||
output = bsddialog_msgbox(&conf, "Example", 7, 20);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
/* User Input */
|
||||
printf("User input: ");
|
||||
switch (input) {
|
||||
case BSDDIALOG_ERROR: printf("Error %s\n", bsddialog_geterror()); break;
|
||||
case BSDDIALOG_OK: printf("OK\n"); break;
|
||||
case BSDDIALOG_ESC: printf("ESC\n"); break;
|
||||
switch (output) {
|
||||
case BSDDIALOG_ERROR:
|
||||
printf("Error %s\n", bsddialog_geterror());
|
||||
break;
|
||||
case BSDDIALOG_OK:
|
||||
printf("OK\n");
|
||||
break;
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
return (output);
|
||||
}
|
@ -18,12 +18,13 @@ int main()
|
||||
int output;
|
||||
struct bsddialog_conf conf;
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "pause";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_pause(&conf, "Example", 8, 50, 10);
|
||||
|
||||
bsddialog_end();
|
||||
@ -32,9 +33,6 @@ int main()
|
||||
case BSDDIALOG_OK:
|
||||
printf("OK\n");
|
||||
break;
|
||||
case BSDDIALOG_ESC:
|
||||
printf("ESC\n");
|
||||
break;
|
||||
case BSDDIALOG_CANCEL:
|
||||
printf("Cancel\n");
|
||||
break;
|
||||
@ -46,5 +44,5 @@ int main()
|
||||
break;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
return (output);
|
||||
}
|
@ -18,27 +18,37 @@ int main()
|
||||
int i, output;
|
||||
struct bsddialog_conf conf;
|
||||
struct bsddialog_menuitem items[5] = {
|
||||
{"", true, 0, "Name 1", "Desc 1", "Bottom Desc 1"},
|
||||
{"", false, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
|
||||
{"", true, 0, "Name 3", "Desc 3", "Bottom Desc 3"},
|
||||
{"", false, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
|
||||
{"", true, 0, "Name 5", "Desc 5", "Bottom Desc 5"}
|
||||
{"I", true, 0, "Name 1", "Desc 1", "Bottom Desc 1"},
|
||||
{"II", false, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
|
||||
{"III", true, 0, "Name 3", "Desc 3", "Bottom Desc 3"},
|
||||
{"IV", false, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
|
||||
{"V", true, 0, "Name 5", "Desc 5", "Bottom Desc 5"}
|
||||
};
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "radiolist";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_radiolist(&conf, "Example", 15, 30, 5, 5, items, NULL);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
if (output == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (output == BSDDIALOG_CANCEL) {
|
||||
printf("Cancel\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
printf("Radiolist:\n");
|
||||
for (i=0; i<5; i++)
|
||||
for (i = 0; i < 5; i++)
|
||||
printf(" (%c) %s\n", items[i].on ? '*' : ' ', items[i].name);
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
return (output);
|
||||
}
|
@ -18,18 +18,24 @@ int main()
|
||||
int value, output;
|
||||
struct bsddialog_conf conf;
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "rangebox";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
value = 5;
|
||||
output = bsddialog_rangebox(&conf, "Example", 8, 50, 0, 10, &value);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
printf("Value: %d", value);
|
||||
if (output == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
printf("Value: %d\n", value);
|
||||
|
||||
return (output);
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*
|
||||
* Written in 2021 by Alfonso Sabato Siciliano.
|
||||
* To the extent possible under law, the author has dedicated all copyright
|
||||
* and related and neighboring rights to this software to the public domain
|
||||
* worldwide. This software is distributed without any warranty, see:
|
||||
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
|
||||
#include <bsddialog.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Figure 15 - https://docs.freebsd.org/en/books/handbook/bsdinstall/ */
|
||||
int main()
|
||||
{
|
||||
int i, output;
|
||||
struct bsddialog_conf conf;
|
||||
char *text = "Please review the disk setup. When complete, press the "
|
||||
"Finish button";
|
||||
struct bsddialog_menuitem items[5] = {
|
||||
{"", false, 0, "ada0", "16 GB GPT", ""},
|
||||
{"", false, 1, "ada0p1", "512 KB freebsd-boot", ""},
|
||||
{"", false, 1, "ada0p2", "15 GB freebsd-ufs", ""},
|
||||
{"", false, 1, "ada0p3", "819 MB freebsd-swap none", ""},
|
||||
{"", false, 0, "ada1", "16 GB", ""}
|
||||
};
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
|
||||
conf.title = "Partition Editor";
|
||||
conf.menu.shortcut_buttons = true;
|
||||
conf.menu.align_left = true;
|
||||
conf.button.ok_label = "Create";
|
||||
conf.button.with_extra = true;
|
||||
conf.button.extra_label = "Delete";
|
||||
conf.button.cancel_label = "Cancel";
|
||||
conf.button.with_help = true;
|
||||
conf.button.help_label = "Revert";
|
||||
conf.button.generic1_label = "Auto";
|
||||
conf.button.generic2_label = "Finish";
|
||||
conf.button.default_label = "Finish";
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR)
|
||||
return (1);
|
||||
output = bsddialog_menu(&conf, text, 20, 0, 10, 5, items, NULL);
|
||||
bsddialog_end();
|
||||
|
||||
printf("Menu:\n");
|
||||
for (i=0; i<5; i++)
|
||||
printf(" [%c] %s\n", items[i].on ? 'X' : ' ', items[i].name);
|
||||
|
||||
|
||||
return (output);
|
||||
}
|
@ -16,47 +16,60 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
int output;
|
||||
int output, focusitem;
|
||||
struct bsddialog_conf conf;
|
||||
enum bsddialog_default_theme theme;
|
||||
struct bsddialog_menuitem items[4] = {
|
||||
{"", false, 0, "Dialog", "Current dialog theme", "BSDDIALOG_THEME_DIALOG" },
|
||||
{"", false, 0, "BSDDialog", "Future default theme", "BSDDIALOG_THEME_DEFAULT"},
|
||||
{"", false, 0, "BlackWhite","Black and White theme", "BSDDIALOG_THEME_BLACKWHITE"},
|
||||
{"", false, 0, "Quit", "Exit", "Quit or Cancel to exit" }
|
||||
struct bsddialog_menuitem items[5] = {
|
||||
{"", false, 0, "Default", "dialog-like",
|
||||
"BSDDIALOG_THEME_DEFAULT" },
|
||||
{"", false, 0, "Dialog", "dialog clone",
|
||||
"BSDDIALOG_THEME_DIALOG" },
|
||||
{"", false, 0, "BSDDialog", "new theme",
|
||||
"BSDDIALOG_THEME_BSDDIALOG" },
|
||||
{"", false, 0, "BlackWhite","black and white",
|
||||
"BSDDIALOG_THEME_BLACKWHITE" },
|
||||
{"", false, 0, "Quit", "Exit", "Quit or Cancel to exit" }
|
||||
};
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
|
||||
bsddialog_backtitle(&conf, "Theme Example");
|
||||
|
||||
conf.title = " Theme ";
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
focusitem = -1;
|
||||
while (true) {
|
||||
bsddialog_backtitle(&conf, "Theme Example");
|
||||
output = bsddialog_menu(&conf, "Choose theme", 15, 40, 5, 5,
|
||||
items, &focusitem);
|
||||
|
||||
output = bsddialog_menu(&conf, "Choose theme", 15, 40, 4, 4, items, NULL);
|
||||
|
||||
if (output != BSDDIALOG_OK || items[3].on)
|
||||
if (output != BSDDIALOG_OK || items[4].on)
|
||||
break;
|
||||
|
||||
if (items[0].on) {
|
||||
theme = BSDDIALOG_THEME_DIALOG;
|
||||
conf.menu.default_item = items[0].name;
|
||||
theme = BSDDIALOG_THEME_DEFAULT;
|
||||
focusitem = 0;
|
||||
}
|
||||
else if (items[1].on) {
|
||||
theme = BSDDIALOG_THEME_BSDDIALOG;
|
||||
conf.menu.default_item = items[1].name;
|
||||
theme = BSDDIALOG_THEME_DIALOG;
|
||||
focusitem = 1;
|
||||
}
|
||||
else if (items[2].on) {
|
||||
theme = BSDDIALOG_THEME_BSDDIALOG;
|
||||
focusitem = 2;
|
||||
}
|
||||
else if (items[3].on) {
|
||||
theme = BSDDIALOG_THEME_BLACKWHITE;
|
||||
conf.menu.default_item = items[2].name;
|
||||
focusitem = 3;
|
||||
}
|
||||
|
||||
bsddialog_set_default_theme(theme);
|
||||
}
|
||||
|
||||
bsddialog_end();
|
||||
bsddialog_end();
|
||||
|
||||
return output;
|
||||
}
|
||||
return (output);
|
||||
}
|
@ -28,24 +28,22 @@ int main()
|
||||
mm = localtm->tm_min;
|
||||
ss = localtm->tm_sec;
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "timebox";
|
||||
conf.bottomtitle = "Press TAB and arrows";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_timebox(&conf, "Example", 10, 50, &hh, &mm, &ss);
|
||||
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
switch (output) {
|
||||
case BSDDIALOG_OK:
|
||||
printf("Time: [%u:%u:%u]\n", hh, mm, ss);
|
||||
break;
|
||||
case BSDDIALOG_ESC:
|
||||
printf("ESC\n");
|
||||
break;
|
||||
case BSDDIALOG_CANCEL:
|
||||
printf("Cancel\n");
|
||||
break;
|
||||
@ -54,5 +52,5 @@ int main()
|
||||
break;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
return (output);
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*
|
||||
* Written in 2021 by Alfonso Sabato Siciliano.
|
||||
* To the extent possible under law, the author has dedicated all copyright
|
||||
* and related and neighboring rights to this software to the public domain
|
||||
* worldwide. This software is distributed without any warranty, see:
|
||||
* <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <bsddialog.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, output;
|
||||
struct bsddialog_conf conf;
|
||||
struct bsddialog_menuitem items[5] = {
|
||||
{"", false, 0, "Name 1", "Desc 1", "Bottom Desc 1"},
|
||||
{"", false, 1, "Name 2", "Desc 2", "Bottom Desc 2"},
|
||||
{"", false, 1, "Name 3", "Desc 3", "Bottom Desc 3"},
|
||||
{"", false, 2, "Name 4", "Desc 4", "Bottom Desc 4"},
|
||||
{"", false, 1, "Name 5", "Desc 5", "Bottom Desc 5"}
|
||||
};
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "radiolist";
|
||||
conf.menu.no_name = true;
|
||||
conf.menu.align_left = true;
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_radiolist(&conf, "Example", 15, 30, 5, 5, items, NULL);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
printf("Treeview:\n");
|
||||
for (i=0; i<5; i++)
|
||||
printf(" (%c) %s\n", items[i].on ? '*' : ' ', items[i].name);
|
||||
|
||||
|
||||
return output;
|
||||
}
|
@ -18,15 +18,28 @@ int main()
|
||||
int output;
|
||||
struct bsddialog_conf conf;
|
||||
|
||||
if (bsddialog_init() == BSDDIALOG_ERROR) {
|
||||
printf("Error: %s\n", bsddialog_geterror());
|
||||
return (1);
|
||||
}
|
||||
|
||||
bsddialog_initconf(&conf);
|
||||
conf.title = "yesno";
|
||||
|
||||
if (bsddialog_init() < 0)
|
||||
return -1;
|
||||
|
||||
output = bsddialog_yesno(&conf, "Example", 7, 25);
|
||||
|
||||
bsddialog_end();
|
||||
|
||||
return output;
|
||||
}
|
||||
switch (output) {
|
||||
case BSDDIALOG_ERROR:
|
||||
printf("Error %s\n", bsddialog_geterror());
|
||||
break;
|
||||
case BSDDIALOG_YES:
|
||||
printf("YES\n");
|
||||
break;
|
||||
case BSDDIALOG_NO:
|
||||
printf("NO\n");
|
||||
break;
|
||||
}
|
||||
|
||||
return (output);
|
||||
}
|
@ -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 buildlist --buildlist "Hello World!" 15 40 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
|
@ -6,9 +6,9 @@
|
||||
# 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 --title checklist --checklist "Hello World!" 15 30 5 \
|
||||
./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 \
|
||||
|
@ -6,14 +6,14 @@
|
||||
# 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 --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 \
|
||||
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
|
||||
|
||||
|
||||
|
@ -6,23 +6,23 @@
|
||||
# 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/>.
|
||||
|
||||
input="A B C D E F G"
|
||||
total=`echo $input | awk '{print split($0, a)}'`
|
||||
curr=1
|
||||
for i in $input
|
||||
characters="A B C D E F G"
|
||||
total=`echo $characters | awk '{print split($0, a)}'`
|
||||
i=1
|
||||
for c in $characters
|
||||
do
|
||||
sleep 1
|
||||
perc="$(expr $(expr $curr "*" 100 ) "/" $total )"
|
||||
echo XXX
|
||||
echo $perc
|
||||
echo "[$curr/$total] Input: $i"
|
||||
echo XXX
|
||||
if [ $curr -eq $total ]
|
||||
then
|
||||
echo EOF
|
||||
fi
|
||||
curr=`expr $curr + 1`
|
||||
done | ./bsddialog --title gauge --gauge "[0/$total] Starting..." 10 70 0
|
||||
echo XXX
|
||||
echo "$(expr $(expr $i "*" 100) "/" $total)"
|
||||
echo "[$i/$total] Char: $c"
|
||||
echo XXX
|
||||
if [ $i -eq $total ]
|
||||
then
|
||||
sleep 1
|
||||
echo EOF
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done | ./bsddialog --title " gauge " --gauge "[0/$total] Starting..." 10 70
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
# 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 seconds" 6 20
|
||||
./bsddialog --sleep 3 --title " infobox " --infobox "Hello World!\n3 secs" 6 20
|
||||
|
@ -6,7 +6,7 @@
|
||||
# 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 --title " inputbox " --inputbox "Hello World!" 12 40 init \
|
||||
./bsddialog --title " inputbox " --inputbox "Hello World!" 12 40 default \
|
||||
2>out.txt ; cat out.txt ; rm out.txt
|
||||
|
@ -6,12 +6,12 @@
|
||||
# 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 --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" \
|
||||
./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
|
||||
|
@ -6,10 +6,10 @@
|
||||
# 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 --insecure --title " mixedform " --mixedform "Hello World!" 12 40 5 \
|
||||
Label: 1 1 Entry 1 11 18 25 0 \
|
||||
Label: 2 1 Read-Only 2 11 18 25 2 \
|
||||
Password: 3 1 Value2 3 11 18 25 1 \
|
||||
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
|
||||
|
@ -6,29 +6,25 @@
|
||||
# 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/>.
|
||||
|
||||
|
||||
input="A B C D E F G H"
|
||||
total=`echo $input | awk '{print split($0, a)}'`
|
||||
curr=1
|
||||
for i in $input
|
||||
perc=0
|
||||
while [ $perc -le 100 ]
|
||||
do
|
||||
perc="$(expr $(expr $curr "*" 100 ) "/" $total )"
|
||||
curr=`expr $curr + 1`
|
||||
./bsddialog --sleep 1 --title " mixedgauge " --mixedgauge "Example" 25 50 $perc \
|
||||
"Hidden!" 8 \
|
||||
"Label 1" 0 \
|
||||
"Label 2" 1 \
|
||||
"Label 3" 2 \
|
||||
"Label 4" 3 \
|
||||
"Label 5" 4 \
|
||||
"Label 6" 5 \
|
||||
"Label 7" 6 \
|
||||
"Label 8" 7 \
|
||||
"Label 9" 9 \
|
||||
"Label 10" 10 \
|
||||
"Label X" " -$perc"
|
||||
#sleep 1
|
||||
done
|
||||
./bsddialog --sleep 1 --title " mixedgauge " \
|
||||
--mixedgauge "Example..." 20 45 $perc \
|
||||
"(Hidden)" " -9" \
|
||||
"Label 1" " -1" \
|
||||
"Label 2" " -2" \
|
||||
"Label 3" " -3" \
|
||||
"Label 4" " -4" \
|
||||
"Label 5" " -5" \
|
||||
"Label 6" " -6" \
|
||||
"Label 7" " -7" \
|
||||
"Label 8" " -8" \
|
||||
"Label 9" " -10" \
|
||||
"Label 10" " -11" \
|
||||
"Label X" $perc
|
||||
|
||||
perc=`expr $perc + 20`
|
||||
done
|
||||
|
@ -6,6 +6,6 @@
|
||||
# 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 --title msgbox --msgbox "Hello World!" 6 20
|
||||
./bsddialog --title " msgbox " --msgbox "Hello World!" 6 20
|
||||
|
@ -6,7 +6,7 @@
|
||||
# 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 --insecure --title " password " --passwordbox "Hello World!" 12 40 \
|
||||
2>out.txt ; cat out.txt ; rm out.txt
|
||||
|
@ -6,12 +6,12 @@
|
||||
# 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 --insecure --title " passwordform " --passwordform "Example" 12 40 5 \
|
||||
Password1: 1 1 Value1 1 12 18 25 \
|
||||
Password2: 2 1 Value2 2 12 18 25 \
|
||||
Password3: 3 1 Value3 3 12 18 25 \
|
||||
Password4: 4 1 Value4 4 12 18 25 \
|
||||
Password5: 5 1 Value5 5 12 18 25 \
|
||||
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
|
||||
|
@ -6,12 +6,12 @@
|
||||
# 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 --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 \
|
||||
./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
|
||||
|
@ -6,12 +6,12 @@
|
||||
# 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 --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 \
|
||||
./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
|
||||
|
@ -6,6 +6,6 @@
|
||||
# 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 --title yesno --yesno "Hello World!" 6 25
|
||||
./bsddialog --title " yesno " --yesno "Hello World!" 6 25
|
||||
|
@ -1,17 +1,17 @@
|
||||
# PUBLIC DOMAIN - NO WARRANTY, see:
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
#
|
||||
# Written in 2021 by Alfonso Sabato Siciliano
|
||||
|
||||
VERSION = 0.0.2
|
||||
VERSION = 0.1
|
||||
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 = -g -Wall -Werror -fpic
|
||||
LDFLAGS = -lform -lncurses -ltinfo
|
||||
CFLAGS = -Wall -Werror -fpic
|
||||
LDFLAGS = -lformw -lncursesw -ltinfo
|
||||
LIBFLAG = -shared
|
||||
|
||||
RM = rm -f
|
||||
|
74
lib/Makefile
74
lib/Makefile
@ -1,56 +1,55 @@
|
||||
# Any copyright is dedicated to the Public Domain, see:
|
||||
# PUBLIC DOMAIN - NO WARRANTY, see:
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>
|
||||
#
|
||||
# Written in 2021 by Alfonso Sabato Siciliano
|
||||
|
||||
VERSION = 0.0.2
|
||||
VERSION = 0.1
|
||||
LIBRARY = bsddialog
|
||||
LIBRARY_SO = lib${LIBRARY:=.so}
|
||||
LIBRARY_A = lib${LIBRARY:=.a}
|
||||
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 = -I/usr/local/include -fPIC -Wall -Wextra
|
||||
LDFLAGS = -fstack-protector-strong -shared -Wl,-x -Wl,--fatal-warnings \
|
||||
-Wl,--warn-shared-textrel -Wl,-soname,${LIBRARY_SO}.${VERSION}
|
||||
OBJECTS = ${SOURCES:.c=.o}
|
||||
CFLAGS += -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
|
||||
CFLAGS = -g -fPIC -Wall -Wextra
|
||||
.else
|
||||
CFLAGS += -O2 -pipe -std=gnu99 -Wno-format-zero-length \
|
||||
-fstack-protector-strong -Qunused-arguments
|
||||
.endif
|
||||
|
||||
.if defined(PORTNCURSES)
|
||||
# PORT ncurses `make -DPORTNCURSES`
|
||||
CFLAGS += -DPORTNCURSES -I/usr/local/include
|
||||
LDFLAGS += -L/usr/local/lib -lformw -lncursesw -ltinfow
|
||||
.else
|
||||
# BASE ncurses
|
||||
LDFLAGS += -L/usr/lib -lformw -lncursesw -ltinfow
|
||||
.endif
|
||||
|
||||
INSTALL_PREFIX=/usr/local
|
||||
LOCALBASE = /usr/local
|
||||
LN = ln -s -f
|
||||
RM = rm -f
|
||||
CP = cp
|
||||
GZIP = gzip -cn
|
||||
LDCONFIG = /sbin/ldconfig -m
|
||||
MAN= ${OUTPUT}.3
|
||||
GZIP= gzip -cn
|
||||
MANDIR= /usr/local/share/man/man3
|
||||
INSTALL= install
|
||||
RM= rm -f
|
||||
MAN = ${OUTPUT}.3
|
||||
GZIP = gzip -cn
|
||||
MANDIR = ${LOCALBASE}/share/man/man3
|
||||
INSTALL = install
|
||||
RM = rm -f
|
||||
|
||||
#all : man ${LIBRARY}
|
||||
all : ${LIBRARY}
|
||||
all : man ${LIBRARY}
|
||||
|
||||
${LIBRARY}: ${OBJECTS}
|
||||
${LIBRARY}: ${LIBRARY_SO} ${LIBRARY_A}
|
||||
|
||||
${LIBRARY_SO}.${VERSION}: ${OBJECTS}
|
||||
${CC} ${LDFLAGS} ${.ALLSRC} -o ${LIBRARY_SO}.${VERSION}
|
||||
# LN for devel
|
||||
|
||||
${LIBRARY_SO}: ${LIBRARY_SO}.${VERSION}
|
||||
${LN} ${LIBRARY_SO}.${VERSION} ${LIBRARY_SO}
|
||||
|
||||
${LIBRARY_A}: ${OBJECTS}
|
||||
${AR} cr ${.TARGET} ${OBJECTS}
|
||||
${RANLIB} ${.TARGET}
|
||||
|
||||
.c.o:
|
||||
${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
|
||||
|
||||
@ -58,19 +57,20 @@ man:
|
||||
${GZIP} ${LIBRARY}.3 > ${LIBRARY}.3.gz
|
||||
|
||||
clean:
|
||||
${RM} ${LIBRARY_SO}* *.o *~ *.gz
|
||||
${RM} ${LIBRARY_SO}* *.o *~ *.gz ${LIBRARY_A}
|
||||
|
||||
|
||||
install:
|
||||
${CP} ${LIBRARY}.h ${INSTALL_PREFIX}/include
|
||||
${CP} ${LIBRARY_SO}.${VERSION} ${INSTALL_PREFIX}/lib/
|
||||
${LN} ${INSTALL_PREFIX}/lib/${LIBRARY_SO}.${VERSION} ${INSTALL_PREFIX}/lib/${LIBRARY_SO}
|
||||
${LDCONFIG} ${INSTALL_PREFIX}/lib
|
||||
${CP} ${LIBRARY}.3.gz ${INSTALL_PREFIX}/man/man3/
|
||||
${INSTALL} -m 644 ${HEADERS} ${LOCALBASE}/include
|
||||
${INSTALL} -m 644 -s ${LIBRARY_SO}.${VERSION} ${LOCALBASE}/lib/
|
||||
${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}
|
||||
|
||||
unistall:
|
||||
${RM} ${INSTALL_PREFIX}/include/${LIBRARY}.h
|
||||
${RM} ${INSTALL_PREFIX}/lib/${LIBRARY_SO}
|
||||
${RM} ${INSTALL_PREFIX}/lib/${LIBRARY_SO}.${VERSION}
|
||||
${LDCONFIG} ${INSTALL_PREFIX}/lib
|
||||
${RM} ${INSTALL_PREFIX}/man/man3/${LIBRARY}.3.gz
|
||||
${RM} ${LOCALBASE}/include/${LIBRARY}*.h
|
||||
${RM} ${LOCALBASE}/lib/${LIBRARY_SO}
|
||||
${RM} ${LOCALBASE}/lib/${LIBRARY_SO}.${VERSION}
|
||||
${LDCONFIG} ${LOCALBASE}/lib
|
||||
${RM} ${MANDIR}/${LIBRARY}.3.gz
|
||||
|
571
lib/barbox.c
571
lib/barbox.c
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -28,26 +28,19 @@
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#ifdef PORTNCURSES
|
||||
#include <ncurses/ncurses.h>
|
||||
#else
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <curses.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "bsddialog.h"
|
||||
#include "bsddialog_progressview.h"
|
||||
#include "lib_util.h"
|
||||
#include "bsddialog_theme.h"
|
||||
#include "lib_util.h"
|
||||
|
||||
#define BARMARGIN 3
|
||||
#define MINBARWIDTH 10
|
||||
#define MINWIDTH (VBORDERS + MINBARWIDTH + BARMARGIN * 2)
|
||||
#define MINHEIGHT 7 /* without text */
|
||||
|
||||
/* "Bar": gauge - mixedgauge - rangebox - pause - progressview */
|
||||
#define BARPADDING 3
|
||||
#define MINBARWIDTH (15 + BARPADDING * 2)
|
||||
|
||||
bool bsddialog_interruptprogview;
|
||||
bool bsddialog_abortprogview;
|
||||
@ -56,11 +49,11 @@ int bsddialog_total_progview;
|
||||
extern struct bsddialog_theme t;
|
||||
|
||||
static void
|
||||
draw_perc_bar(WINDOW *win, int y, int x, int size, int perc, bool withlabel,
|
||||
draw_bar(WINDOW *win, int y, int x, int size, int perc, bool withlabel,
|
||||
int label)
|
||||
{
|
||||
char labelstr[128];
|
||||
int i, blue_x, color;
|
||||
char labelstr[128];
|
||||
|
||||
blue_x = (int)((perc*(size))/100);
|
||||
|
||||
@ -77,7 +70,7 @@ draw_perc_bar(WINDOW *win, int y, int x, int size, int perc, bool withlabel,
|
||||
else
|
||||
sprintf(labelstr, "%3d%%", perc);
|
||||
wmove(win, y, x + size/2 - 2);
|
||||
for (i=0; i < (int) strlen(labelstr); i++) {
|
||||
for (i = 0; i < (int)strlen(labelstr); i++) {
|
||||
color = (blue_x + 1 <= size/2 - (int)strlen(labelstr)/2 + i ) ?
|
||||
t.bar.color : t.bar.f_color;
|
||||
wattron(win, color);
|
||||
@ -88,49 +81,27 @@ draw_perc_bar(WINDOW *win, int y, int x, int size, int perc, bool withlabel,
|
||||
|
||||
static int
|
||||
bar_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
|
||||
char *text, struct buttons *bs)
|
||||
const char *text, struct buttons *bs)
|
||||
{
|
||||
int maxword, maxline, nlines, buttonswidth;
|
||||
int htext, wtext;
|
||||
|
||||
if (get_text_properties(conf, text, &maxword, &maxline, &nlines) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
buttonswidth = 0;
|
||||
if (bs != NULL) { /* gauge has not buttons */
|
||||
buttonswidth= bs->nbuttons * bs->sizebutton;
|
||||
if (bs->nbuttons > 0)
|
||||
buttonswidth += (bs->nbuttons-1) * t.button.space;
|
||||
if (cols == BSDDIALOG_AUTOSIZE || rows == BSDDIALOG_AUTOSIZE) {
|
||||
if (text_size(conf, rows, cols, text, bs, 3, MINBARWIDTH,
|
||||
&htext, &wtext) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
}
|
||||
|
||||
if (cols == BSDDIALOG_AUTOSIZE) {
|
||||
*w = VBORDERS;
|
||||
/* buttons size */
|
||||
*w += buttonswidth;
|
||||
/* bar size */
|
||||
*w = MAX(*w, MINWIDTH);
|
||||
/* text size*/
|
||||
*w = MAX((int)(maxline + VBORDERS + t.text.hmargin * 2), *w);
|
||||
/* conf.auto_minwidth */
|
||||
*w = MAX(*w, (int)conf->auto_minwidth);
|
||||
/* avoid terminal overflow */
|
||||
*w = MIN(*w, widget_max_width(conf));
|
||||
}
|
||||
if (cols == BSDDIALOG_AUTOSIZE)
|
||||
*w = widget_min_width(conf, wtext, MINBARWIDTH, bs);
|
||||
|
||||
if (rows == BSDDIALOG_AUTOSIZE) {
|
||||
*h = MINHEIGHT;
|
||||
if (maxword > 0)
|
||||
*h += 1;
|
||||
/* conf.auto_minheight */
|
||||
*h = MAX(*h, (int)conf->auto_minheight);
|
||||
/* avoid terminal overflow */
|
||||
*h = MIN(*h, widget_max_height(conf));
|
||||
}
|
||||
if (rows == BSDDIALOG_AUTOSIZE)
|
||||
*h = widget_min_height(conf, htext, 3 /* bar */, bs != NULL);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
bar_checksize(char *text, int rows, int cols, struct buttons *bs)
|
||||
bar_checksize(int rows, int cols, struct buttons *bs)
|
||||
{
|
||||
int minheight, minwidth;
|
||||
|
||||
@ -140,200 +111,213 @@ bar_checksize(char *text, int rows, int cols, struct buttons *bs)
|
||||
if (bs->nbuttons > 0)
|
||||
minwidth += (bs->nbuttons-1) * t.button.space;
|
||||
}
|
||||
minwidth = MAX(minwidth + VBORDERS, MINBARWIDTH);
|
||||
minwidth = MAX(minwidth, MINBARWIDTH);
|
||||
minwidth += VBORDERS;
|
||||
|
||||
if (cols< minwidth)
|
||||
RETURN_ERROR("Few cols for this widget");
|
||||
if (cols < minwidth)
|
||||
RETURN_ERROR("Few cols to draw bar and/or buttons");
|
||||
|
||||
minheight = MINHEIGHT + ((text != NULL && strlen(text) > 0) ? 1 : 0);
|
||||
minheight = HBORDERS + 3;
|
||||
if (bs != NULL)
|
||||
minheight += 2;
|
||||
if (rows < minheight)
|
||||
RETURN_ERROR("Few rows for this mixedgauge");
|
||||
RETURN_ERROR("Few rows to draw bar");
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
bsddialog_gauge(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int perc)
|
||||
bsddialog_gauge(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int perc, int fd, const char *sep)
|
||||
{
|
||||
WINDOW *widget, *textpad, *bar, *shadow;
|
||||
char input[2048], ntext[2048], *pntext;
|
||||
int y, x, h, w, htextpad;
|
||||
bool mainloop;
|
||||
int y, x, h, w, fd2;
|
||||
FILE *input;
|
||||
WINDOW *widget, *textpad, *bar, *shadow;
|
||||
char inputbuf[2048], ntext[2048], *pntext;
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_autosize(conf, rows, cols, &h, &w, text, NULL) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (bar_checksize(text, h, w, NULL) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_checksize(h, w, NULL) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
if (new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w, RAISED,
|
||||
&textpad, &htextpad, text, false) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, NULL,
|
||||
false) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
bar = new_boxed_window(conf, y+h-4, x+3, 3, w-6, RAISED);
|
||||
|
||||
mainloop = true;
|
||||
mainloop = (fd < 0) ? false : true;
|
||||
|
||||
if (mainloop) {
|
||||
fd2 = dup(fd);
|
||||
input = fdopen(fd2, "r");
|
||||
if (input == NULL)
|
||||
RETURN_ERROR("Cannot build FILE* from fd");
|
||||
} else
|
||||
input = NULL;
|
||||
|
||||
while (mainloop) {
|
||||
wrefresh(widget);
|
||||
prefresh(textpad, 0, 0, y+1, x+1+t.text.hmargin, y+h-4,
|
||||
x+w-1-t.text.hmargin);
|
||||
draw_perc_bar(bar, 1, 1, w-8, perc, false, -1 /*unused*/);
|
||||
prefresh(textpad, 0, 0, y+1, x+1+TEXTHMARGIN, y+h-4,
|
||||
x+w-1-TEXTHMARGIN);
|
||||
draw_borders(conf, bar, 3, w-6, RAISED);
|
||||
draw_bar(bar, 1, 1, w-8, perc, false, -1 /*unused*/);
|
||||
wrefresh(bar);
|
||||
|
||||
while (true) {
|
||||
scanf("%s", input);
|
||||
if (strcmp(input,"EOF") == 0) {
|
||||
fscanf(input, "%s", inputbuf);
|
||||
if (strcmp(inputbuf,"EOF") == 0) {
|
||||
mainloop = false;
|
||||
break;
|
||||
}
|
||||
if (strcmp(input,"XXX") == 0)
|
||||
if (strcmp(inputbuf, sep) == 0)
|
||||
break;
|
||||
}
|
||||
scanf("%d", &perc);
|
||||
if (mainloop == false)
|
||||
break;
|
||||
fscanf(input, "%d", &perc);
|
||||
perc = perc < 0 ? 0 : perc;
|
||||
perc = perc > 100 ? 100 : perc;
|
||||
htextpad = 1;
|
||||
wclear(textpad);
|
||||
pntext = &ntext[0];
|
||||
ntext[0] = '\0';
|
||||
while (true) {
|
||||
scanf("%s", input);
|
||||
if (strcmp(input,"EOF") == 0) {
|
||||
fscanf(input, "%s", inputbuf);
|
||||
if (strcmp(inputbuf,"EOF") == 0) {
|
||||
mainloop = false;
|
||||
break;
|
||||
}
|
||||
if (strcmp(input,"XXX") == 0)
|
||||
if (strcmp(inputbuf, sep) == 0)
|
||||
break;
|
||||
strcpy(pntext, inputbuf);
|
||||
pntext += strlen(inputbuf);
|
||||
pntext[0] = ' ';
|
||||
pntext++;
|
||||
strcpy(pntext, input);
|
||||
pntext += strlen(input);
|
||||
}
|
||||
print_textpad(conf, textpad, &htextpad, w-2-t.text.hmargin*2,
|
||||
ntext);
|
||||
if (update_dialog(conf, shadow, widget, y, x, h, w, textpad,
|
||||
ntext, NULL, false) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
}
|
||||
|
||||
if (input != NULL)
|
||||
fclose(input);
|
||||
delwin(bar);
|
||||
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
|
||||
end_dialog(conf, shadow, widget, textpad);
|
||||
|
||||
return BSDDIALOG_OK;
|
||||
return (BSDDIALOG_OK);
|
||||
}
|
||||
|
||||
|
||||
/* Mixedgauge */
|
||||
static int
|
||||
mixedgauge(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int mainperc, unsigned int nminibars, char **minilabels,
|
||||
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)
|
||||
{
|
||||
WINDOW *widget, *textpad, *bar, *shadow;
|
||||
int i, output, miniperc, y, x, h, w, max_minbarlen;
|
||||
int maxword, maxline, nlines, htextpad, ypad;
|
||||
int i, output, miniperc, y, x, h, w, ypad, max_minbarlen;
|
||||
int htextpad, htext, wtext;
|
||||
int colorperc, red, green;
|
||||
WINDOW *widget, *textpad, *bar, *shadow;
|
||||
char states[12][14] = {
|
||||
" Succeeded ", /* 0 */
|
||||
" Failed ", /* 1 */
|
||||
" Passed ", /* 2 */
|
||||
" Completed ", /* 3 */
|
||||
" Checked ", /* 4 */
|
||||
" Done ", /* 5 */
|
||||
" Skipped ", /* 6 */
|
||||
" In Progress ", /* 7 */
|
||||
"(blank) ", /* 8 */
|
||||
" N/A ", /* 9 */
|
||||
" Pending ", /* 10 */
|
||||
" UNKNOWN ", /* 10+ */
|
||||
" Succeeded ", /* -1 */
|
||||
" Failed ", /* -2 */
|
||||
" Passed ", /* -3 */
|
||||
" Completed ", /* -4 */
|
||||
" Checked ", /* -5 */
|
||||
" Done ", /* -6 */
|
||||
" Skipped ", /* -7 */
|
||||
" In Progress ", /* -8 */
|
||||
"(blank) ", /* -9 */
|
||||
" N/A ", /* -10 */
|
||||
" Pending ", /* -11 */
|
||||
" UNKNOWN ", /* < -11, no API */
|
||||
};
|
||||
|
||||
red = bsddialog_color(BSDDIALOG_WHITE,BSDDIALOG_RED, BSDDIALOG_BOLD);
|
||||
green = bsddialog_color(BSDDIALOG_WHITE,BSDDIALOG_GREEN,BSDDIALOG_BOLD);
|
||||
|
||||
max_minbarlen = 0;
|
||||
for (i=0; i < (int)nminibars; i++)
|
||||
for (i = 0; i < (int)nminibars; i++)
|
||||
max_minbarlen = MAX(max_minbarlen, (int)strlen(minilabels[i]));
|
||||
max_minbarlen += 3 + 16 /* seps + [...] or mainbar */;
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
/* mixedgauge autosize */
|
||||
if (get_text_properties(conf, text, &maxword, &maxline, &nlines) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
if (cols == BSDDIALOG_AUTOSIZE) {
|
||||
w = max_minbarlen + HBORDERS;
|
||||
w = MAX(w, maxline + 4);
|
||||
w = MAX(w, (int)conf->auto_minwidth);
|
||||
w = MIN(w, widget_max_width(conf) - 1);
|
||||
}
|
||||
if (rows == BSDDIALOG_AUTOSIZE) {
|
||||
h = 5; /* borders + mainbar */
|
||||
h += nminibars;
|
||||
h += (strlen(text) > 0 ? 3 : 0);
|
||||
h = MAX(h, (int)conf->auto_minheight);
|
||||
h = MIN(h, widget_max_height(conf) -1);
|
||||
if (cols == BSDDIALOG_AUTOSIZE || rows == BSDDIALOG_AUTOSIZE) {
|
||||
if (text_size(conf, rows, cols, text, NULL, nminibars + 3,
|
||||
max_minbarlen, &htext, &wtext) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
}
|
||||
if (cols == BSDDIALOG_AUTOSIZE)
|
||||
w = widget_min_width(conf, wtext, max_minbarlen, NULL);
|
||||
if (rows == BSDDIALOG_AUTOSIZE)
|
||||
h = widget_min_height(conf, htext, nminibars + 3, false);
|
||||
|
||||
/* mixedgauge checksize */
|
||||
if (w < max_minbarlen + 2)
|
||||
RETURN_ERROR("Few cols for this mixedgauge");
|
||||
if (h < 5 + (int)nminibars + (strlen(text) > 0 ? 1 : 0))
|
||||
if (h < 5 + (int)nminibars)
|
||||
RETURN_ERROR("Few rows for this mixedgauge");
|
||||
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
output = new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w,
|
||||
RAISED, &textpad, &htextpad, text, false);
|
||||
output = new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text,
|
||||
NULL, false);
|
||||
if (output == BSDDIALOG_ERROR)
|
||||
return output;
|
||||
return (output);
|
||||
|
||||
/* mini bars */
|
||||
for (i=0; i < (int)nminibars; i++) {
|
||||
for (i = 0; i < (int)nminibars; i++) {
|
||||
miniperc = minipercs[i];
|
||||
if (miniperc == 8)
|
||||
if (miniperc == BSDDIALOG_MG_BLANK)
|
||||
continue;
|
||||
/* label */
|
||||
if (color && (miniperc == 7 || miniperc < 0))
|
||||
if (color && (miniperc >= 0))
|
||||
wattron(widget, A_BOLD);
|
||||
mvwaddstr(widget, i+1, 2, minilabels[i]);
|
||||
wattroff(widget, A_BOLD);
|
||||
/* perc */
|
||||
if (miniperc > 10)
|
||||
if (miniperc < -11)
|
||||
mvwaddstr(widget, i+1, w-2-15, states[11]);
|
||||
else if (miniperc >= 0 && miniperc <= 10) {
|
||||
else if (miniperc < 0) {
|
||||
mvwaddstr(widget, i+1, w-2-15, "[ ]");
|
||||
if (color && miniperc == 1) /* Failed */
|
||||
colorperc = -1;
|
||||
if (color && miniperc == BSDDIALOG_MG_FAILED)
|
||||
colorperc = red;
|
||||
if (color && miniperc == 5) /* Done */
|
||||
if (color && miniperc == BSDDIALOG_MG_DONE)
|
||||
colorperc = green;
|
||||
if (color && (miniperc == 1 || miniperc == 5))
|
||||
if (colorperc != -1)
|
||||
wattron(widget, colorperc);
|
||||
miniperc = abs(miniperc + 1);
|
||||
mvwaddstr(widget, i+1, 1+w-2-15, states[miniperc]);
|
||||
if (color && (miniperc == 1 || miniperc == 5))
|
||||
if (colorperc != -1)
|
||||
wattroff(widget, colorperc);
|
||||
}
|
||||
else { /* miniperc < 0 */
|
||||
miniperc = abs(miniperc);
|
||||
else { /* miniperc >= 0 */
|
||||
if (miniperc > 100)
|
||||
miniperc = 100;
|
||||
mvwaddstr(widget, i+1, w-2-15, "[ ]");
|
||||
draw_perc_bar(widget, i+1, 1+w-2-15, 13, miniperc,
|
||||
false, -1 /*unused*/);
|
||||
draw_bar(widget, i+1, 1+w-2-15, 13, miniperc, false,
|
||||
-1 /*unused*/);
|
||||
}
|
||||
}
|
||||
|
||||
wrefresh(widget);
|
||||
ypad = y + h - 5 - htextpad;
|
||||
getmaxyx(textpad, htextpad, i /* unused */);
|
||||
ypad = y + h - 4 - htextpad;
|
||||
ypad = ypad < y+(int)nminibars ? y+nminibars : ypad;
|
||||
prefresh(textpad, 0, 0, ypad, x+2, y+h-4, x+w-2);
|
||||
|
||||
|
||||
/* main bar */
|
||||
bar = new_boxed_window(conf, y+h -4, x+3, 3, w-6, RAISED);
|
||||
|
||||
draw_perc_bar(bar, 1, 1, w-8, mainperc, false, -1 /*unused*/);
|
||||
|
||||
draw_bar(bar, 1, 1, w-8, mainperc, false, -1 /*unused*/);
|
||||
|
||||
wattron(bar, t.bar.color);
|
||||
mvwaddstr(bar, 0, 2, "Overall Progress");
|
||||
@ -344,48 +328,46 @@ mixedgauge(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
/* getch(); port ncurses shows nothing */
|
||||
|
||||
delwin(bar);
|
||||
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
|
||||
end_dialog(conf, shadow, widget, textpad);
|
||||
|
||||
return BSDDIALOG_OK;
|
||||
return (BSDDIALOG_OK);
|
||||
}
|
||||
|
||||
int
|
||||
bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows,
|
||||
int cols, unsigned int mainperc, unsigned int nminibars, char **minilabels,
|
||||
int *minipercs)
|
||||
bsddialog_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int mainperc, unsigned int nminibars,
|
||||
const char **minilabels, int *minipercs)
|
||||
{
|
||||
int output;
|
||||
|
||||
output = mixedgauge(conf, text, rows, cols, mainperc, nminibars,
|
||||
output = do_mixedgauge(conf, text, rows, cols, mainperc, nminibars,
|
||||
minilabels, minipercs, false);
|
||||
|
||||
return (output);
|
||||
}
|
||||
|
||||
int
|
||||
bsddialog_progressview (struct bsddialog_conf *conf, char * text, int rows,
|
||||
bsddialog_progressview (struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, struct bsddialog_progviewconf *pvconf, unsigned int nminibar,
|
||||
struct bsddialog_fileminibar *minibar)
|
||||
{
|
||||
int perc, output;
|
||||
int *minipercs;
|
||||
unsigned int i;
|
||||
char **minilabels;
|
||||
unsigned int mainperc, totaltodo;
|
||||
time_t tstart, told, tnew, refresh;
|
||||
bool update;
|
||||
int perc, output, *minipercs;
|
||||
unsigned int i, mainperc, totaltodo;
|
||||
float readforsec;
|
||||
const char **minilabels;
|
||||
time_t tstart, told, tnew, refresh;
|
||||
|
||||
if ((minilabels = calloc(nminibar, sizeof(char*))) == NULL)
|
||||
RETURN_ERROR("Cannot allocate memory for minilabels\n");
|
||||
RETURN_ERROR("Cannot allocate memory for minilabels");
|
||||
if ((minipercs = calloc(nminibar, sizeof(int))) == NULL)
|
||||
RETURN_ERROR("Cannot allocate memory for minipercs\n");
|
||||
RETURN_ERROR("Cannot allocate memory for minipercs");
|
||||
|
||||
totaltodo = 0;
|
||||
for(i=0; i<nminibar; i++) {
|
||||
totaltodo += minibar[i].size;
|
||||
for (i = 0; i < nminibar; i++) {
|
||||
totaltodo += minibar[i].size;
|
||||
minilabels[i] = minibar[i].label;
|
||||
minipercs[i] = 10; /*Pending*/
|
||||
minipercs[i] = minibar[i].status;
|
||||
}
|
||||
|
||||
refresh = pvconf->refresh == 0 ? 0 : pvconf->refresh - 1;
|
||||
@ -402,15 +384,15 @@ bsddialog_progressview (struct bsddialog_conf *conf, char * text, int rows,
|
||||
|
||||
time(&tnew);
|
||||
if (update || tnew > told + refresh) {
|
||||
output = mixedgauge(conf, text, rows, cols, mainperc,
|
||||
output = do_mixedgauge(conf, text, rows, cols, mainperc,
|
||||
nminibar, minilabels, minipercs, true);
|
||||
if (output == BSDDIALOG_ERROR)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
move(LINES-1, 2);
|
||||
move(SCREENLINES - 1, 2);
|
||||
clrtoeol();
|
||||
readforsec = ((tnew - tstart) == 0) ?
|
||||
0 : bsddialog_total_progview / (float)(tnew - tstart);
|
||||
readforsec = ((tnew - tstart) == 0) ? 0 :
|
||||
bsddialog_total_progview / (float)(tnew - tstart);
|
||||
printw(pvconf->fmtbottomstr, bsddialog_total_progview,
|
||||
readforsec);
|
||||
refresh();
|
||||
@ -421,22 +403,20 @@ bsddialog_progressview (struct bsddialog_conf *conf, char * text, int rows,
|
||||
|
||||
if (i >= nminibar)
|
||||
break;
|
||||
if (minibar[i].status == 1) /* Failed*/
|
||||
if (minibar[i].status == BSDDIALOG_MG_FAILED)
|
||||
break;
|
||||
|
||||
perc = pvconf->callback(&minibar[i]);
|
||||
|
||||
if (minibar[i].status == 5) {/* ||prec >= 100) Done */
|
||||
minipercs[i] = 5;
|
||||
if (minibar[i].status == BSDDIALOG_MG_DONE) { /*||perc >= 100)*/
|
||||
minipercs[i] = BSDDIALOG_MG_DONE;
|
||||
update = true;
|
||||
i++;
|
||||
} else if (minibar[i].status == 1 || perc < 0) { /* Failed */
|
||||
minipercs[i] = 1;
|
||||
} else if (minibar[i].status == BSDDIALOG_MG_FAILED || perc < 0) {
|
||||
minipercs[i] = BSDDIALOG_MG_FAILED;
|
||||
update = true;
|
||||
} else if (perc == 0)
|
||||
minipercs[i] = 7; /* In progress */
|
||||
else /* perc > 0 */
|
||||
minipercs[i] = -(perc);
|
||||
} else /* perc >= 0 */
|
||||
minipercs[i] = perc;
|
||||
}
|
||||
|
||||
free(minilabels);
|
||||
@ -445,14 +425,14 @@ bsddialog_progressview (struct bsddialog_conf *conf, char * text, int rows,
|
||||
}
|
||||
|
||||
int
|
||||
bsddialog_rangebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
int min, int max, int *value)
|
||||
bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, int min, int max, int *value)
|
||||
{
|
||||
WINDOW *widget, *textpad, *bar, *shadow;
|
||||
int i, y, x, h, w, htextpad;
|
||||
bool loop, buttupdate, barupdate;
|
||||
int y, x, h, w;
|
||||
int input, currvalue, output, sizebar, bigchange, positions;
|
||||
float perc;
|
||||
WINDOW *widget, *textpad, *bar, *shadow;
|
||||
struct buttons bs;
|
||||
|
||||
if (value == NULL)
|
||||
@ -464,41 +444,41 @@ bsddialog_rangebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
currvalue = *value;
|
||||
positions = max - min + 1;
|
||||
|
||||
get_buttons(conf, &bs, BUTTONLABEL(ok_label), BUTTONLABEL(extra_label),
|
||||
BUTTONLABEL(cancel_label), BUTTONLABEL(help_label));
|
||||
get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_autosize(conf, rows, cols, &h, &w, text, &bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (bar_checksize(text, h, w, &bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_checksize(h, w, &bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
if (new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w, RAISED,
|
||||
&textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs,
|
||||
true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
prefresh(textpad, 0, 0, y+1, x+1+t.text.hmargin, y+h-7,
|
||||
x+w-1-t.text.hmargin);
|
||||
doupdate();
|
||||
|
||||
sizebar = w - HBORDERS - 2 - BARMARGIN * 2;
|
||||
prefresh(textpad, 0, 0, y+1, x+1+TEXTHMARGIN, y+h-7, x+w-1-TEXTHMARGIN);
|
||||
|
||||
sizebar = w - HBORDERS - 2 - BARPADDING * 2;
|
||||
bigchange = MAX(1, sizebar/10);
|
||||
|
||||
bar = new_boxed_window(conf, y + h - 6, x + 1 + BARMARGIN, 3,
|
||||
bar = new_boxed_window(conf, y + h - 6, x + 1 + BARPADDING, 3,
|
||||
sizebar + 2, RAISED);
|
||||
|
||||
loop = buttupdate = barupdate = true;
|
||||
while(loop) {
|
||||
while (loop) {
|
||||
if (buttupdate) {
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
draw_buttons(widget, bs, true);
|
||||
wrefresh(widget);
|
||||
buttupdate = false;
|
||||
}
|
||||
if (barupdate) {
|
||||
perc = ((float)(currvalue - min)*100) / (positions-1);
|
||||
draw_perc_bar(bar, 1, 1, sizebar, perc, true, currvalue);
|
||||
draw_bar(bar, 1, 1, sizebar, perc, true, currvalue);
|
||||
barupdate = false;
|
||||
wrefresh(bar);
|
||||
}
|
||||
@ -512,8 +492,10 @@ bsddialog_rangebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
loop = false;
|
||||
break;
|
||||
case 27: /* Esc */
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
if (conf->key.enable_esc) {
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
}
|
||||
break;
|
||||
case '\t': /* TAB */
|
||||
bs.curr = (bs.curr + 1) % bs.nbuttons;
|
||||
@ -567,125 +549,108 @@ bsddialog_rangebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
if (conf->f1_file == NULL && conf->f1_message == NULL)
|
||||
break;
|
||||
if (f1help(conf) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
/* No break! the terminal size can change */
|
||||
return (BSDDIALOG_ERROR);
|
||||
/* No break, screen size can change */
|
||||
case KEY_RESIZE:
|
||||
hide_widget(y, x, h, w,conf->shadow);
|
||||
|
||||
/*
|
||||
* Unnecessary, but, when the columns decrease the
|
||||
* following "refresh" seem not work
|
||||
*/
|
||||
/* Important for decreasing screen */
|
||||
hide_widget(y, x, h, w, conf->shadow);
|
||||
refresh();
|
||||
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (bar_autosize(conf, rows, cols, &h, &w, text, &bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (bar_checksize(text, h, w, &bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_autosize(conf, rows, cols, &h, &w, text,
|
||||
&bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_checksize(h, w, &bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
wclear(shadow);
|
||||
mvwin(shadow, y + t.shadow.h, x + t.shadow.w);
|
||||
wresize(shadow, h, w);
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
wclear(widget);
|
||||
mvwin(widget, y, x);
|
||||
wresize(widget, h, w);
|
||||
if (update_dialog(conf, shadow, widget,y, x, h, w,
|
||||
textpad, text, &bs, true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
htextpad = 1;
|
||||
wclear(textpad);
|
||||
wresize(textpad, 1, w - HBORDERS - t.text.hmargin * 2);
|
||||
doupdate();
|
||||
|
||||
sizebar = w - HBORDERS - 2 - BARMARGIN * 2;
|
||||
sizebar = w - HBORDERS - 2 - BARPADDING * 2;
|
||||
bigchange = MAX(1, sizebar/10);
|
||||
wclear(bar);
|
||||
mvwin(bar, y + h - 6, x + 1 + BARMARGIN);
|
||||
mvwin(bar, y + h - 6, x + 1 + BARPADDING);
|
||||
wresize(bar, 3, sizebar + 2);
|
||||
draw_borders(conf, bar, 3, sizebar+2, RAISED);
|
||||
|
||||
if(update_widget_withtextpad(conf, shadow, widget, h, w,
|
||||
RAISED, textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
prefresh(textpad, 0, 0, y+1, x+1+t.text.hmargin, y+h-7,
|
||||
x+w-1-t.text.hmargin);
|
||||
|
||||
draw_borders(conf, bar, 3, sizebar + 2, RAISED);
|
||||
prefresh(textpad, 0, 0, y+1, x+1+TEXTHMARGIN, y+h-7,
|
||||
x+w-1-TEXTHMARGIN);
|
||||
|
||||
barupdate = true;
|
||||
buttupdate = true;
|
||||
break;
|
||||
default:
|
||||
for (i = 0; i < (int) bs.nbuttons; i++)
|
||||
if (tolower(input) == tolower((bs.label[i])[0])) {
|
||||
output = bs.value[i];
|
||||
loop = false;
|
||||
if (shortcut_buttons(input, &bs)) {
|
||||
output = bs.value[bs.curr];
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delwin(bar);
|
||||
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
|
||||
end_dialog(conf, shadow, widget, textpad);
|
||||
|
||||
return output;
|
||||
return (output);
|
||||
}
|
||||
|
||||
int
|
||||
bsddialog_pause(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int sec)
|
||||
bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int sec)
|
||||
{
|
||||
WINDOW *widget, *textpad, *bar, *shadow;
|
||||
int i, output, y, x, h, w, htextpad;
|
||||
bool loop, buttupdate, barupdate;
|
||||
int input, tout, sizebar;
|
||||
int output, y, x, h, w, input, tout, sizebar;
|
||||
float perc;
|
||||
WINDOW *widget, *textpad, *bar, *shadow;
|
||||
struct buttons bs;
|
||||
|
||||
get_buttons(conf, &bs, BUTTONLABEL(ok_label), BUTTONLABEL(extra_label),
|
||||
BUTTONLABEL(cancel_label), BUTTONLABEL(help_label));
|
||||
get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_autosize(conf, rows, cols, &h, &w, text, &bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (bar_checksize(text, h, w, &bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_checksize(h, w, &bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
if (new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w, RAISED,
|
||||
&textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
prefresh(textpad, 0, 0, y+1, x+1+t.text.hmargin, y+h-7,
|
||||
x+w-1-t.text.hmargin);
|
||||
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs,
|
||||
true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
sizebar = w - HBORDERS - 2 - BARMARGIN * 2;
|
||||
bar = new_boxed_window(conf, y + h - 6, x + 1 + BARMARGIN, 3,
|
||||
doupdate();
|
||||
|
||||
prefresh(textpad, 0, 0, y+1, x+1+TEXTHMARGIN, y+h-7, x+w-1-TEXTHMARGIN);
|
||||
|
||||
sizebar = w - HBORDERS - 2 - BARPADDING * 2;
|
||||
bar = new_boxed_window(conf, y + h - 6, x + 1 + BARPADDING, 3,
|
||||
sizebar + 2, RAISED);
|
||||
|
||||
tout = sec;
|
||||
nodelay(stdscr, TRUE);
|
||||
timeout(1000);
|
||||
loop = buttupdate = barupdate = true;
|
||||
while(loop) {
|
||||
while (loop) {
|
||||
if (barupdate) {
|
||||
perc = (float)tout * 100 / sec;
|
||||
draw_perc_bar(bar, 1, 1, sizebar, perc, true, tout);
|
||||
draw_bar(bar, 1, 1, sizebar, perc, true, tout);
|
||||
barupdate = false;
|
||||
wrefresh(bar);
|
||||
}
|
||||
|
||||
if (buttupdate) {
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
draw_buttons(widget, bs, true);
|
||||
wrefresh(widget);
|
||||
buttupdate = false;
|
||||
}
|
||||
|
||||
input = getch();
|
||||
if(input < 0) { /* timeout */
|
||||
if (input < 0) { /* timeout */
|
||||
tout--;
|
||||
if (tout < 0) {
|
||||
output = BSDDIALOG_TIMEOUT;
|
||||
@ -703,8 +668,10 @@ bsddialog_pause(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
loop = false;
|
||||
break;
|
||||
case 27: /* Esc */
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
if (conf->key.enable_esc) {
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
}
|
||||
break;
|
||||
case '\t': /* TAB */
|
||||
bs.curr = (bs.curr + 1) % bs.nbuttons;
|
||||
@ -726,60 +693,44 @@ bsddialog_pause(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
if (conf->f1_file == NULL && conf->f1_message == NULL)
|
||||
break;
|
||||
if (f1help(conf) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
/* No break! the terminal size can change */
|
||||
return (BSDDIALOG_ERROR);
|
||||
/* No break, screen size can change */
|
||||
case KEY_RESIZE:
|
||||
hide_widget(y, x, h, w,conf->shadow);
|
||||
|
||||
/*
|
||||
* Unnecessary, but, when the columns decrease the
|
||||
* following "refresh" seem not work
|
||||
*/
|
||||
/* Important for decreasing screen */
|
||||
hide_widget(y, x, h, w, conf->shadow);
|
||||
refresh();
|
||||
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (bar_autosize(conf, rows, cols, &h, &w, text, &bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (bar_checksize(text, h, w, &bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_autosize(conf, rows, cols, &h, &w, text,
|
||||
&bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (bar_checksize(h, w, &bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
wclear(shadow);
|
||||
mvwin(shadow, y + t.shadow.h, x + t.shadow.w);
|
||||
wresize(shadow, h, w);
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
wclear(widget);
|
||||
mvwin(widget, y, x);
|
||||
wresize(widget, h, w);
|
||||
if (update_dialog(conf, shadow, widget,y, x, h, w,
|
||||
textpad, text, &bs, true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
htextpad = 1;
|
||||
wclear(textpad);
|
||||
wresize(textpad, 1, w - HBORDERS - t.text.hmargin * 2);
|
||||
doupdate();
|
||||
|
||||
sizebar = w - HBORDERS - 2 - BARMARGIN * 2;
|
||||
sizebar = w - HBORDERS - 2 - BARPADDING * 2;
|
||||
wclear(bar);
|
||||
mvwin(bar, y + h - 6, x + 1 + BARMARGIN);
|
||||
mvwin(bar, y + h - 6, x + 1 + BARPADDING);
|
||||
wresize(bar, 3, sizebar + 2);
|
||||
draw_borders(conf, bar, 3, sizebar+2, LOWERED);
|
||||
|
||||
if(update_widget_withtextpad(conf, shadow, widget, h, w,
|
||||
RAISED, textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
prefresh(textpad, 0, 0, y+1, x+1+t.text.hmargin, y+h-7,
|
||||
x+w-1-t.text.hmargin);
|
||||
|
||||
draw_borders(conf, bar, 3, sizebar + 2, RAISED);
|
||||
prefresh(textpad, 0, 0, y+1, x+1+TEXTHMARGIN, y+h-7,
|
||||
x+w-1-TEXTHMARGIN);
|
||||
|
||||
barupdate = true;
|
||||
buttupdate = true;
|
||||
break;
|
||||
default:
|
||||
for (i = 0; i < (int) bs.nbuttons; i++)
|
||||
if (tolower(input) == tolower((bs.label[i])[0])) {
|
||||
output = bs.value[i];
|
||||
loop = false;
|
||||
if (shortcut_buttons(input, &bs)) {
|
||||
output = bs.value[bs.curr];
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -787,7 +738,7 @@ bsddialog_pause(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
nodelay(stdscr, FALSE);
|
||||
|
||||
delwin(bar);
|
||||
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
|
||||
end_dialog(conf, shadow, widget, textpad);
|
||||
|
||||
return output;
|
||||
}
|
||||
return (output);
|
||||
}
|
811
lib/bsddialog.3
811
lib/bsddialog.3
File diff suppressed because it is too large
Load Diff
182
lib/bsddialog.h
182
lib/bsddialog.h
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -30,83 +30,100 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define LIBBSDDIALOG_VERSION "0.0.2"
|
||||
#define LIBBSDDIALOG_VERSION "0.1"
|
||||
|
||||
/* Exit status */
|
||||
#define BSDDIALOG_ERROR -1
|
||||
#define BSDDIALOG_OK 0
|
||||
#define BSDDIALOG_YES BSDDIALOG_OK
|
||||
#define BSDDIALOG_CANCEL 1
|
||||
#define BSDDIALOG_NO BSDDIALOG_CANCEL
|
||||
#define BSDDIALOG_HELP 2
|
||||
#define BSDDIALOG_EXTRA 3
|
||||
#define BSDDIALOG_TIMEOUT 4
|
||||
#define BSDDIALOG_ESC 5
|
||||
#define BSDDIALOG_GENERIC1 6
|
||||
#define BSDDIALOG_GENERIC2 7
|
||||
#define BSDDIALOG_ERROR -1
|
||||
#define BSDDIALOG_OK 0
|
||||
#define BSDDIALOG_YES BSDDIALOG_OK
|
||||
#define BSDDIALOG_CANCEL 1
|
||||
#define BSDDIALOG_NO BSDDIALOG_CANCEL
|
||||
#define BSDDIALOG_HELP 2
|
||||
#define BSDDIALOG_EXTRA 3
|
||||
#define BSDDIALOG_TIMEOUT 4
|
||||
#define BSDDIALOG_ESC 5
|
||||
#define BSDDIALOG_GENERIC1 6
|
||||
#define BSDDIALOG_GENERIC2 7
|
||||
|
||||
/* Size and position */
|
||||
#define BSDDIALOG_FULLSCREEN -1
|
||||
#define BSDDIALOG_AUTOSIZE 0
|
||||
#define BSDDIALOG_CENTER -1
|
||||
#define BSDDIALOG_FULLSCREEN -1
|
||||
#define BSDDIALOG_AUTOSIZE 0
|
||||
#define BSDDIALOG_CENTER -1
|
||||
|
||||
/* Mixedgauge */
|
||||
#define BSDDIALOG_MG_SUCCEEDED -1
|
||||
#define BSDDIALOG_MG_FAILED -2
|
||||
#define BSDDIALOG_MG_PASSED -3
|
||||
#define BSDDIALOG_MG_COMPLETED -4
|
||||
#define BSDDIALOG_MG_CHECKED -5
|
||||
#define BSDDIALOG_MG_DONE -6
|
||||
#define BSDDIALOG_MG_SKIPPED -7
|
||||
#define BSDDIALOG_MG_INPROGRESS -8
|
||||
#define BSDDIALOG_MG_BLANK -9
|
||||
#define BSDDIALOG_MG_NA -10
|
||||
#define BSDDIALOG_MG_PENDING -11
|
||||
|
||||
/* Form */
|
||||
#define BSDDIALOG_FIELDHIDDEN 1U
|
||||
#define BSDDIALOG_FIELDREADONLY 2U
|
||||
|
||||
struct bsddialog_conf {
|
||||
bool ascii_lines;
|
||||
unsigned int aspect_ratio;
|
||||
unsigned int auto_minheight;
|
||||
unsigned int auto_minwidth;
|
||||
char *bottomtitle;
|
||||
const char *bottomtitle;
|
||||
bool clear;
|
||||
char *f1_file;
|
||||
char *f1_message;
|
||||
int *get_height;
|
||||
int *get_width;
|
||||
const char *f1_file;
|
||||
const char *f1_message;
|
||||
int *get_height;
|
||||
int *get_width;
|
||||
bool no_lines;
|
||||
bool shadow;
|
||||
unsigned int sleep;
|
||||
char *title;
|
||||
int y;
|
||||
int x;
|
||||
const char *title;
|
||||
int y;
|
||||
int x;
|
||||
struct {
|
||||
bool colors;
|
||||
bool enable_esc;
|
||||
} key;
|
||||
struct {
|
||||
bool highlight;
|
||||
unsigned int tablen;
|
||||
} text;
|
||||
struct {
|
||||
bool align_left;
|
||||
char *default_item;
|
||||
bool no_desc;
|
||||
bool no_name;
|
||||
bool on_without_ok;
|
||||
bool shortcut_buttons;
|
||||
} menu;
|
||||
struct {
|
||||
int securech;
|
||||
bool value_withcancel;
|
||||
bool value_withextra;
|
||||
bool value_withhelp;
|
||||
bool value_without_ok;
|
||||
} form;
|
||||
struct {
|
||||
bool without_ok;
|
||||
char *ok_label;
|
||||
const char *ok_label;
|
||||
bool with_extra;
|
||||
char *extra_label;
|
||||
const char *extra_label;
|
||||
bool without_cancel;
|
||||
char *cancel_label;
|
||||
const char *cancel_label;
|
||||
bool default_cancel;
|
||||
bool with_help;
|
||||
char *help_label;
|
||||
char *exit_label;
|
||||
char *generic1_label;
|
||||
char *generic2_label;
|
||||
char *default_label;
|
||||
const char *help_label;
|
||||
const char *generic1_label;
|
||||
const char *generic2_label;
|
||||
const char *default_label;
|
||||
} button;
|
||||
};
|
||||
|
||||
struct bsddialog_menuitem {
|
||||
char *prefix;
|
||||
const char *prefix;
|
||||
bool on;
|
||||
unsigned int depth;
|
||||
char *name;
|
||||
char *desc;
|
||||
char *bottomdesc;
|
||||
const char *name;
|
||||
const char *desc;
|
||||
const char *bottomdesc;
|
||||
};
|
||||
|
||||
enum bsddialog_grouptype {
|
||||
@ -122,96 +139,93 @@ struct bsddialog_menugroup {
|
||||
};
|
||||
|
||||
struct bsddialog_formitem {
|
||||
char *label;
|
||||
const char *label;
|
||||
unsigned int ylabel;
|
||||
unsigned int xlabel;
|
||||
|
||||
char *init;
|
||||
const char *init;
|
||||
unsigned int yfield;
|
||||
unsigned int xfield;
|
||||
unsigned int fieldlen;
|
||||
unsigned int maxvaluelen;
|
||||
char *value;
|
||||
#define BSDDIALOG_FIELDHIDDEN 1U
|
||||
#define BSDDIALOG_FIELDREADONLY 2U
|
||||
unsigned int flags;
|
||||
|
||||
char *bottomdesc;
|
||||
const char *bottomdesc;
|
||||
};
|
||||
|
||||
int bsddialog_init(void);
|
||||
int bsddialog_end(void);
|
||||
int bsddialog_backtitle(struct bsddialog_conf *conf, char *backtitle);
|
||||
int bsddialog_backtitle(struct bsddialog_conf *conf, const char *backtitle);
|
||||
int bsddialog_initconf(struct bsddialog_conf *conf);
|
||||
int bsddialog_clearterminal(void);
|
||||
const char *bsddialog_geterror(void);
|
||||
|
||||
/* Dialogs */
|
||||
int
|
||||
bsddialog_buildlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int menurows, int nitems, struct bsddialog_menuitem *items,
|
||||
int *focusitem);
|
||||
bsddialog_checklist(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int menurows, unsigned int nitems,
|
||||
struct bsddialog_menuitem *items, int *focusitem);
|
||||
|
||||
int
|
||||
bsddialog_checklist(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int menurows, int nitems, struct bsddialog_menuitem *items,
|
||||
int *focusitem);
|
||||
bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd);
|
||||
|
||||
int
|
||||
bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int *yy, unsigned int *mm, unsigned int *dd);
|
||||
|
||||
int
|
||||
bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int formheight, unsigned int nitems,
|
||||
bsddialog_form(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int formheight, unsigned int nitems,
|
||||
struct bsddialog_formitem *items);
|
||||
|
||||
int
|
||||
bsddialog_gauge(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int perc);
|
||||
bsddialog_gauge(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int perc, int fd, const char *sep);
|
||||
|
||||
int
|
||||
bsddialog_infobox(struct bsddialog_conf *conf, char* text, int rows, int cols);
|
||||
bsddialog_infobox(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols);
|
||||
|
||||
int
|
||||
bsddialog_menu(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int menurows, int nitems, struct bsddialog_menuitem *items,
|
||||
int *focusitem);
|
||||
bsddialog_menu(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int menurows, unsigned int nitems,
|
||||
struct bsddialog_menuitem *items, int *focusitem);
|
||||
|
||||
int
|
||||
bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows,
|
||||
int cols, unsigned int mainperc, unsigned int nminibars, char **minilabels,
|
||||
int *minipercs);
|
||||
bsddialog_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int mainperc, unsigned int nminibars,
|
||||
const char **minilabels, int *minipercs);
|
||||
|
||||
int
|
||||
bsddialog_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int menurows, int ngroups, struct bsddialog_menugroup *groups,
|
||||
int *focuslist, int *focusitem);
|
||||
bsddialog_mixedlist(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int menurows, unsigned int ngroups,
|
||||
struct bsddialog_menugroup *groups, int *focuslist, int *focusitem);
|
||||
|
||||
int
|
||||
bsddialog_msgbox(struct bsddialog_conf *conf, char* text, int rows, int cols);
|
||||
bsddialog_msgbox(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols);
|
||||
|
||||
int
|
||||
bsddialog_pause(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int sec);
|
||||
bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int seconds);
|
||||
|
||||
int
|
||||
bsddialog_radiolist(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int menurows, int nitems, struct bsddialog_menuitem *items,
|
||||
int *focusitem);
|
||||
bsddialog_radiolist(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int menurows, unsigned int nitems,
|
||||
struct bsddialog_menuitem *items, int *focusitem);
|
||||
|
||||
int
|
||||
bsddialog_rangebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
int min, int max, int *value);
|
||||
bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, int min, int max, int *value);
|
||||
|
||||
int
|
||||
bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols);
|
||||
bsddialog_textbox(struct bsddialog_conf *conf, const char *file, int rows,
|
||||
int cols);
|
||||
|
||||
int
|
||||
bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int *hh, unsigned int *mm, unsigned int *ss);
|
||||
bsddialog_timebox(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int *hh, unsigned int *mm, unsigned int *ss);
|
||||
|
||||
int
|
||||
bsddialog_yesno(struct bsddialog_conf *conf, char* text, int rows, int cols);
|
||||
bsddialog_yesno(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols);
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -28,27 +28,33 @@
|
||||
#ifndef _LIBBSDDIALOG_PROGRESSVIEW_H_
|
||||
#define _LIBBSDDIALOG_PROGRESSVIEW_H_
|
||||
|
||||
/*
|
||||
* Undocumented API, DO NOT USE!
|
||||
* Please consider this file private: it is used by bsdinstall/distextract,
|
||||
* could be deleted or changed in the future.
|
||||
*/
|
||||
|
||||
extern bool bsddialog_interruptprogview;
|
||||
extern bool bsddialog_abortprogview;
|
||||
extern int bsddialog_total_progview;
|
||||
|
||||
struct bsddialog_fileminibar {
|
||||
char *path;
|
||||
char *label;
|
||||
int status; /* mixedgauge: 1 failed - 5 done - 7 in progress*/
|
||||
const char *path;
|
||||
const char *label;
|
||||
int status; /* next if BSDDIALOG_MG_DONE or BSDDIALOG_MG_FAILED */
|
||||
long long size;
|
||||
long long read;
|
||||
};
|
||||
|
||||
struct bsddialog_progviewconf {
|
||||
char *fmtbottomstr;
|
||||
const char *fmtbottomstr;
|
||||
unsigned int refresh; /* in seconds */
|
||||
int (*callback)(struct bsddialog_fileminibar *minibar);
|
||||
};
|
||||
|
||||
int
|
||||
bsddialog_progressview (struct bsddialog_conf *conf, char * text, int rows,
|
||||
bsddialog_progressview (struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, struct bsddialog_progviewconf *pvconf, unsigned int nminibar,
|
||||
struct bsddialog_fileminibar *minibar);
|
||||
|
||||
#endif
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -28,11 +28,15 @@
|
||||
#ifndef _LIBBSDDIALOG_THEME_H_
|
||||
#define _LIBBSDDIALOG_THEME_H_
|
||||
|
||||
/* f_ focus/active element */
|
||||
/* color flags */
|
||||
#define BSDDIALOG_BOLD 1U
|
||||
#define BSDDIALOG_REVERSE 2U
|
||||
#define BSDDIALOG_UNDERLINE 4U
|
||||
|
||||
struct bsddialog_theme {
|
||||
struct {
|
||||
int color;
|
||||
} terminal;
|
||||
} screen;
|
||||
struct {
|
||||
int color;
|
||||
unsigned int h;
|
||||
@ -46,9 +50,6 @@ struct bsddialog_theme {
|
||||
int linelowercolor;
|
||||
int bottomtitlecolor;
|
||||
} dialog;
|
||||
struct {
|
||||
unsigned int hmargin;
|
||||
} text;
|
||||
struct {
|
||||
int arrowcolor;
|
||||
int selectorcolor;
|
||||
@ -87,7 +88,7 @@ enum bsddialog_default_theme {
|
||||
BSDDIALOG_THEME_BLACKWHITE,
|
||||
BSDDIALOG_THEME_BSDDIALOG,
|
||||
BSDDIALOG_THEME_DEFAULT,
|
||||
BSDDIALOG_THEME_DIALOG,
|
||||
BSDDIALOG_THEME_DIALOG
|
||||
};
|
||||
|
||||
enum bsddialog_color {
|
||||
@ -98,13 +99,9 @@ enum bsddialog_color {
|
||||
BSDDIALOG_BLUE,
|
||||
BSDDIALOG_MAGENTA,
|
||||
BSDDIALOG_CYAN,
|
||||
BSDDIALOG_WHITE,
|
||||
BSDDIALOG_WHITE
|
||||
};
|
||||
|
||||
#define BSDDIALOG_BOLD 1U
|
||||
#define BSDDIALOG_REVERSE 2U
|
||||
#define BSDDIALOG_UNDERLINE 4U
|
||||
|
||||
int
|
||||
bsddialog_color(enum bsddialog_color foreground,
|
||||
enum bsddialog_color background, unsigned int flags);
|
||||
@ -112,4 +109,4 @@ int bsddialog_get_theme(struct bsddialog_theme *theme);
|
||||
int bsddialog_set_default_theme(enum bsddialog_default_theme theme);
|
||||
int bsddialog_set_theme(struct bsddialog_theme *theme);
|
||||
|
||||
#endif
|
||||
#endif
|
277
lib/formbox.c
277
lib/formbox.c
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -28,35 +28,29 @@
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#ifdef PORTNCURSES
|
||||
#include <ncurses/form.h>
|
||||
#else
|
||||
#include <form.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bsddialog.h"
|
||||
#include "lib_util.h"
|
||||
#include "bsddialog_theme.h"
|
||||
#include "lib_util.h"
|
||||
|
||||
#define REDRAWFORM 14021986 /* magic number */
|
||||
#define REDRAWFORM 19860214 /* magic number */
|
||||
#define ISFIELDHIDDEN(item) (item.flags & BSDDIALOG_FIELDHIDDEN)
|
||||
#define ISFIELDREADONLY(item) (item.flags & BSDDIALOG_FIELDREADONLY)
|
||||
|
||||
/* "Form": inputbox - passwordbox - form - passwordform - mixedform */
|
||||
|
||||
extern struct bsddialog_theme t;
|
||||
|
||||
/* util struct for private buffer and view options */
|
||||
/* field_userptr for private buffer and view options */
|
||||
struct myfield {
|
||||
int buflen;
|
||||
int buflen;
|
||||
char *buf;
|
||||
int pos;
|
||||
int maxpos;
|
||||
int pos;
|
||||
int maxpos;
|
||||
bool secure;
|
||||
int securech;
|
||||
char *bottomdesc;
|
||||
int securech;
|
||||
const char *bottomdesc;
|
||||
};
|
||||
#define GETMYFIELD(field) ((struct myfield*)field_userptr(field))
|
||||
#define GETMYFIELD2(form) ((struct myfield*)field_userptr(current_field(form)))
|
||||
@ -95,8 +89,7 @@ static void shiftleft(struct myfield *mf)
|
||||
|
||||
static void print_bottomdesc(struct myfield *mf)
|
||||
{
|
||||
|
||||
move(LINES-1, 2);
|
||||
move(SCREENLINES - 1, 2);
|
||||
clrtoeol();
|
||||
if (mf->bottomdesc != NULL) {
|
||||
addstr(mf->bottomdesc);
|
||||
@ -105,26 +98,18 @@ static void print_bottomdesc(struct myfield *mf)
|
||||
}
|
||||
|
||||
int
|
||||
return_values(struct bsddialog_conf *conf, struct buttons bs, int nitems,
|
||||
return_values(struct bsddialog_conf *conf, int output, int nitems,
|
||||
struct bsddialog_formitem *items, FORM *form, FIELD **cfield)
|
||||
{
|
||||
int i, output;
|
||||
int i;
|
||||
struct myfield *mf;
|
||||
|
||||
output = bs.value[bs.curr];
|
||||
if (output == BSDDIALOG_HELP && conf->form.value_withhelp == false)
|
||||
return output;
|
||||
if (output == BSDDIALOG_EXTRA && conf->form.value_withextra == false)
|
||||
return output;
|
||||
if (output == BSDDIALOG_CANCEL && conf->form.value_withcancel == false)
|
||||
return output;
|
||||
if (output == BSDDIALOG_GENERIC1 || output == BSDDIALOG_GENERIC2)
|
||||
return output;
|
||||
if (output != BSDDIALOG_OK && conf->form.value_without_ok == false)
|
||||
return (output);
|
||||
|
||||
/* BSDDIALOG_OK */
|
||||
form_driver(form, REQ_NEXT_FIELD);
|
||||
form_driver(form, REQ_PREV_FIELD);
|
||||
for (i=0; i<nitems; i++) {
|
||||
for (i = 0; i < nitems; i++) {
|
||||
mf = GETMYFIELD(cfield[i]);
|
||||
items[i].value = strdup(mf->buf);
|
||||
if (items[i].value == NULL)
|
||||
@ -135,11 +120,11 @@ return_values(struct bsddialog_conf *conf, struct buttons bs, int nitems,
|
||||
}
|
||||
|
||||
static int
|
||||
form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
|
||||
struct buttons bs, WINDOW *formwin, FORM *form, FIELD **cfield, int nitems,
|
||||
form_handler(struct bsddialog_conf *conf, WINDOW *widget, struct buttons bs,
|
||||
WINDOW *formwin, FORM *form, FIELD **cfield, int nitems,
|
||||
struct bsddialog_formitem *items)
|
||||
{
|
||||
bool loop, buttupdate, informwin = true;
|
||||
bool loop, buttupdate, informwin;
|
||||
int i, input, output;
|
||||
struct myfield *mf;
|
||||
|
||||
@ -149,11 +134,15 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
|
||||
form_driver(form, REQ_END_LINE);
|
||||
mf->pos = MIN(mf->buflen, mf->maxpos);
|
||||
curs_set(2);
|
||||
informwin = true;
|
||||
|
||||
bs.curr = -1;
|
||||
loop = buttupdate = true;
|
||||
while(loop) {
|
||||
buttupdate = true;
|
||||
|
||||
loop = true;
|
||||
while (loop) {
|
||||
if (buttupdate) {
|
||||
draw_buttons(widget, y, cols, bs, !informwin);
|
||||
draw_buttons(widget, bs, !informwin);
|
||||
wrefresh(widget);
|
||||
buttupdate = false;
|
||||
}
|
||||
@ -164,12 +153,16 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
|
||||
case 10: /* Enter */
|
||||
if (informwin)
|
||||
break;
|
||||
output = return_values(conf, bs.value[bs.curr], nitems,
|
||||
items, form, cfield);
|
||||
loop = false;
|
||||
output = return_values(conf, bs, nitems, items, form, cfield);
|
||||
break;
|
||||
case 27: /* Esc */
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
if (conf->key.enable_esc) {
|
||||
output = return_values(conf, BSDDIALOG_ESC,
|
||||
nitems, items, form, cfield);
|
||||
loop = false;
|
||||
}
|
||||
break;
|
||||
case '\t': /* TAB */
|
||||
if (informwin) {
|
||||
@ -178,7 +171,7 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
|
||||
curs_set(0);
|
||||
} else {
|
||||
bs.curr++;
|
||||
informwin = bs.curr >= (int) bs.nbuttons ?
|
||||
informwin = bs.curr >= (int)bs.nbuttons ?
|
||||
true : false;
|
||||
if (informwin) {
|
||||
curs_set(2);
|
||||
@ -248,7 +241,7 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
|
||||
form_driver(form, REQ_DEL_PREV);
|
||||
form_driver(form, REQ_BEG_LINE);
|
||||
mf->pos = mf->pos - 1;
|
||||
for (i=0; i<mf->pos; i++)
|
||||
for (i = 0; i < mf->pos; i++)
|
||||
form_driver(form, REQ_NEXT_CHAR);
|
||||
shiftleft(mf);
|
||||
break;
|
||||
@ -262,16 +255,13 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
|
||||
if (conf->f1_file == NULL && conf->f1_message == NULL)
|
||||
break;
|
||||
if (f1help(conf) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
/* No Break */
|
||||
case KEY_RESIZE:
|
||||
output = REDRAWFORM;
|
||||
loop = false;
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
* user input, add unicode chars to "public" buffer
|
||||
*/
|
||||
if (informwin) {
|
||||
mf = GETMYFIELD2(form);
|
||||
if (mf->secure)
|
||||
@ -281,14 +271,11 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
|
||||
insertch(mf, input);
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < (int) bs.nbuttons; i++) {
|
||||
if (tolower(input) ==
|
||||
tolower((bs.label[i])[0])) {
|
||||
bs.curr = i;
|
||||
output = return_values(conf, bs,
|
||||
nitems, items, form, cfield);
|
||||
loop = false;
|
||||
}
|
||||
if (shortcut_buttons(input, &bs)) {
|
||||
output = return_values(conf,
|
||||
bs.value[bs.curr], nitems, items,
|
||||
form, cfield);
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -297,62 +284,47 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
|
||||
|
||||
curs_set(0);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static void
|
||||
form_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
|
||||
char *text, int linelen, unsigned int *formheight, int nitems,
|
||||
struct buttons bs)
|
||||
{
|
||||
int textrow, menusize;
|
||||
|
||||
textrow = text != NULL && strlen(text) > 0 ? 1 : 0;
|
||||
|
||||
if (cols == BSDDIALOG_AUTOSIZE) {
|
||||
*w = VBORDERS;
|
||||
/* buttons size */
|
||||
*w += bs.nbuttons * bs.sizebutton;
|
||||
*w += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
|
||||
/* line size */
|
||||
*w = MAX(*w, linelen + 3);
|
||||
/* conf.auto_minwidth */
|
||||
*w = MAX(*w, (int)conf->auto_minwidth);
|
||||
/*
|
||||
* avoid terminal overflow,
|
||||
* -1 fix false negative with big menu over the terminal and
|
||||
* autosize, for example "portconfig /usr/ports/www/apache24/".
|
||||
*/
|
||||
*w = MIN(*w, widget_max_width(conf)-1);
|
||||
}
|
||||
|
||||
if (rows == BSDDIALOG_AUTOSIZE) {
|
||||
*h = HBORDERS + 2 /* buttons */ + textrow;
|
||||
|
||||
if (*formheight == 0) {
|
||||
*h += nitems + 2;
|
||||
*h = MIN(*h, widget_max_height(conf));
|
||||
menusize = MIN(nitems + 2, *h - (HBORDERS + 2 + textrow));
|
||||
menusize -=2;
|
||||
*formheight = menusize < 0 ? 0 : menusize;
|
||||
}
|
||||
else /* h autosize with a fixed formheight */
|
||||
*h = *h + *formheight + 2;
|
||||
|
||||
/* conf.auto_minheight */
|
||||
*h = MAX(*h, (int)conf->auto_minheight);
|
||||
/* avoid terminal overflow */
|
||||
*h = MIN(*h, widget_max_height(conf));
|
||||
}
|
||||
else {
|
||||
if (*formheight == 0)
|
||||
*formheight = MIN(rows-6-textrow, nitems);
|
||||
}
|
||||
return (output);
|
||||
}
|
||||
|
||||
static int
|
||||
form_checksize(int rows, int cols, char *text, int formheight, int nitems,
|
||||
form_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
|
||||
const char *text, int linelen, unsigned int *formheight, int nitems,
|
||||
struct buttons bs)
|
||||
{
|
||||
int htext, wtext, menusize;
|
||||
|
||||
if (cols == BSDDIALOG_AUTOSIZE || rows == BSDDIALOG_AUTOSIZE) {
|
||||
if (text_size(conf, rows, cols, text, &bs, *formheight + 2,
|
||||
linelen + 2, &htext, &wtext) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
}
|
||||
|
||||
if (cols == BSDDIALOG_AUTOSIZE)
|
||||
*w = widget_min_width(conf, wtext, linelen + 2, &bs);
|
||||
|
||||
if (rows == BSDDIALOG_AUTOSIZE) {
|
||||
if (*formheight == 0) {
|
||||
menusize = widget_max_height(conf) - HBORDERS -
|
||||
2 /*buttons*/ - htext;
|
||||
menusize = MIN(menusize, nitems + 2);
|
||||
*formheight = menusize - 2 < 0 ? 0 : menusize - 2;
|
||||
}
|
||||
else /* h autosize with fixed formheight */
|
||||
menusize = *formheight + 2;
|
||||
|
||||
*h = widget_min_height(conf, htext, menusize, true);
|
||||
} else {
|
||||
if (*formheight == 0)
|
||||
*formheight = MIN(rows-6-htext, nitems);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
form_checksize(int rows, int cols, const char *text, int formheight, int nitems,
|
||||
unsigned int linelen, struct buttons bs)
|
||||
{
|
||||
int mincols, textrow, formrows;
|
||||
|
||||
@ -360,40 +332,39 @@ form_checksize(int rows, int cols, char *text, int formheight, int nitems,
|
||||
/* buttons */
|
||||
mincols += bs.nbuttons * bs.sizebutton;
|
||||
mincols += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
|
||||
/* line, comment to permet some cols hidden */
|
||||
/* mincols = MAX(mincols, linelen); */
|
||||
mincols = MAX(mincols, (int)linelen + 4);
|
||||
|
||||
if (cols < mincols)
|
||||
RETURN_ERROR("Few cols, width < size buttons or "\
|
||||
"labels + forms");
|
||||
RETURN_ERROR("Few cols, width < size buttons or "
|
||||
"forms (label + field)");
|
||||
|
||||
textrow = text != NULL && strlen(text) > 0 ? 1 : 0;
|
||||
|
||||
if (nitems > 0 && formheight == 0)
|
||||
RETURN_ERROR("fields > 0 but formheight == 0, probably "\
|
||||
RETURN_ERROR("fields > 0 but formheight == 0, probably "
|
||||
"terminal too small");
|
||||
|
||||
formrows = nitems > 0 ? 3 : 0;
|
||||
if (rows < 2 + 2 + formrows + textrow)
|
||||
RETURN_ERROR("Few lines for this menus");
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int formheight, unsigned int nitems,
|
||||
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, htextpad;
|
||||
int i, output, color, y, x, h, w;
|
||||
FIELD **cfield;
|
||||
FORM *form;
|
||||
struct buttons bs;
|
||||
struct myfield *myfields;
|
||||
unsigned long maxline;
|
||||
|
||||
/* disable form scrolling like dialog */
|
||||
/* disable form scrolling */
|
||||
if (formheight < nitems)
|
||||
formheight = nitems;
|
||||
|
||||
@ -409,7 +380,7 @@ bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
maxline = 0;
|
||||
myfields = malloc(nitems * sizeof(struct myfield));
|
||||
cfield = calloc(nitems + 1, sizeof(FIELD*));
|
||||
for (i=0; i < (int)nitems; i++) {
|
||||
for (i = 0; i < (int)nitems; i++) {
|
||||
cfield[i] = new_field(1, items[i].fieldlen, items[i].yfield-1,
|
||||
items[i].xfield-1, 0, 0);
|
||||
field_opts_off(cfield[i], O_STATIC);
|
||||
@ -417,7 +388,7 @@ bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
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); // end with '\0' for strdup
|
||||
memset(myfields[i].buf, 0, items[i].maxvaluelen + 1);
|
||||
strncpy(myfields[i].buf, items[i].init, items[i].maxvaluelen);
|
||||
|
||||
myfields[i].buflen = strlen(myfields[i].buf);
|
||||
@ -430,16 +401,15 @@ bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
|
||||
field_opts_off(cfield[i], O_AUTOSKIP);
|
||||
field_opts_off(cfield[i], O_BLANK);
|
||||
/* field_opts_off(field[i], O_BS_OVERLOAD); */
|
||||
|
||||
if (ISFIELDHIDDEN(items[i])) {
|
||||
/* field_opts_off(field[i], O_PUBLIC); old hidden */
|
||||
myfields[i].secure = true;
|
||||
myfields[i].securech = ' ';
|
||||
if (conf->form.securech != '\0')
|
||||
myfields[i].securech = conf->form.securech;
|
||||
}
|
||||
else myfields[i].secure = false;
|
||||
else
|
||||
myfields[i].secure = false;
|
||||
|
||||
if (ISFIELDREADONLY(items[i])) {
|
||||
field_opts_off(cfield[i], O_EDIT);
|
||||
@ -452,7 +422,7 @@ bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
set_field_back(cfield[i], color);
|
||||
|
||||
maxline = MAX(maxline, items[i].xlabel + strlen(items[i].label));
|
||||
maxline = MAX(maxline, items[i].xfield + items[i].fieldlen);
|
||||
maxline = MAX(maxline, items[i].xfield + items[i].fieldlen - 1);
|
||||
}
|
||||
cfield[i] = NULL;
|
||||
|
||||
@ -462,26 +432,26 @@ bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
set_field_fore(cfield[0], t.dialog.color);
|
||||
set_field_back(cfield[0], t.dialog.color);
|
||||
}
|
||||
|
||||
get_buttons(conf, &bs, BUTTONLABEL(ok_label), BUTTONLABEL(extra_label),
|
||||
BUTTONLABEL(cancel_label), BUTTONLABEL(help_label));
|
||||
|
||||
get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
form_autosize(conf, rows, cols, &h, &w, text, maxline, &formheight,
|
||||
nitems, bs);
|
||||
if (form_checksize(h, w, text, formheight, nitems, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (form_autosize(conf, rows, cols, &h, &w, text, maxline, &formheight,
|
||||
nitems, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (form_checksize(h, w, text, formheight, nitems, maxline, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
if (new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w, RAISED,
|
||||
&textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs,
|
||||
true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
prefresh(textpad, 0, 0, y + 1, x + 1 + TEXTHMARGIN,
|
||||
y + h - formheight, x + 1 + w - TEXTHMARGIN);
|
||||
|
||||
prefresh(textpad, 0, 0, y + 1, x + 1 + t.text.hmargin,
|
||||
y + h - formheight, x + 1 + w - t.text.hmargin);
|
||||
|
||||
formwin = new_boxed_window(conf, y + h - 3 - formheight -2, x +1,
|
||||
formheight+2, w-2, LOWERED);
|
||||
|
||||
@ -491,32 +461,35 @@ bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
set_form_sub(form, derwin(formwin, nitems, w-4, 1, 1));
|
||||
post_form(form);
|
||||
|
||||
for (i=0; i < (int)nitems; i++)
|
||||
mvwaddstr(formwin, items[i].ylabel, items[i].xlabel, items[i].label);
|
||||
for (i = 0; i < (int)nitems; i++)
|
||||
mvwaddstr(formwin, items[i].ylabel, items[i].xlabel,
|
||||
items[i].label);
|
||||
|
||||
wrefresh(formwin);
|
||||
|
||||
do {
|
||||
output = form_handler(conf, widget, h-2, w, bs, formwin, form,
|
||||
cfield, nitems, items);
|
||||
output = form_handler(conf, widget, bs, formwin, form, cfield,
|
||||
nitems, items);
|
||||
|
||||
if(update_widget_withtextpad(conf, shadow, widget, h, w,
|
||||
RAISED, textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
if (update_dialog(conf, shadow, widget, y, x, h, w, textpad,
|
||||
text, &bs, true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
doupdate();
|
||||
wrefresh(widget);
|
||||
|
||||
prefresh(textpad, 0, 0, y + 1, x + 1 + t.text.hmargin,
|
||||
y + h - formheight, x + 1 + w - t.text.hmargin);
|
||||
prefresh(textpad, 0, 0, y + 1, x + 1 + TEXTHMARGIN,
|
||||
y + h - formheight, x + 1 + w - TEXTHMARGIN);
|
||||
|
||||
draw_borders(conf, formwin, formheight+2, w-2, LOWERED);
|
||||
/* wrefresh(formwin); */
|
||||
wrefresh(formwin);
|
||||
|
||||
refresh();
|
||||
} while (output == REDRAWFORM);
|
||||
|
||||
unpost_form(form);
|
||||
free_form(form);
|
||||
for (i=0; i < (int)nitems; i++) {
|
||||
for (i = 0; i < (int)nitems; i++) {
|
||||
free_field(cfield[i]);
|
||||
free(myfields[i].buf);
|
||||
}
|
||||
@ -524,7 +497,7 @@ bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
free(myfields);
|
||||
|
||||
delwin(formwin);
|
||||
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
|
||||
end_dialog(conf, shadow, widget, textpad);
|
||||
|
||||
return output;
|
||||
}
|
||||
return (output);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -27,92 +27,73 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#ifdef PORTNCURSES
|
||||
#include <ncurses/ncurses.h>
|
||||
#else
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <curses.h>
|
||||
|
||||
#include "bsddialog.h"
|
||||
#include "lib_util.h"
|
||||
#include "bsddialog_theme.h"
|
||||
|
||||
/* "Info": infobox */
|
||||
|
||||
#define MIN_HEIGHT 3
|
||||
#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,
|
||||
char *text)
|
||||
infobox_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h,
|
||||
int *w, const char *text)
|
||||
{
|
||||
int maxword, maxline, nlines;
|
||||
int htext, wtext;
|
||||
|
||||
if (get_text_properties(conf, text, &maxword, &maxline, &nlines) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
if (cols == BSDDIALOG_AUTOSIZE) {
|
||||
/* text size */
|
||||
*w = maxline + VBORDERS + t.text.hmargin * 2;
|
||||
/* conf.auto_minwidth */
|
||||
*w = MAX(*w, (int)conf->auto_minwidth);
|
||||
/* avoid terminal overflow */
|
||||
*w = MIN(*w, widget_max_width(conf));
|
||||
if (cols == BSDDIALOG_AUTOSIZE || rows == BSDDIALOG_AUTOSIZE) {
|
||||
if (text_size(conf, rows, cols, text, NULL, 0, SCREENCOLS/2,
|
||||
&htext, &wtext) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
}
|
||||
|
||||
if (rows == BSDDIALOG_AUTOSIZE) {
|
||||
*h = MIN_HEIGHT - 1;
|
||||
if (maxword > 0)
|
||||
*h += MIN(nlines, (int)(*w / GET_ASPECT_RATIO(conf)));
|
||||
*h = MAX(*h, MIN_HEIGHT);
|
||||
/* conf.auto_minheight */
|
||||
*h = MAX(*h, (int)conf->auto_minheight);
|
||||
/* avoid terminal overflow */
|
||||
*h = MIN(*h, widget_max_height(conf));
|
||||
}
|
||||
if (cols == BSDDIALOG_AUTOSIZE)
|
||||
*w = widget_min_width(conf, wtext, 0, NULL);
|
||||
|
||||
return 0;
|
||||
if (rows == BSDDIALOG_AUTOSIZE)
|
||||
*h = widget_min_height(conf, htext, 0, false);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int infobox_checksize(int rows, int cols)
|
||||
{
|
||||
if (cols < HBORDERS)
|
||||
RETURN_ERROR("Few cols, infobox needs at least width 2");
|
||||
|
||||
if (cols < HBORDERS + 1 + (int) t.text.hmargin * 2)
|
||||
RETURN_ERROR("Few cols, infobox needs at least width 3 + text "\
|
||||
"margins");
|
||||
if (rows < VBORDERS)
|
||||
RETURN_ERROR("Infobox needs at least height 2");
|
||||
|
||||
if (rows < 3)
|
||||
RETURN_ERROR("Infobox needs at least height 3");
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* API */
|
||||
int
|
||||
bsddialog_infobox(struct bsddialog_conf *conf, char* text, int rows, int cols)
|
||||
bsddialog_infobox(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols)
|
||||
{
|
||||
int y, x, h, w;
|
||||
WINDOW *shadow, *widget, *textpad;
|
||||
int y, x, h, w, htextpad;
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (infobox_autosize(conf, rows, cols, &h, &w, text) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (infobox_checksize(h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
if (new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w, RAISED,
|
||||
&textpad, &htextpad, text, false) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text,
|
||||
NULL, false) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
pnoutrefresh(textpad, 0, 0, y+1, x+1+t.text.hmargin, y+h-2, x+w-t.text.hmargin);
|
||||
pnoutrefresh(textpad, 0, 0, y+1, x+1+TEXTHMARGIN, y+h-2,
|
||||
x+w-TEXTHMARGIN);
|
||||
|
||||
doupdate();
|
||||
|
||||
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
|
||||
end_dialog(conf, shadow, widget, textpad);
|
||||
|
||||
return (BSDDIALOG_OK);
|
||||
}
|
||||
|
||||
}
|
751
lib/lib_util.c
751
lib/lib_util.c
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -28,21 +28,10 @@
|
||||
#ifndef _LIBBSDDIALOG_UTIL_H_
|
||||
#define _LIBBSDDIALOG_UTIL_H_
|
||||
|
||||
/*
|
||||
* Utils to implement widgets - Internal library API - Dafult values
|
||||
*/
|
||||
|
||||
#define HBORDER 1
|
||||
#define HBORDERS (HBORDER + HBORDER)
|
||||
#define VBORDER 1
|
||||
#define VBORDERS (VBORDER + VBORDER)
|
||||
#define PADDING(p) (p)
|
||||
|
||||
/* ncurses has not a Ctrl key macro */
|
||||
#define KEY_CTRL(x) ((x) & 0x1f)
|
||||
|
||||
/* Set default aspect ratio to 9 */
|
||||
#define GET_ASPECT_RATIO(conf) (conf->aspect_ratio > 0 ? conf->aspect_ratio : 9)
|
||||
#define HBORDERS 2
|
||||
#define VBORDERS 2
|
||||
#define TEXTHMARGIN 1
|
||||
#define TEXTHMARGINS (TEXTHMARGIN + TEXTHMARGIN)
|
||||
|
||||
/* debug */
|
||||
#define BSDDIALOG_DEBUG(y,x,fmt, ...) do { \
|
||||
@ -56,36 +45,29 @@ void set_error_string(char *string);
|
||||
|
||||
#define RETURN_ERROR(str) do { \
|
||||
set_error_string(str); \
|
||||
return BSDDIALOG_ERROR; \
|
||||
return (BSDDIALOG_ERROR); \
|
||||
} while (0)
|
||||
|
||||
/* Buttons */
|
||||
#define LABEL_cancel_label "Cancel"
|
||||
#define LABEL_exit_label "EXIT"
|
||||
#define LABEL_extra_label "Extra"
|
||||
#define LABEL_help_label "Help"
|
||||
#define LABEL_ok_label "OK"
|
||||
#define BUTTONLABEL(l) (conf->button.l != NULL ? conf->button.l : LABEL_ ##l)
|
||||
|
||||
#define MAXBUTTONS 6 /* yes|ok + extra + no|cancel + help + 2 generics */
|
||||
/* buttons */
|
||||
struct buttons {
|
||||
unsigned int nbuttons;
|
||||
char *label[MAXBUTTONS];
|
||||
#define MAXBUTTONS 6 /* ok + extra + cancel + help + 2 generics */
|
||||
const char *label[MAXBUTTONS];
|
||||
int value[MAXBUTTONS];
|
||||
int curr;
|
||||
unsigned int sizebutton; /* including left and right delimiters */
|
||||
};
|
||||
|
||||
#define BUTTON_OK_LABEL "OK"
|
||||
#define BUTTON_CANCEL_LABEL "Cancel"
|
||||
void
|
||||
get_buttons(struct bsddialog_conf *conf, struct buttons *bs, char *yesoklabel,
|
||||
char *extralabel, char *nocancellabel, char *helplabel);
|
||||
char *nocancellabel);
|
||||
|
||||
void
|
||||
draw_button(WINDOW *window, int y, int x, int size, char *text, bool selected,
|
||||
bool shortkey);
|
||||
draw_buttons(WINDOW *window, struct buttons bs, bool shortcut);
|
||||
|
||||
void
|
||||
draw_buttons(WINDOW *window, int y, int cols, struct buttons bs, bool shortkey);
|
||||
bool shortcut_buttons(int key, struct buttons *bs);
|
||||
|
||||
/* help window with F1 key */
|
||||
int f1help(struct bsddialog_conf *conf);
|
||||
@ -94,24 +76,32 @@ int f1help(struct bsddialog_conf *conf);
|
||||
int hide_widget(int y, int x, int h, int w, bool withshadow);
|
||||
|
||||
/* (auto) size and (auto) position */
|
||||
#define SCREENLINES (getmaxy(stdscr))
|
||||
#define SCREENCOLS (getmaxx(stdscr))
|
||||
|
||||
int
|
||||
get_text_properties(struct bsddialog_conf *conf, char *text, int *maxword,
|
||||
int *maxline, int *nlines);
|
||||
text_size(struct bsddialog_conf *conf, int rows, int cols, const char *text,
|
||||
struct buttons *bs, int rowsnotext, int startwtext, int *htext, int *wtext);
|
||||
|
||||
int widget_max_height(struct bsddialog_conf *conf);
|
||||
int widget_max_width(struct bsddialog_conf *conf);
|
||||
|
||||
int
|
||||
set_widget_size(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w);
|
||||
widget_min_height(struct bsddialog_conf *conf, int htext, int minwidget,
|
||||
bool withbuttons);
|
||||
|
||||
int
|
||||
widget_min_width(struct bsddialog_conf *conf, int wtext, int minwidget,
|
||||
struct buttons *bs);
|
||||
|
||||
int
|
||||
set_widget_size(struct bsddialog_conf *conf, int rows, int cols, int *h,
|
||||
int *w);
|
||||
|
||||
int
|
||||
set_widget_position(struct bsddialog_conf *conf, int *y, int *x, int h, int w);
|
||||
|
||||
/* widget builders */
|
||||
int
|
||||
print_textpad(struct bsddialog_conf *conf, WINDOW *pad, int *rows, int cols,
|
||||
char *text);
|
||||
|
||||
enum elevation { RAISED, LOWERED };
|
||||
|
||||
void
|
||||
@ -123,17 +113,17 @@ new_boxed_window(struct bsddialog_conf *conf, int y, int x, int rows, int cols,
|
||||
enum elevation elev);
|
||||
|
||||
int
|
||||
new_widget_withtextpad(struct bsddialog_conf *conf, WINDOW **shadow,
|
||||
WINDOW **widget, int y, int x, int h, int w, enum elevation elev,
|
||||
WINDOW **textpad, int *htextpad, char *text, bool buttons);
|
||||
new_dialog(struct bsddialog_conf *conf, WINDOW **shadow, WINDOW **widget, int y,
|
||||
int x, int h, int w, WINDOW **textpad, const char *text, struct buttons *bs,
|
||||
bool shortcutbuttons);
|
||||
|
||||
int
|
||||
update_widget_withtextpad(struct bsddialog_conf *conf, WINDOW *shadow,
|
||||
WINDOW *widget, int h, int w, enum elevation elev, WINDOW *textpad,
|
||||
int *htextpad, char *text, bool buttons);
|
||||
update_dialog(struct bsddialog_conf *conf, WINDOW *shadow, WINDOW *widget,
|
||||
int y, int x, int h, int w, WINDOW *textpad, const char *text,
|
||||
struct buttons *bs, bool shortcutbuttons);
|
||||
|
||||
void
|
||||
end_widget_withtextpad(struct bsddialog_conf *conf, WINDOW *window, int h, int w,
|
||||
WINDOW *textpad, WINDOW *shadow);
|
||||
end_dialog(struct bsddialog_conf *conf, WINDOW *shadow, WINDOW *widget,
|
||||
WINDOW *textpad);
|
||||
|
||||
#endif
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -25,43 +25,26 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef PORTNCURSES
|
||||
#include <ncurses/ncurses.h>
|
||||
#else
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <curses.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "bsddialog.h"
|
||||
#include "lib_util.h"
|
||||
#include "bsddialog_theme.h"
|
||||
|
||||
/*
|
||||
* This file implements public functions not related to a specific dialog.
|
||||
* lib_utils.h/c: private functions to implement the library.
|
||||
* theme.h/c: public API related to themes.
|
||||
* Dialogs implementation:
|
||||
* infobox.c infobox
|
||||
* messgebox.c msgbox - yesno
|
||||
* menubox.c buildlist - checklist - menu - mixedlist - radiolist
|
||||
* formbox.c inputbox - passwordbox - form - passwordform - mixedform
|
||||
* barbox.c gauge - mixedgauge - rangebox - pause - progressview
|
||||
* textbox.c textbox
|
||||
* timebox.c timebox - calendar
|
||||
*/
|
||||
#include "lib_util.h"
|
||||
|
||||
extern struct bsddialog_theme t;
|
||||
|
||||
int bsddialog_init(void)
|
||||
{
|
||||
int i, j, c, error;
|
||||
enum bsddialog_default_theme theme;
|
||||
|
||||
set_error_string("");
|
||||
|
||||
if(initscr() == NULL)
|
||||
RETURN_ERROR("Cannot init ncurses (initscr)");
|
||||
if (initscr() == NULL)
|
||||
RETURN_ERROR("Cannot init curses (initscr)");
|
||||
|
||||
error = OK;
|
||||
error += keypad(stdscr, TRUE);
|
||||
@ -69,24 +52,25 @@ int bsddialog_init(void)
|
||||
error += cbreak();
|
||||
error += noecho();
|
||||
curs_set(0);
|
||||
if(error != OK) {
|
||||
if (error != OK) {
|
||||
bsddialog_end();
|
||||
RETURN_ERROR("Cannot init ncurses (keypad and cursor)");
|
||||
RETURN_ERROR("Cannot init curses (keypad and cursor)");
|
||||
}
|
||||
|
||||
c = 1;
|
||||
error += start_color();
|
||||
for (i=0; i<8; i++)
|
||||
for(j=0; j<8; j++) {
|
||||
for (i = 0; i < 8; i++)
|
||||
for (j = 0; j < 8; j++) {
|
||||
error += init_pair(c, i, j);
|
||||
c++;
|
||||
}
|
||||
if(error != OK) {
|
||||
bsddialog_end();
|
||||
RETURN_ERROR("Cannot init ncurses (colors)");
|
||||
}
|
||||
|
||||
if (bsddialog_set_default_theme(BSDDIALOG_THEME_DEFAULT) != 0) {
|
||||
if (error == OK)
|
||||
theme = BSDDIALOG_THEME_DEFAULT;
|
||||
else
|
||||
theme = BSDDIALOG_THEME_BLACKWHITE;
|
||||
|
||||
if (bsddialog_set_default_theme(theme) != 0) {
|
||||
bsddialog_end();
|
||||
return (BSDDIALOG_ERROR);
|
||||
}
|
||||
@ -97,16 +81,17 @@ int bsddialog_init(void)
|
||||
int bsddialog_end(void)
|
||||
{
|
||||
if (endwin() != OK)
|
||||
RETURN_ERROR("Cannot end ncurses (endwin)");
|
||||
RETURN_ERROR("Cannot end curses (endwin)");
|
||||
|
||||
return (BSDDIALOG_OK);
|
||||
}
|
||||
|
||||
int bsddialog_backtitle(struct bsddialog_conf *conf, char *backtitle)
|
||||
int bsddialog_backtitle(struct bsddialog_conf *conf, const char *backtitle)
|
||||
{
|
||||
mvaddstr(0, 1, backtitle);
|
||||
if (conf->no_lines != true)
|
||||
mvhline(1, 1, conf->ascii_lines ? '-' : ACS_HLINE, COLS-2);
|
||||
mvhline(1, 1, conf->ascii_lines ? '-' : ACS_HLINE,
|
||||
SCREENCOLS - 2);
|
||||
|
||||
refresh();
|
||||
|
||||
@ -140,4 +125,4 @@ int bsddialog_clearterminal(void)
|
||||
refresh();
|
||||
|
||||
return (BSDDIALOG_OK);
|
||||
}
|
||||
}
|
1095
lib/menubox.c
1095
lib/menubox.c
File diff suppressed because it is too large
Load Diff
235
lib/messagebox.c
235
lib/messagebox.c
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -27,60 +27,34 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#ifdef PORTNCURSES
|
||||
#include <ncurses/ncurses.h>
|
||||
#else
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bsddialog.h"
|
||||
#include "lib_util.h"
|
||||
#include "bsddialog_theme.h"
|
||||
|
||||
#define AUTO_WIDTH (COLS / 3U)
|
||||
/* at least 1 line text for its pad building in widget_withtextpad_init() */
|
||||
#define MIN_HEIGHT (HBORDERS + 2 /*buttons*/ + 1 /*text*/)
|
||||
#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, char *text, struct buttons bs)
|
||||
int *w, const char *text, struct buttons bs)
|
||||
{
|
||||
int maxword, maxline, nlines, line;
|
||||
int htext, wtext;
|
||||
|
||||
if (get_text_properties(conf, text, &maxword, &maxline, &nlines) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
if (cols == BSDDIALOG_AUTOSIZE) {
|
||||
*w = VBORDERS;
|
||||
/* buttons size */
|
||||
*w += bs.nbuttons * bs.sizebutton;
|
||||
*w += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
|
||||
/* text size */
|
||||
line = MIN(maxline + VBORDERS + t.text.hmargin * 2, AUTO_WIDTH);
|
||||
line = MAX(line, (int) (maxword + VBORDERS + t.text.hmargin * 2));
|
||||
*w = MAX(*w, line);
|
||||
/* conf.auto_minwidth */
|
||||
*w = MAX(*w, (int)conf->auto_minwidth);
|
||||
/* avoid terminal overflow */
|
||||
*w = MIN(*w, widget_max_width(conf));
|
||||
if (cols == BSDDIALOG_AUTOSIZE || rows == BSDDIALOG_AUTOSIZE) {
|
||||
if (text_size(conf, rows, cols, text, &bs, 0, SCREENCOLS/2,
|
||||
&htext, &wtext) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
}
|
||||
|
||||
if (rows == BSDDIALOG_AUTOSIZE) {
|
||||
*h = MIN_HEIGHT - 1;
|
||||
if (maxword > 0)
|
||||
*h += MAX(nlines, (int)(*w / GET_ASPECT_RATIO(conf)));
|
||||
*h = MAX(*h, MIN_HEIGHT);
|
||||
/* conf.auto_minheight */
|
||||
*h = MAX(*h, (int)conf->auto_minheight);
|
||||
/* avoid terminal overflow */
|
||||
*h = MIN(*h, widget_max_height(conf));
|
||||
}
|
||||
if (cols == BSDDIALOG_AUTOSIZE)
|
||||
*w = widget_min_width(conf, wtext, 0, &bs);
|
||||
|
||||
return 0;
|
||||
if (rows == BSDDIALOG_AUTOSIZE)
|
||||
*h = widget_min_height(conf, htext, 0, true);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int message_checksize(int rows, int cols, struct buttons bs)
|
||||
@ -92,182 +66,167 @@ static int message_checksize(int rows, int cols, struct buttons bs)
|
||||
mincols += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
|
||||
|
||||
if (cols < mincols)
|
||||
RETURN_ERROR("Few cols, Msgbox and Yesno need at least width "\
|
||||
RETURN_ERROR("Few cols, Msgbox and Yesno need at least width "
|
||||
"for borders, buttons and spaces between buttons");
|
||||
|
||||
if (rows < MIN_HEIGHT)
|
||||
RETURN_ERROR("Msgbox and Yesno need at least height 5");
|
||||
if (rows < HBORDERS + 2 /*buttons*/)
|
||||
RETURN_ERROR("Msgbox and Yesno need at least height 4");
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
buttonsupdate(WINDOW *widget, int h, int w, struct buttons bs)
|
||||
textupdate(WINDOW *widget, WINDOW *textpad, int htextpad, int ytextpad)
|
||||
{
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
wnoutrefresh(widget);
|
||||
}
|
||||
int y, x, h, w;
|
||||
|
||||
getbegyx(widget, y, x);
|
||||
getmaxyx(widget, h, w);
|
||||
|
||||
static void
|
||||
textupdate(WINDOW *widget, int y, int x, int h, int w, WINDOW *textpad,
|
||||
int htextpad, int textrow)
|
||||
{
|
||||
if (htextpad > h - 4) {
|
||||
mvwprintw(widget, h-3, w-6, "%3d%%",
|
||||
100 * (textrow+h-4)/ htextpad);
|
||||
100 * (ytextpad+h-4)/ htextpad);
|
||||
wnoutrefresh(widget);
|
||||
}
|
||||
|
||||
pnoutrefresh(textpad, textrow, 0, y+1, x+2, y+h-4, x+w-2);
|
||||
pnoutrefresh(textpad, ytextpad, 0, y+1, x+2, y+h-4, x+w-2);
|
||||
}
|
||||
|
||||
static int
|
||||
do_dialog(struct bsddialog_conf *conf, char *text, int rows, int cols,
|
||||
do_message(struct bsddialog_conf *conf, const char *text, int rows, int cols,
|
||||
struct buttons bs)
|
||||
{
|
||||
WINDOW *widget, *textpad, *shadow;
|
||||
bool loop;
|
||||
int i, y, x, h, w, input, output, htextpad, textrow;
|
||||
int y, x, h, w, input, output, ytextpad, htextpad, unused;
|
||||
WINDOW *widget, *textpad, *shadow;
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (message_autosize(conf, rows, cols, &h, &w, text, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (message_checksize(h, w, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
if (new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w, RAISED,
|
||||
&textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs,
|
||||
true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
textrow = 0;
|
||||
ytextpad = 0;
|
||||
getmaxyx(textpad, htextpad, unused);
|
||||
unused++; /* fix unused error */
|
||||
textupdate(widget, textpad, htextpad, ytextpad);
|
||||
loop = true;
|
||||
buttonsupdate(widget, h, w, bs);
|
||||
textupdate(widget, y, x, h, w, textpad, htextpad, textrow);
|
||||
while(loop) {
|
||||
while (loop) {
|
||||
doupdate();
|
||||
input = getch();
|
||||
switch (input) {
|
||||
case KEY_ENTER:
|
||||
case 10: /* Enter */
|
||||
output = bs.value[bs.curr];
|
||||
loop = false;
|
||||
break;
|
||||
case 27: /* Esc */
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
if (conf->key.enable_esc) {
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
}
|
||||
break;
|
||||
case '\t': /* TAB */
|
||||
bs.curr = (bs.curr + 1) % bs.nbuttons;
|
||||
buttonsupdate(widget, h, w, bs);
|
||||
draw_buttons(widget, bs, true);
|
||||
wnoutrefresh(widget);
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if (bs.curr > 0) {
|
||||
bs.curr--;
|
||||
draw_buttons(widget, bs, true);
|
||||
wnoutrefresh(widget);
|
||||
}
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
if (bs.curr < (int)bs.nbuttons - 1) {
|
||||
bs.curr++;
|
||||
draw_buttons(widget, bs, true);
|
||||
wnoutrefresh(widget);
|
||||
}
|
||||
break;
|
||||
case KEY_F(1):
|
||||
if (conf->f1_file == NULL && conf->f1_message == NULL)
|
||||
break;
|
||||
if (f1help(conf) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
/* No break! the terminal size can change */
|
||||
return (BSDDIALOG_ERROR);
|
||||
/* No break, screen size can change */
|
||||
case KEY_RESIZE:
|
||||
hide_widget(y, x, h, w,conf->shadow);
|
||||
|
||||
/*
|
||||
* Unnecessary, but, when the columns decrease the
|
||||
* following "refresh" seem not work
|
||||
*/
|
||||
/* Important for decreasing screen */
|
||||
hide_widget(y, x, h, w, conf->shadow);
|
||||
refresh();
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (message_autosize(conf, rows, cols, &h, &w, text, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (message_autosize(conf, rows, cols, &h, &w, text,
|
||||
bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (message_checksize(h, w, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
wclear(shadow);
|
||||
mvwin(shadow, y + t.shadow.h, x + t.shadow.w);
|
||||
wresize(shadow, h, w);
|
||||
if (update_dialog(conf, shadow, widget, y, x, h, w,
|
||||
textpad, text, &bs, true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
wclear(widget);
|
||||
mvwin(widget, y, x);
|
||||
wresize(widget, h, w);
|
||||
|
||||
htextpad = 1;
|
||||
wclear(textpad);
|
||||
wresize(textpad, 1, w - HBORDERS - t.text.hmargin * 2);
|
||||
|
||||
if(update_widget_withtextpad(conf, shadow, widget, h, w,
|
||||
RAISED, textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
buttonsupdate(widget, h, w, bs);
|
||||
textupdate(widget, y, x, h, w, textpad, htextpad, textrow);
|
||||
getmaxyx(textpad, htextpad, unused);
|
||||
textupdate(widget, textpad, htextpad, ytextpad);
|
||||
|
||||
/* Important to fix grey lines expanding screen */
|
||||
refresh();
|
||||
break;
|
||||
case KEY_UP:
|
||||
if (textrow == 0)
|
||||
if (ytextpad == 0)
|
||||
break;
|
||||
textrow--;
|
||||
textupdate(widget, y, x, h, w, textpad, htextpad, textrow);
|
||||
ytextpad--;
|
||||
textupdate(widget, textpad, htextpad, ytextpad);
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
if (textrow + h - 4 >= htextpad)
|
||||
if (ytextpad + h - 4 >= htextpad)
|
||||
break;
|
||||
textrow++;
|
||||
textupdate(widget, y, x, h, w, textpad, htextpad, textrow);
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if (bs.curr > 0) {
|
||||
bs.curr--;
|
||||
buttonsupdate(widget, h, w, bs);
|
||||
}
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
if (bs.curr < (int) bs.nbuttons - 1) {
|
||||
bs.curr++;
|
||||
buttonsupdate(widget, h, w, bs);
|
||||
}
|
||||
ytextpad++;
|
||||
textupdate(widget, textpad, htextpad, ytextpad);
|
||||
break;
|
||||
default:
|
||||
for (i = 0; i < (int) bs.nbuttons; i++)
|
||||
if (tolower(input) == tolower(bs.label[i][0])) {
|
||||
output = bs.value[i];
|
||||
loop = false;
|
||||
if (shortcut_buttons(input, &bs)) {
|
||||
output = bs.value[bs.curr];
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
|
||||
end_dialog(conf, shadow, widget, textpad);
|
||||
|
||||
return output;
|
||||
return (output);
|
||||
}
|
||||
|
||||
/* API */
|
||||
int
|
||||
bsddialog_msgbox(struct bsddialog_conf *conf, char* text, int rows, int cols)
|
||||
bsddialog_msgbox(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols)
|
||||
{
|
||||
struct buttons bs;
|
||||
|
||||
get_buttons(conf, &bs, BUTTONLABEL(ok_label), BUTTONLABEL(extra_label),
|
||||
NULL, BUTTONLABEL(help_label));
|
||||
get_buttons(conf, &bs, BUTTON_OK_LABEL, NULL);
|
||||
|
||||
return (do_dialog(conf, text, rows, cols, bs));
|
||||
return (do_message(conf, text, rows, cols, bs));
|
||||
}
|
||||
|
||||
int
|
||||
bsddialog_yesno(struct bsddialog_conf *conf, char* text, int rows, int cols)
|
||||
bsddialog_yesno(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols)
|
||||
{
|
||||
struct buttons bs;
|
||||
|
||||
get_buttons(conf, &bs,
|
||||
conf->button.ok_label == NULL ? "Yes" : conf->button.ok_label,
|
||||
BUTTONLABEL(extra_label),
|
||||
conf->button.cancel_label == NULL ? "No" : conf->button.cancel_label,
|
||||
BUTTONLABEL(help_label));
|
||||
get_buttons(conf, &bs, "Yes", "No");
|
||||
|
||||
return (do_dialog(conf, text, rows, cols, bs));
|
||||
}
|
||||
return (do_message(conf, text, rows, cols, bs));
|
||||
}
|
164
lib/textbox.c
164
lib/textbox.c
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -25,57 +25,34 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#ifdef PORTNCURSES
|
||||
#include <ncurses/ncurses.h>
|
||||
#else
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bsddialog.h"
|
||||
#include "lib_util.h"
|
||||
#include "bsddialog_theme.h"
|
||||
|
||||
/* "Text": textbox */
|
||||
|
||||
#define BUTTON_TEXTBOX "EXIT"
|
||||
#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)
|
||||
textbox_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h,
|
||||
int *w, int hpad, int wpad, struct buttons bs)
|
||||
{
|
||||
if (cols == BSDDIALOG_AUTOSIZE)
|
||||
*w = widget_min_width(conf, 0, wpad, &bs);
|
||||
|
||||
if (cols == BSDDIALOG_AUTOSIZE) {
|
||||
*w = VBORDERS;
|
||||
/* buttons size */
|
||||
*w += strlen(BUTTON_TEXTBOX) + 2 /* text delims*/;
|
||||
/* text size */
|
||||
*w = MAX(*w, wpad + VBORDERS);
|
||||
/* conf.auto_minwidth */
|
||||
*w = MAX(*w, (int)conf->auto_minwidth);
|
||||
/* avoid terminal overflow */
|
||||
*w = MIN(*w, widget_max_width(conf)-1); /* again -1, fix util.c */
|
||||
}
|
||||
|
||||
if (rows == BSDDIALOG_AUTOSIZE) {
|
||||
*h = hpad + 4; /* HBORDERS + button border */
|
||||
/* conf.auto_minheight */
|
||||
*h = MAX(*h, (int)conf->auto_minheight);
|
||||
/* avoid terminal overflow */
|
||||
*h = MIN(*h, widget_max_height(conf));
|
||||
}
|
||||
if (rows == BSDDIALOG_AUTOSIZE)
|
||||
*h = widget_min_height(conf, 0, hpad, true);
|
||||
}
|
||||
|
||||
static int textbox_checksize(int rows, int cols, int hpad)
|
||||
static int
|
||||
textbox_checksize(int rows, int cols, int hpad, struct buttons bs)
|
||||
{
|
||||
int mincols;
|
||||
|
||||
mincols = VBORDERS + strlen(BUTTON_TEXTBOX) + 2 /* text delims */;
|
||||
mincols = VBORDERS + bs.sizebutton;
|
||||
|
||||
if (cols < mincols)
|
||||
RETURN_ERROR("Few cols for the textbox");
|
||||
@ -83,18 +60,21 @@ static int textbox_checksize(int rows, int cols, int hpad)
|
||||
if (rows < 4 /* HBORDERS + button*/ + (hpad > 0 ? 1 : 0))
|
||||
RETURN_ERROR("Few rows for the textbox");
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* API */
|
||||
int
|
||||
bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
|
||||
bsddialog_textbox(struct bsddialog_conf *conf, const char* file, int rows,
|
||||
int cols)
|
||||
{
|
||||
WINDOW *widget, *pad, *shadow;
|
||||
int i, input, y, x, h, w, hpad, wpad, ypad, xpad, ys, ye, xs, xe, printrows;
|
||||
char buf[BUFSIZ], *exitbutt;
|
||||
FILE *fp;
|
||||
bool loop;
|
||||
int output;
|
||||
int i, output, input;
|
||||
int y, x, h, w, hpad, wpad, ypad, xpad, ys, ye, xs, xe, printrows;
|
||||
char buf[BUFSIZ];
|
||||
FILE *fp;
|
||||
struct buttons bs;
|
||||
WINDOW *shadow, *widget, *pad;
|
||||
|
||||
if ((fp = fopen(file, "r")) == NULL)
|
||||
RETURN_ERROR("Cannot open file");
|
||||
@ -104,7 +84,7 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
|
||||
pad = newpad(hpad, wpad);
|
||||
wbkgd(pad, t.dialog.color);
|
||||
i = 0;
|
||||
while(fgets(buf, BUFSIZ, fp) != NULL) {
|
||||
while (fgets(buf, BUFSIZ, fp) != NULL) {
|
||||
if ((int) strlen(buf) > wpad) {
|
||||
wpad = strlen(buf);
|
||||
wresize(pad, hpad, wpad);
|
||||
@ -118,23 +98,25 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
bs.nbuttons = 1;
|
||||
bs.label[0] = "EXIT";
|
||||
if (conf->button.ok_label != NULL)
|
||||
bs.label[0] = conf->button.ok_label;
|
||||
bs.value[0] = BSDDIALOG_OK;
|
||||
bs.curr = 0;
|
||||
bs.sizebutton = strlen(bs.label[0]) + 2;
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
textbox_autosize(conf, rows, cols, &h, &w, hpad, wpad);
|
||||
if (textbox_checksize(h, w, hpad) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
textbox_autosize(conf, rows, cols, &h, &w, hpad, wpad, bs);
|
||||
if (textbox_checksize(h, w, hpad, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
if (new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w, RAISED,
|
||||
NULL, NULL, NULL, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
exitbutt = conf->button.exit_label == NULL ? BUTTON_TEXTBOX : conf->button.exit_label;
|
||||
draw_button(widget, h-2, (w-2)/2 - strlen(exitbutt)/2, strlen(exitbutt)+2,
|
||||
exitbutt, true, false);
|
||||
|
||||
wrefresh(widget);
|
||||
if (new_dialog(conf, &shadow, &widget, y, x, h, w, NULL, NULL, &bs,
|
||||
true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
ys = y + 1;
|
||||
xs = x + 1;
|
||||
@ -143,8 +125,10 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
|
||||
ypad = xpad = 0;
|
||||
printrows = h-4;
|
||||
loop = true;
|
||||
while(loop) {
|
||||
prefresh(pad, ypad, xpad, ys, xs, ye, xe);
|
||||
while (loop) {
|
||||
wnoutrefresh(widget);
|
||||
pnoutrefresh(pad, ypad, xpad, ys, xs, ye, xe);
|
||||
doupdate();
|
||||
input = getch();
|
||||
switch(input) {
|
||||
case KEY_ENTER:
|
||||
@ -153,8 +137,10 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
|
||||
loop = false;
|
||||
break;
|
||||
case 27: /* Esc */
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
if (conf->key.enable_esc) {
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
}
|
||||
break;
|
||||
case KEY_HOME:
|
||||
ypad = 0;
|
||||
@ -169,7 +155,8 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
|
||||
break;
|
||||
case KEY_NPAGE:
|
||||
ypad += printrows;
|
||||
ypad = ypad + printrows > hpad ? hpad - printrows : ypad;
|
||||
if (ypad + printrows > hpad)
|
||||
ypad = hpad - printrows;
|
||||
break;
|
||||
case '0':
|
||||
xpad = 0;
|
||||
@ -193,32 +180,21 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
|
||||
if (conf->f1_file == NULL && conf->f1_message == NULL)
|
||||
break;
|
||||
if (f1help(conf) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
/* No break! the terminal size can change */
|
||||
return (BSDDIALOG_ERROR);
|
||||
/* No break, screen size can change */
|
||||
case KEY_RESIZE:
|
||||
hide_widget(y, x, h, w,conf->shadow);
|
||||
|
||||
/*
|
||||
* Unnecessary, but, when the columns decrease the
|
||||
* following "refresh" seem not work
|
||||
*/
|
||||
/* Important for decreasing screen */
|
||||
hide_widget(y, x, h, w, conf->shadow);
|
||||
refresh();
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
textbox_autosize(conf, rows, cols, &h, &w, hpad, wpad);
|
||||
if (textbox_checksize(h, w, hpad) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
textbox_autosize(conf, rows, cols, &h, &w, hpad, wpad,
|
||||
bs);
|
||||
if (textbox_checksize(h, w, hpad, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
wclear(shadow);
|
||||
mvwin(shadow, y + t.shadow.h, x + t.shadow.w);
|
||||
wresize(shadow, h, w);
|
||||
|
||||
wclear(widget);
|
||||
mvwin(widget, y, x);
|
||||
wresize(widget, h, w);
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
ys = y + 1;
|
||||
xs = x + 1;
|
||||
@ -227,22 +203,22 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
|
||||
ypad = xpad = 0;
|
||||
printrows = h - 4;
|
||||
|
||||
if(update_widget_withtextpad(conf, shadow, widget, h, w,
|
||||
RAISED, NULL, NULL, NULL, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
draw_button(widget, h-2, (w-2)/2 - strlen(exitbutt)/2,
|
||||
strlen(exitbutt)+2, exitbutt, true, false);
|
||||
|
||||
wrefresh(widget); /* for button */
|
||||
if (update_dialog(conf, shadow, widget, y, x, h, w,
|
||||
NULL, NULL, &bs, true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
/* Important to fix grey lines expanding screen */
|
||||
refresh();
|
||||
break;
|
||||
default:
|
||||
if (shortcut_buttons(input, &bs)) {
|
||||
output = bs.value[bs.curr];
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end_widget_withtextpad(conf, widget, h, w, pad, shadow);
|
||||
end_dialog(conf, shadow, widget, pad);
|
||||
|
||||
return output;
|
||||
}
|
||||
return (output);
|
||||
}
|
48
lib/theme.c
48
lib/theme.c
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -25,15 +25,11 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef PORTNCURSES
|
||||
#include <ncurses/ncurses.h>
|
||||
#else
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <curses.h>
|
||||
|
||||
#include "bsddialog.h"
|
||||
#include "lib_util.h"
|
||||
#include "bsddialog_theme.h"
|
||||
#include "lib_util.h"
|
||||
|
||||
#define GET_COLOR(bg, fg) (COLOR_PAIR(bg * 8 + fg +1))
|
||||
|
||||
@ -42,7 +38,7 @@ struct bsddialog_theme t;
|
||||
static struct bsddialog_theme bsddialogtheme = {
|
||||
#define bgwidget COLOR_WHITE
|
||||
#define bgcurr COLOR_YELLOW
|
||||
.terminal.color = GET_COLOR(COLOR_BLACK, COLOR_CYAN),
|
||||
.screen.color = GET_COLOR(COLOR_BLACK, COLOR_CYAN),
|
||||
|
||||
.shadow.color = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
|
||||
.shadow.h = 1,
|
||||
@ -55,8 +51,6 @@ static struct bsddialog_theme bsddialogtheme = {
|
||||
.dialog.color = GET_COLOR(COLOR_BLACK, bgwidget),
|
||||
.dialog.bottomtitlecolor = GET_COLOR(COLOR_BLACK, bgwidget),
|
||||
|
||||
.text.hmargin = 1,
|
||||
|
||||
.menu.arrowcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
|
||||
.menu.selectorcolor = GET_COLOR(COLOR_BLACK, bgwidget) | A_BOLD,
|
||||
.menu.f_desccolor = GET_COLOR(COLOR_WHITE, bgcurr),
|
||||
@ -89,7 +83,7 @@ static struct bsddialog_theme bsddialogtheme = {
|
||||
static struct bsddialog_theme blackwhite = {
|
||||
#define fg COLOR_WHITE
|
||||
#define bk COLOR_BLACK
|
||||
.terminal.color = GET_COLOR(fg, bk),
|
||||
.screen.color = GET_COLOR(fg, bk),
|
||||
|
||||
.shadow.color = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
|
||||
.shadow.h = 1,
|
||||
@ -102,8 +96,6 @@ static struct bsddialog_theme blackwhite = {
|
||||
.dialog.color = GET_COLOR(fg, bk),
|
||||
.dialog.bottomtitlecolor = GET_COLOR(fg, bk),
|
||||
|
||||
.text.hmargin = 1,
|
||||
|
||||
.menu.arrowcolor = GET_COLOR(fg, bk),
|
||||
.menu.selectorcolor = GET_COLOR(fg, bk),
|
||||
.menu.f_desccolor = GET_COLOR(fg, bk) | A_REVERSE,
|
||||
@ -134,7 +126,7 @@ static struct bsddialog_theme blackwhite = {
|
||||
};
|
||||
|
||||
static struct bsddialog_theme dialogtheme = {
|
||||
.terminal.color = GET_COLOR(COLOR_CYAN, COLOR_BLUE) | A_BOLD,
|
||||
.screen.color = GET_COLOR(COLOR_CYAN, COLOR_BLUE) | A_BOLD,
|
||||
|
||||
.shadow.color = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
|
||||
.shadow.h = 1,
|
||||
@ -147,18 +139,16 @@ static struct bsddialog_theme dialogtheme = {
|
||||
.dialog.color = GET_COLOR(COLOR_BLACK, COLOR_WHITE),
|
||||
.dialog.bottomtitlecolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
|
||||
|
||||
.text.hmargin = 1,
|
||||
|
||||
.menu.arrowcolor = GET_COLOR(COLOR_GREEN, COLOR_WHITE),
|
||||
.menu.selectorcolor = GET_COLOR(COLOR_BLACK, bgwidget) | A_BOLD,
|
||||
.menu.f_desccolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE) | A_BOLD,
|
||||
.menu.desccolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
|
||||
.menu.f_namecolor = GET_COLOR(COLOR_YELLOW, COLOR_BLUE) | A_BOLD,
|
||||
.menu.namecolor = GET_COLOR(COLOR_BLUE, COLOR_WHITE) | A_BOLD,
|
||||
.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.namecolor = GET_COLOR(COLOR_BLUE, COLOR_WHITE),
|
||||
.menu.namesepcolor = GET_COLOR(COLOR_RED, COLOR_WHITE),
|
||||
.menu.descsepcolor = GET_COLOR(COLOR_RED, COLOR_WHITE),
|
||||
.menu.f_shortcutcolor = GET_COLOR(COLOR_RED, COLOR_BLUE) | A_BOLD,
|
||||
.menu.shortcutcolor = GET_COLOR(COLOR_RED, COLOR_WHITE) | A_BOLD,
|
||||
.menu.f_shortcutcolor = GET_COLOR(COLOR_RED, COLOR_BLUE),
|
||||
.menu.shortcutcolor = GET_COLOR(COLOR_RED, COLOR_WHITE),
|
||||
|
||||
.form.f_fieldcolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE) | A_BOLD,
|
||||
.form.fieldcolor = GET_COLOR(COLOR_WHITE, COLOR_CYAN) | A_BOLD,
|
||||
@ -181,11 +171,12 @@ static struct bsddialog_theme dialogtheme = {
|
||||
static void
|
||||
set_theme(struct bsddialog_theme *dst, struct bsddialog_theme *src)
|
||||
{
|
||||
dst->screen.color = src->screen.color;
|
||||
|
||||
dst->shadow.color = src->shadow.color;
|
||||
dst->shadow.h = src->shadow.h;
|
||||
dst->shadow.w = src->shadow.w;
|
||||
|
||||
dst->terminal.color = src->terminal.color;
|
||||
dst->dialog.delimtitle = src->dialog.delimtitle;
|
||||
dst->dialog.titlecolor = src->dialog.titlecolor;
|
||||
dst->dialog.lineraisecolor = src->dialog.lineraisecolor;
|
||||
@ -193,8 +184,6 @@ set_theme(struct bsddialog_theme *dst, struct bsddialog_theme *src)
|
||||
dst->dialog.color = src->dialog.color;
|
||||
dst->dialog.bottomtitlecolor = src->dialog.bottomtitlecolor;
|
||||
|
||||
dst->text.hmargin = src->text.hmargin;
|
||||
|
||||
dst->menu.arrowcolor = src->menu.arrowcolor;
|
||||
dst->menu.selectorcolor = src->menu.selectorcolor;
|
||||
dst->menu.f_desccolor = src->menu.f_desccolor;
|
||||
@ -223,7 +212,7 @@ set_theme(struct bsddialog_theme *dst, struct bsddialog_theme *src)
|
||||
dst->button.f_shortcutcolor = src->button.f_shortcutcolor;
|
||||
dst->button.shortcutcolor = src->button.shortcutcolor;
|
||||
|
||||
bkgd(dst->terminal.color);
|
||||
bkgd(dst->screen.color);
|
||||
refresh();
|
||||
}
|
||||
|
||||
@ -258,6 +247,9 @@ int bsddialog_set_default_theme(enum bsddialog_default_theme newtheme)
|
||||
if (newtheme == BSDDIALOG_THEME_DEFAULT) {
|
||||
bsddialog_set_theme(&dialogtheme);
|
||||
t.dialog.lineraisecolor = t.dialog.linelowercolor;
|
||||
t.dialog.delimtitle = true;
|
||||
t.button.leftch = '[';
|
||||
t.button.rightch = ']';
|
||||
}
|
||||
else if (newtheme == BSDDIALOG_THEME_BSDDIALOG)
|
||||
bsddialog_set_theme(&bsddialogtheme);
|
||||
@ -285,4 +277,4 @@ bsddialog_color(enum bsddialog_color foreground,
|
||||
cursesflags |= A_UNDERLINE;
|
||||
|
||||
return (GET_COLOR(foreground, background) | cursesflags);
|
||||
}
|
||||
}
|
345
lib/timebox.c
345
lib/timebox.c
@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2021 Alfonso Sabato Siciliano
|
||||
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -28,66 +28,41 @@
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#ifdef PORTNCURSES
|
||||
#include <ncurses/ncurses.h>
|
||||
#else
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <curses.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bsddialog.h"
|
||||
#include "lib_util.h"
|
||||
#include "bsddialog_theme.h"
|
||||
#include "lib_util.h"
|
||||
|
||||
#define MINWDATE 25 /* 23 wins + 2 VBORDERS */
|
||||
#define MINWTIME 16 /*14 wins + 2 VBORDERS */
|
||||
#define MINHEIGHT 8 /* 2 for text */
|
||||
|
||||
/* "Time": timebox - datebox */
|
||||
#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, char *text, struct buttons bs)
|
||||
int *w, int minw, const char *text, struct buttons bs)
|
||||
{
|
||||
int maxword, maxline, nlines, line;
|
||||
int htext, wtext;
|
||||
|
||||
if (get_text_properties(conf, text, &maxword, &maxline, &nlines) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
if (cols == BSDDIALOG_AUTOSIZE) {
|
||||
*w = VBORDERS;
|
||||
/* buttons size */
|
||||
*w += bs.nbuttons * bs.sizebutton;
|
||||
*w += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
|
||||
/* text size */
|
||||
line = maxline + VBORDERS + t.text.hmargin * 2;
|
||||
line = MAX(line, (int) (maxword + VBORDERS + t.text.hmargin * 2));
|
||||
*w = MAX(*w, line);
|
||||
/* date windows */
|
||||
*w = MAX(*w, minw);
|
||||
/* conf.auto_minwidth */
|
||||
*w = MAX(*w, (int)conf->auto_minwidth);
|
||||
/* avoid terminal overflow */
|
||||
*w = MIN(*w, widget_max_width(conf) -1);
|
||||
if (cols == BSDDIALOG_AUTOSIZE || rows == BSDDIALOG_AUTOSIZE) {
|
||||
if (text_size(conf, rows, cols, text, &bs, 3, minw, &htext,
|
||||
&wtext) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
}
|
||||
|
||||
if (rows == BSDDIALOG_AUTOSIZE) {
|
||||
*h = MINHEIGHT;
|
||||
if (maxword > 0)
|
||||
*h += MAX(nlines, (int)(*w / GET_ASPECT_RATIO(conf)));
|
||||
/* conf.auto_minheight */
|
||||
*h = MAX(*h, (int)conf->auto_minheight);
|
||||
/* avoid terminal overflow */
|
||||
*h = MIN(*h, widget_max_height(conf) -1);
|
||||
}
|
||||
if (cols == BSDDIALOG_AUTOSIZE)
|
||||
*w = widget_min_width(conf, htext,minw, &bs);
|
||||
|
||||
return 0;
|
||||
if (rows == BSDDIALOG_AUTOSIZE)
|
||||
*h = widget_min_height(conf, htext, 3 /* windows */, true);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
datetime_checksize(int rows, int cols, char *text, int minw, struct buttons bs)
|
||||
datetime_checksize(int rows, int cols, int minw, struct buttons bs)
|
||||
{
|
||||
int mincols;
|
||||
|
||||
@ -99,19 +74,20 @@ datetime_checksize(int rows, int cols, char *text, int minw, struct buttons bs)
|
||||
if (cols < mincols)
|
||||
RETURN_ERROR("Few cols for this timebox/datebox");
|
||||
|
||||
if (rows < MINHEIGHT + (strlen(text) > 0 ? 1 : 0))
|
||||
RETURN_ERROR("Few rows for this timebox/datebox");
|
||||
if (rows < 7) /* 2 button + 2 borders + 3 windows */
|
||||
RETURN_ERROR("Few rows for this timebox/datebox, at least 7");
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int *hh, unsigned int *mm, unsigned int *ss)
|
||||
int
|
||||
bsddialog_timebox(struct bsddialog_conf *conf, const char* text, int rows,
|
||||
int cols, unsigned int *hh, unsigned int *mm, unsigned int *ss)
|
||||
{
|
||||
WINDOW *widget, *textpad, *shadow;
|
||||
int i, input, output, y, x, h, w, sel, htextpad;
|
||||
struct buttons bs;
|
||||
bool loop;
|
||||
int i, input, output, y, x, h, w, sel;
|
||||
WINDOW *widget, *textpad, *shadow;
|
||||
struct buttons bs;
|
||||
struct myclockstruct {
|
||||
unsigned int max;
|
||||
unsigned int value;
|
||||
@ -132,41 +108,38 @@ int bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int col
|
||||
c[i].value = c[i].max;
|
||||
}
|
||||
|
||||
get_buttons(conf, &bs, BUTTONLABEL(ok_label), BUTTONLABEL(extra_label),
|
||||
BUTTONLABEL(cancel_label), BUTTONLABEL(help_label));
|
||||
get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (datetime_autosize(conf, rows, cols, &h, &w, MINWTIME, text, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (datetime_checksize(h, w, text, MINWTIME, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (datetime_autosize(conf, rows, cols, &h, &w, MINWTIME, text,
|
||||
bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (datetime_checksize(h, w, MINWTIME, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
if (new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w, RAISED,
|
||||
&textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs,
|
||||
true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
wrefresh(widget);
|
||||
pnoutrefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
||||
doupdate();
|
||||
|
||||
prefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
||||
|
||||
c[0].win = new_boxed_window(conf, y + h - 6, x + w/2 - 7, 3, 4, LOWERED);
|
||||
c[0].win = new_boxed_window(conf, y+h-6, x + w/2 - 7, 3, 4, LOWERED);
|
||||
mvwaddch(widget, h - 5, w/2 - 3, ':');
|
||||
c[1].win = new_boxed_window(conf, y + h - 6, x + w/2 - 2, 3, 4, LOWERED);
|
||||
c[1].win = new_boxed_window(conf, y+h-6, x + w/2 - 2, 3, 4, LOWERED);
|
||||
mvwaddch(widget, h - 5, w/2 + 2, ':');
|
||||
c[2].win = new_boxed_window(conf, y + h - 6, x + w/2 + 3, 3, 4, LOWERED);
|
||||
c[2].win = new_boxed_window(conf, y+h-6, x + w/2 + 3, 3, 4, LOWERED);
|
||||
|
||||
wrefresh(widget);
|
||||
|
||||
sel = 0;
|
||||
curs_set(2);
|
||||
loop = true;
|
||||
while(loop) {
|
||||
for (i=0; i<3; i++) {
|
||||
while (loop) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
mvwprintw(c[i].win, 1, 1, "%2d", c[i].value);
|
||||
wrefresh(c[i].win);
|
||||
}
|
||||
@ -186,79 +159,61 @@ int bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int col
|
||||
loop = false;
|
||||
break;
|
||||
case 27: /* Esc */
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
if (conf->key.enable_esc) {
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
}
|
||||
break;
|
||||
case '\t': /* TAB */
|
||||
sel = (sel + 1) % 3;
|
||||
bs.curr = (bs.curr + 1) % bs.nbuttons;
|
||||
draw_buttons(widget, bs, true);
|
||||
wrefresh(widget);
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if (bs.curr > 0) {
|
||||
bs.curr--;
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
wrefresh(widget);
|
||||
}
|
||||
sel = sel == 0 ? 2 : (sel - 1);
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
if (bs.curr < (int) bs.nbuttons - 1) {
|
||||
bs.curr++;
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
wrefresh(widget);
|
||||
}
|
||||
sel = (sel + 1) % 3;
|
||||
break;
|
||||
case KEY_UP:
|
||||
c[sel].value = c[sel].value < c[sel].max ? c[sel].value + 1 : 0;
|
||||
c[sel].value = c[sel].value < c[sel].max ?
|
||||
c[sel].value + 1 : 0;
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
c[sel].value = c[sel].value > 0 ? c[sel].value - 1 : c[sel].max;
|
||||
c[sel].value = c[sel].value > 0 ?
|
||||
c[sel].value - 1 : c[sel].max;
|
||||
break;
|
||||
case KEY_F(1):
|
||||
if (conf->f1_file == NULL && conf->f1_message == NULL)
|
||||
break;
|
||||
curs_set(0);
|
||||
if (f1help(conf) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
curs_set(2);
|
||||
/* No break! the terminal size can change */
|
||||
/* No break, screen size can change */
|
||||
case KEY_RESIZE:
|
||||
hide_widget(y, x, h, w,conf->shadow);
|
||||
|
||||
/*
|
||||
* Unnecessary, but, when the columns decrease the
|
||||
* following "refresh" seem not work
|
||||
*/
|
||||
/* Important for decreasing screen */
|
||||
hide_widget(y, x, h, w, conf->shadow);
|
||||
refresh();
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (datetime_autosize(conf, rows, cols, &h, &w, MINWTIME, text, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (datetime_checksize(h, w, text, MINWTIME, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (datetime_autosize(conf, rows, cols, &h, &w,
|
||||
MINWTIME, text, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (datetime_checksize(h, w, MINWTIME, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
wclear(shadow);
|
||||
mvwin(shadow, y + t.shadow.h, x + t.shadow.w);
|
||||
wresize(shadow, h, w);
|
||||
if (update_dialog(conf, shadow, widget, y, x, h, w,
|
||||
textpad, text, &bs, true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
wclear(widget);
|
||||
mvwin(widget, y, x);
|
||||
wresize(widget, h, w);
|
||||
doupdate();
|
||||
|
||||
htextpad = 1;
|
||||
wclear(textpad);
|
||||
wresize(textpad, 1, w - HBORDERS - t.text.hmargin * 2);
|
||||
|
||||
if(update_widget_withtextpad(conf, shadow, widget, h, w,
|
||||
RAISED, textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
mvwaddch(widget, h - 5, w/2 - 3, ':');
|
||||
mvwaddch(widget, h - 5, w/2 + 2, ':');
|
||||
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
|
||||
wrefresh(widget);
|
||||
|
||||
prefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
||||
@ -282,31 +237,30 @@ int bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int col
|
||||
refresh();
|
||||
break;
|
||||
default:
|
||||
for (i = 0; i < (int) bs.nbuttons; i++)
|
||||
if (tolower(input) == tolower((bs.label[i])[0])) {
|
||||
output = bs.value[i];
|
||||
loop = false;
|
||||
if (shortcut_buttons(input, &bs)) {
|
||||
output = bs.value[bs.curr];
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
curs_set(0);
|
||||
|
||||
for (i=0; i<3; i++)
|
||||
for (i = 0; i < 3; i++)
|
||||
delwin(c[i].win);
|
||||
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
|
||||
end_dialog(conf, shadow, widget, textpad);
|
||||
|
||||
return output;
|
||||
return (output);
|
||||
}
|
||||
|
||||
int
|
||||
bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
unsigned int *yy, unsigned int *mm, unsigned int *dd)
|
||||
bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
|
||||
int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd)
|
||||
{
|
||||
WINDOW *widget, *textpad, *shadow;
|
||||
int i, input, output, y, x, h, w, sel, htextpad;
|
||||
struct buttons bs;
|
||||
bool loop;
|
||||
int i, input, output, y, x, h, w, sel;
|
||||
WINDOW *widget, *textpad, *shadow;
|
||||
struct buttons bs;
|
||||
struct calendar {
|
||||
int max;
|
||||
int value;
|
||||
@ -348,44 +302,41 @@ bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
if (c[2].value > c[2].max)
|
||||
c[2].value = c[2].max;
|
||||
|
||||
get_buttons(conf, &bs, BUTTONLABEL(ok_label), BUTTONLABEL(extra_label),
|
||||
BUTTONLABEL(cancel_label), BUTTONLABEL(help_label));
|
||||
get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (datetime_autosize(conf, rows, cols, &h, &w, MINWDATE, text, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (datetime_checksize(h, w, text, MINWDATE, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (datetime_autosize(conf, rows, cols, &h, &w, MINWDATE, text,
|
||||
bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (datetime_checksize(h, w, MINWDATE, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
if (new_widget_withtextpad(conf, &shadow, &widget, y, x, h, w, RAISED,
|
||||
&textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs,
|
||||
true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
pnoutrefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
||||
doupdate();
|
||||
|
||||
wrefresh(widget);
|
||||
|
||||
prefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
||||
|
||||
c[0].win = new_boxed_window(conf, y + h - 6, x + w/2 - 11, 3, 6, LOWERED);
|
||||
c[0].win = new_boxed_window(conf, y+h-6, x + w/2 - 11, 3, 6, LOWERED);
|
||||
mvwaddch(widget, h - 5, w/2 - 5, '/');
|
||||
c[1].win = new_boxed_window(conf, y + h - 6, x + w/2 - 4, 3, 11, LOWERED);
|
||||
c[1].win = new_boxed_window(conf, y+h-6, x + w/2 - 4, 3, 11, LOWERED);
|
||||
mvwaddch(widget, h - 5, w/2 + 7, '/');
|
||||
c[2].win = new_boxed_window(conf, y + h - 6, x + w/2 + 8, 3, 4, LOWERED);
|
||||
|
||||
c[2].win = new_boxed_window(conf, y+h-6, x + w/2 + 8, 3, 4, LOWERED);
|
||||
|
||||
wrefresh(widget);
|
||||
|
||||
sel = 2;
|
||||
curs_set(2);
|
||||
loop = true;
|
||||
while(loop) {
|
||||
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);
|
||||
mvwprintw(c[2].win, 1, 1, "%2d", c[2].value);
|
||||
for (i=0; i<3; i++) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
wrefresh(c[i].win);
|
||||
}
|
||||
wmove(c[sel].win, 1, c[sel].x);
|
||||
@ -404,28 +355,25 @@ bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
loop = false;
|
||||
break;
|
||||
case 27: /* Esc */
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
if (conf->key.enable_esc) {
|
||||
output = BSDDIALOG_ESC;
|
||||
loop = false;
|
||||
}
|
||||
break;
|
||||
case '\t': /* TAB */
|
||||
sel = (sel + 1) % 3;
|
||||
bs.curr = (bs.curr + 1) % bs.nbuttons;
|
||||
draw_buttons(widget, bs, true);
|
||||
wrefresh(widget);
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if (bs.curr > 0) {
|
||||
bs.curr--;
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
wrefresh(widget);
|
||||
}
|
||||
sel = sel == 0 ? 2 : (sel - 1);
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
if (bs.curr < (int) bs.nbuttons - 1) {
|
||||
bs.curr++;
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
wrefresh(widget);
|
||||
}
|
||||
sel = (sel + 1) % 3;
|
||||
break;
|
||||
case KEY_UP:
|
||||
c[sel].value = c[sel].value > 1 ? c[sel].value - 1 : c[sel].max ;
|
||||
c[sel].value = c[sel].value > 1 ?
|
||||
c[sel].value - 1 : c[sel].max ;
|
||||
/* if mount change */
|
||||
c[2].max = m[c[1].value -1].days;
|
||||
/* if year change */
|
||||
@ -436,7 +384,8 @@ bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
c[2].value = c[2].max;
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
c[sel].value = c[sel].value < c[sel].max ? c[sel].value + 1 : 1;
|
||||
c[sel].value = c[sel].value < c[sel].max ?
|
||||
c[sel].value + 1 : 1;
|
||||
/* if mount change */
|
||||
c[2].max = m[c[1].value -1].days;
|
||||
/* if year change */
|
||||
@ -451,48 +400,31 @@ bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
break;
|
||||
curs_set(0);
|
||||
if (f1help(conf) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
curs_set(2);
|
||||
/* No break! the terminal size can change */
|
||||
/* No break, screen size can change */
|
||||
case KEY_RESIZE:
|
||||
hide_widget(y, x, h, w,conf->shadow);
|
||||
|
||||
/*
|
||||
* Unnecessary, but, when the columns decrease the
|
||||
* following "refresh" seem not work
|
||||
*/
|
||||
/* Important for decreasing screen */
|
||||
hide_widget(y, x, h, w, conf->shadow);
|
||||
refresh();
|
||||
|
||||
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (datetime_autosize(conf, rows, cols, &h, &w, MINWDATE, text, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
if (datetime_checksize(h, w, text, MINWDATE, bs) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (datetime_autosize(conf, rows, cols, &h, &w,
|
||||
MINWDATE, text, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (datetime_checksize(h, w, MINWDATE, bs) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
return (BSDDIALOG_ERROR);
|
||||
|
||||
wclear(shadow);
|
||||
mvwin(shadow, y + t.shadow.h, x + t.shadow.w);
|
||||
wresize(shadow, h, w);
|
||||
if (update_dialog(conf, shadow, widget, y, x, h, w,
|
||||
textpad, text, &bs, true) != 0)
|
||||
return (BSDDIALOG_ERROR);
|
||||
doupdate();
|
||||
|
||||
wclear(widget);
|
||||
mvwin(widget, y, x);
|
||||
wresize(widget, h, w);
|
||||
|
||||
htextpad = 1;
|
||||
wclear(textpad);
|
||||
wresize(textpad, 1, w - HBORDERS - t.text.hmargin * 2);
|
||||
|
||||
if(update_widget_withtextpad(conf, shadow, widget, h, w,
|
||||
RAISED, textpad, &htextpad, text, true) != 0)
|
||||
return BSDDIALOG_ERROR;
|
||||
|
||||
mvwaddch(widget, h - 5, w/2 - 5, '/');
|
||||
mvwaddch(widget, h - 5, w/2 + 7, '/');
|
||||
|
||||
draw_buttons(widget, h-2, w, bs, true);
|
||||
|
||||
wrefresh(widget);
|
||||
|
||||
prefresh(textpad, 0, 0, y+1, x+2, y+h-7, x+w-2);
|
||||
@ -516,19 +448,18 @@ bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
|
||||
refresh();
|
||||
break;
|
||||
default:
|
||||
for (i = 0; i < (int) bs.nbuttons; i++)
|
||||
if (tolower(input) == tolower((bs.label[i])[0])) {
|
||||
output = bs.value[i];
|
||||
loop = false;
|
||||
if (shortcut_buttons(input, &bs)) {
|
||||
output = bs.value[bs.curr];
|
||||
loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
curs_set(0);
|
||||
|
||||
for (i=0; i<3; i++)
|
||||
for (i = 0; i < 3; i++)
|
||||
delwin(c[i].win);
|
||||
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
|
||||
end_dialog(conf, shadow, widget, textpad);
|
||||
|
||||
return output;
|
||||
}
|
||||
return (output);
|
||||
}
|
Loading…
Reference in New Issue
Block a user