2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2021-2022 Alfonso Sabato Siciliano
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #ifndef _LIBBSDDIALOG_H_
29 #define _LIBBSDDIALOG_H_
33 #define LIBBSDDIALOG_VERSION "0.4"
36 #define BSDDIALOG_ERROR -1
37 #define BSDDIALOG_OK 0
38 #define BSDDIALOG_YES BSDDIALOG_OK
39 #define BSDDIALOG_CANCEL 1
40 #define BSDDIALOG_NO BSDDIALOG_CANCEL
41 #define BSDDIALOG_HELP 2
42 #define BSDDIALOG_EXTRA 3
43 #define BSDDIALOG_TIMEOUT 4
44 #define BSDDIALOG_ESC 5
45 #define BSDDIALOG_GENERIC1 6
46 #define BSDDIALOG_GENERIC2 7
48 /* Size and position */
49 #define BSDDIALOG_FULLSCREEN -1
50 #define BSDDIALOG_AUTOSIZE 0
51 #define BSDDIALOG_CENTER -1
54 #define BSDDIALOG_MG_SUCCEEDED -1
55 #define BSDDIALOG_MG_FAILED -2
56 #define BSDDIALOG_MG_PASSED -3
57 #define BSDDIALOG_MG_COMPLETED -4
58 #define BSDDIALOG_MG_CHECKED -5
59 #define BSDDIALOG_MG_DONE -6
60 #define BSDDIALOG_MG_SKIPPED -7
61 #define BSDDIALOG_MG_INPROGRESS -8
62 #define BSDDIALOG_MG_BLANK -9
63 #define BSDDIALOG_MG_NA -10
64 #define BSDDIALOG_MG_PENDING -11
67 #define BSDDIALOG_FIELDHIDDEN 1U
68 #define BSDDIALOG_FIELDREADONLY 2U
69 #define BSDDIALOG_FIELDNOCOLOR 4U
70 #define BSDDIALOG_FIELDCURSOREND 8U
71 #define BSDDIALOG_FIELDEXTEND 16U
72 #define BSDDIALOG_FIELDSINGLEBYTE 32U
74 struct bsddialog_conf {
76 unsigned int auto_minheight;
77 unsigned int auto_minwidth;
78 unsigned int auto_topmargin;
79 unsigned int auto_downmargin;
80 const char *bottomtitle;
93 const char *f1_message;
96 unsigned int cols_per_row;
105 bool shortcut_buttons;
111 bool value_without_ok;
116 const char *ok_label;
118 const char *extra_label;
120 const char *cancel_label;
123 const char *help_label;
124 const char *generic1_label;
125 const char *generic2_label;
126 const char *default_label;
130 struct bsddialog_menuitem {
136 const char *bottomdesc;
139 enum bsddialog_menutype {
145 struct bsddialog_menugroup {
146 enum bsddialog_menutype type;
148 struct bsddialog_menuitem *items;
151 struct bsddialog_formitem {
159 unsigned int fieldlen;
160 unsigned int maxvaluelen;
164 const char *bottomdesc;
167 int bsddialog_init(void);
168 int bsddialog_init_notheme(void);
169 int bsddialog_end(void);
170 int bsddialog_backtitle(struct bsddialog_conf *conf, const char *backtitle);
171 int bsddialog_initconf(struct bsddialog_conf *conf);
172 int bsddialog_clearterminal(void);
173 const char *bsddialog_geterror(void);
177 bsddialog_calendar(struct bsddialog_conf *conf, const char *text, int rows,
178 int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd);
181 bsddialog_checklist(struct bsddialog_conf *conf, const char *text, int rows,
182 int cols, unsigned int menurows, unsigned int nitems,
183 struct bsddialog_menuitem *items, int *focusitem);
186 bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
187 int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd);
190 bsddialog_form(struct bsddialog_conf *conf, const char *text, int rows,
191 int cols, unsigned int formheight, unsigned int nitems,
192 struct bsddialog_formitem *items);
195 bsddialog_gauge(struct bsddialog_conf *conf, const char *text, int rows,
196 int cols, unsigned int perc, int fd, const char *sep);
199 bsddialog_infobox(struct bsddialog_conf *conf, const char *text, int rows,
203 bsddialog_menu(struct bsddialog_conf *conf, const char *text, int rows,
204 int cols, unsigned int menurows, unsigned int nitems,
205 struct bsddialog_menuitem *items, int *focusitem);
208 bsddialog_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows,
209 int cols, unsigned int mainperc, unsigned int nminibars,
210 const char **minilabels, int *minipercs);
213 bsddialog_mixedlist(struct bsddialog_conf *conf, const char *text, int rows,
214 int cols, unsigned int menurows, unsigned int ngroups,
215 struct bsddialog_menugroup *groups, int *focuslist, int *focusitem);
218 bsddialog_msgbox(struct bsddialog_conf *conf, const char *text, int rows,
222 bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows,
223 int cols, unsigned int seconds);
226 bsddialog_radiolist(struct bsddialog_conf *conf, const char *text, int rows,
227 int cols, unsigned int menurows, unsigned int nitems,
228 struct bsddialog_menuitem *items, int *focusitem);
231 bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
232 int cols, int min, int max, int *value);
235 bsddialog_textbox(struct bsddialog_conf *conf, const char *file, int rows,
239 bsddialog_timebox(struct bsddialog_conf *conf, const char *text, int rows,
240 int cols, unsigned int *hh, unsigned int *mm, unsigned int *ss);
243 bsddialog_yesno(struct bsddialog_conf *conf, const char *text, int rows,