2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2021-2023 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 "1.0"
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_LEFT1 6
46 #define BSDDIALOG_LEFT2 7
47 #define BSDDIALOG_LEFT3 8
48 #define BSDDIALOG_RIGHT1 9
49 #define BSDDIALOG_RIGHT2 10
50 #define BSDDIALOG_RIGHT3 11
52 /* Size and position */
53 #define BSDDIALOG_FULLSCREEN -1
54 #define BSDDIALOG_AUTOSIZE 0
55 #define BSDDIALOG_CENTER -1
58 #define BSDDIALOG_MG_SUCCEEDED -1
59 #define BSDDIALOG_MG_FAILED -2
60 #define BSDDIALOG_MG_PASSED -3
61 #define BSDDIALOG_MG_COMPLETED -4
62 #define BSDDIALOG_MG_CHECKED -5
63 #define BSDDIALOG_MG_DONE -6
64 #define BSDDIALOG_MG_SKIPPED -7
65 #define BSDDIALOG_MG_INPROGRESS -8
66 #define BSDDIALOG_MG_BLANK -9
67 #define BSDDIALOG_MG_NA -10
68 #define BSDDIALOG_MG_PENDING -11
71 #define BSDDIALOG_FIELDHIDDEN 1U
72 #define BSDDIALOG_FIELDREADONLY 2U
73 #define BSDDIALOG_FIELDNOCOLOR 4U
74 #define BSDDIALOG_FIELDCURSOREND 8U
75 #define BSDDIALOG_FIELDEXTEND 16U
76 #define BSDDIALOG_FIELDSINGLEBYTE 32U
78 struct bsddialog_conf {
80 unsigned int auto_minheight;
81 unsigned int auto_minwidth;
82 unsigned int auto_topmargin;
83 unsigned int auto_downmargin;
84 const char *bottomtitle;
97 const char *f1_message;
100 unsigned int cols_per_row;
108 bool shortcut_buttons;
120 const char *left1_label;
121 const char *left2_label;
122 const char *left3_label;
124 const char *ok_label;
126 const char *extra_label;
128 const char *cancel_label;
131 const char *help_label;
132 const char *right1_label;
133 const char *right2_label;
134 const char *right3_label;
135 const char *default_label;
139 struct bsddialog_menuitem {
145 const char *bottomdesc;
148 enum bsddialog_menutype {
154 struct bsddialog_menugroup {
155 enum bsddialog_menutype type;
157 struct bsddialog_menuitem *items;
158 unsigned int min_on; /* unused for now */
161 struct bsddialog_formitem {
169 unsigned int fieldlen;
170 unsigned int maxvaluelen;
174 const char *bottomdesc;
177 int bsddialog_init(void);
178 int bsddialog_init_notheme(void);
179 bool bsddialog_inmode(void);
180 int bsddialog_end(void);
181 int bsddialog_backtitle(struct bsddialog_conf *conf, const char *backtitle);
182 int bsddialog_initconf(struct bsddialog_conf *conf);
183 void bsddialog_clear(unsigned int y);
184 void bsddialog_refresh(void);
185 const char *bsddialog_geterror(void);
189 bsddialog_calendar(struct bsddialog_conf *conf, const char *text, int rows,
190 int cols, unsigned int *year, unsigned int *month, unsigned int *day);
193 bsddialog_checklist(struct bsddialog_conf *conf, const char *text, int rows,
194 int cols, unsigned int menurows, unsigned int nitems,
195 struct bsddialog_menuitem *items, int *focusitem);
198 bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
199 int cols, unsigned int *year, unsigned int *month, unsigned int *day);
202 bsddialog_form(struct bsddialog_conf *conf, const char *text, int rows,
203 int cols, unsigned int formheight, unsigned int nitems,
204 struct bsddialog_formitem *items, int *focusitem);
207 bsddialog_gauge(struct bsddialog_conf *conf, const char *text, int rows,
208 int cols, unsigned int perc, int fd, const char *sep, const char *end);
211 bsddialog_infobox(struct bsddialog_conf *conf, const char *text, int rows,
215 bsddialog_menu(struct bsddialog_conf *conf, const char *text, int rows,
216 int cols, unsigned int menurows, unsigned int nitems,
217 struct bsddialog_menuitem *items, int *focusitem);
220 bsddialog_mixedgauge(struct bsddialog_conf *conf, const char *text, int rows,
221 int cols, unsigned int mainperc, unsigned int nminibars,
222 const char **minilabels, int *minipercs);
225 bsddialog_mixedlist(struct bsddialog_conf *conf, const char *text, int rows,
226 int cols, unsigned int menurows, unsigned int ngroups,
227 struct bsddialog_menugroup *groups, int *focuslist, int *focusitem);
230 bsddialog_msgbox(struct bsddialog_conf *conf, const char *text, int rows,
234 bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows,
235 int cols, unsigned int *seconds);
238 bsddialog_radiolist(struct bsddialog_conf *conf, const char *text, int rows,
239 int cols, unsigned int menurows, unsigned int nitems,
240 struct bsddialog_menuitem *items, int *focusitem);
243 bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
244 int cols, int min, int max, int *value);
247 bsddialog_textbox(struct bsddialog_conf *conf, const char *file, int rows,
251 bsddialog_timebox(struct bsddialog_conf *conf, const char *text, int rows,
252 int cols, unsigned int *hh, unsigned int *mm, unsigned int *ss);
255 bsddialog_yesno(struct bsddialog_conf *conf, const char *text, int rows,