]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bsddialog/lib/bsddialog.h
MFV: less v632.
[FreeBSD/FreeBSD.git] / contrib / bsddialog / lib / bsddialog.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2021-2022 Alfonso Sabato Siciliano
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  */
27
28 #ifndef _LIBBSDDIALOG_H_
29 #define _LIBBSDDIALOG_H_
30
31 #include <stdbool.h>
32
33 #define LIBBSDDIALOG_VERSION     "0.4"
34
35 /* Exit status */
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
47
48 /* Size and position */
49 #define BSDDIALOG_FULLSCREEN     -1
50 #define BSDDIALOG_AUTOSIZE        0
51 #define BSDDIALOG_CENTER         -1
52
53 /* Mixedgauge */
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
65
66 /* Form */
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
73
74 struct bsddialog_conf {
75         bool ascii_lines;
76         unsigned int auto_minheight;
77         unsigned int auto_minwidth;
78         unsigned int auto_topmargin;
79         unsigned int auto_downmargin;
80         const char *bottomtitle;
81         bool clear;
82         int *get_height;
83         int *get_width;
84         bool no_lines;
85         bool shadow;
86         unsigned int sleep;
87         const char *title;
88         int y;
89         int x;
90         struct {
91                 bool enable_esc;
92                 const char *f1_file;
93                 const char *f1_message;
94         } key;
95         struct {
96                 unsigned int cols_per_row;
97                 bool highlight;
98                 unsigned int tablen;
99         } text;
100         struct {
101                 bool align_left;
102                 bool no_desc;
103                 bool no_name;
104                 bool on_without_ok;
105                 bool shortcut_buttons;
106         } menu;
107         struct {
108                 char securech;
109                 char *securembch;
110                 bool value_wchar;
111                 bool value_without_ok;
112         } form;
113         struct {
114                 bool always_active;
115                 bool without_ok;
116                 const char *ok_label;
117                 bool with_extra;
118                 const char *extra_label;
119                 bool without_cancel;
120                 const char *cancel_label;
121                 bool default_cancel;
122                 bool with_help;
123                 const char *help_label;
124                 const char *generic1_label;
125                 const char *generic2_label;
126                 const char *default_label;
127         } button;
128 };
129
130 struct bsddialog_menuitem {
131         const char *prefix;
132         bool on;
133         unsigned int depth;
134         const char *name;
135         const char *desc;
136         const char *bottomdesc;
137 };
138
139 enum bsddialog_menutype {
140         BSDDIALOG_CHECKLIST,
141         BSDDIALOG_RADIOLIST,
142         BSDDIALOG_SEPARATOR,
143 };
144
145 struct bsddialog_menugroup {
146         enum bsddialog_menutype type;
147         unsigned int nitems;
148         struct bsddialog_menuitem *items;
149 };
150
151 struct bsddialog_formitem {
152         const char *label;
153         unsigned int ylabel;
154         unsigned int xlabel;
155
156         const char *init;
157         unsigned int yfield;
158         unsigned int xfield;
159         unsigned int fieldlen;
160         unsigned int maxvaluelen;
161         char *value;
162         unsigned int flags;
163
164         const char *bottomdesc;
165 };
166
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);
174
175 /* Dialogs */
176 int
177 bsddialog_calendar(struct bsddialog_conf *conf, const char *text, int rows,
178     int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd);
179
180 int
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);
184
185 int
186 bsddialog_datebox(struct bsddialog_conf *conf, const char *text, int rows,
187     int cols, unsigned int *yy, unsigned int *mm, unsigned int *dd);
188
189 int
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);
193
194 int
195 bsddialog_gauge(struct bsddialog_conf *conf, const char *text, int rows,
196     int cols, unsigned int perc, int fd, const char *sep);
197
198 int
199 bsddialog_infobox(struct bsddialog_conf *conf, const char *text, int rows,
200     int cols);
201
202 int
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);
206
207 int
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);
211
212 int
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);
216
217 int
218 bsddialog_msgbox(struct bsddialog_conf *conf, const char *text, int rows,
219     int cols);
220
221 int
222 bsddialog_pause(struct bsddialog_conf *conf, const char *text, int rows,
223     int cols, unsigned int seconds);
224
225 int
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);
229
230 int
231 bsddialog_rangebox(struct bsddialog_conf *conf, const char *text, int rows,
232     int cols, int min, int max, int *value);
233
234 int
235 bsddialog_textbox(struct bsddialog_conf *conf, const char *file, int rows,
236     int cols);
237
238 int
239 bsddialog_timebox(struct bsddialog_conf *conf, const char *text, int rows,
240     int cols, unsigned int *hh, unsigned int *mm, unsigned int *ss);
241
242 int
243 bsddialog_yesno(struct bsddialog_conf *conf, const char *text, int rows,
244     int cols);
245
246 #endif