1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2021 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 _BSDDIALOG_H_ 29 #define _BSDDIALOG_H_ 30 31 #include <stdbool.h> 32 33 /* Exit status */ 34 #define BSDDIALOG_ERROR -1 35 #define BSDDIALOG_YESOK 0 36 #define BSDDIALOG_NOCANCEL 1 37 #define BSDDIALOG_HELP 2 38 #define BSDDIALOG_EXTRA 3 39 #define BSDDIALOG_ITEM_HELP 4 40 #define BSDDIALOG_ESC 5 41 42 /* size and position */ 43 #define BSDDIALOG_FULLSCREEN -1 44 #define BSDDIALOG_AUTOSIZE 0 45 #define BSDDIALOG_CENTER -1 46 47 struct bsddialog_conf { 48 /* conf.* */ 49 bool ascii_lines; 50 int aspect_ratio; 51 int x; 52 int y; 53 bool clear; 54 int *get_height; 55 int *get_width; 56 char *hfile; 57 char *hline; 58 /*int input_fd;*/ 59 /*bool keep_tite;*/ 60 /*bool keep_window;*/ 61 /*bool last_key;*/ 62 /*int max_input;*/ 63 /*bool no_kill;*/ 64 bool no_lines; 65 /*bool no_mouse; useful?*/ 66 /*bool scrollbar; useful?*/ 67 /*char *separate_witget;*/ 68 bool shadow; 69 /*bool size_err;*/ 70 int sleep; 71 /*int timeout;*/ 72 char *title; 73 /* conf.text.* */ 74 struct { 75 bool colors; 76 bool cr_wrap; 77 bool no_collapse; 78 bool no_nl_expand; 79 /*bool tab_correct; textbox?*/ 80 /*int tab_len; textbox?*/ 81 bool trim; 82 } text; 83 /* conf.form.* */ 84 /*struct { 85 bool insecure; 86 } form;*/ 87 /* conf.menu.* */ 88 struct { 89 bool align_left; 90 char *colums_separator; 91 char *default_item; /*delete, add int *focus to API?*/ 92 bool no_items; 93 bool no_tags; 94 /*bool visit_items;*/ 95 } menu; 96 /* conf.button.* */ 97 struct { 98 char *cancel_label; 99 bool defaultno; 100 char *default_label; 101 char *exit_label; 102 bool extra_button; 103 char *extra_label; 104 bool help_button; 105 char *help_label; 106 bool no_cancel; 107 char *no_label; 108 bool no_ok; 109 char *ok_label; 110 char *yes_label; 111 } button; 112 }; 113 114 struct bsddialog_menuitem { 115 char *prefix; 116 bool on; 117 int depth; 118 char *name; 119 char *desc; 120 char *bottomdesc; 121 }; 122 123 enum bsddialog_grouptype { 124 BSDDIALOG_CHECKLIST, 125 BSDDIALOG_RADIOLIST, 126 BSDDIALOG_SEPARATOR, 127 }; 128 129 struct bsddialog_menugroup { 130 enum bsddialog_grouptype type; 131 unsigned int nitems; 132 struct bsddialog_menuitem *items; 133 }; 134 135 int bsddialog_init(void); 136 int bsddialog_end(void); 137 int bsddialog_backtitle(struct bsddialog_conf conf, char *backtitle); 138 const char *bsddialog_geterror(void); 139 int bsddialog_terminalheight(void); 140 int bsddialog_terminalwidth(void); 141 void bsddialog_initconf(struct bsddialog_conf *conf); 142 143 /* widgets */ 144 int 145 bsddialog_buildlist(struct bsddialog_conf conf, char* text, int rows, int cols, 146 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 147 int *focusitem); 148 149 int 150 bsddialog_calendar(struct bsddialog_conf conf, char* text, int rows, int cols, 151 unsigned int *yy, unsigned int *mm, unsigned int *dd); 152 153 int 154 bsddialog_checklist(struct bsddialog_conf conf, char* text, int rows, int cols, 155 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 156 int *focusitem); 157 158 int 159 bsddialog_dselect(struct bsddialog_conf conf, char* text, int rows, int cols); 160 161 int 162 bsddialog_editbox(struct bsddialog_conf conf, char* text, int rows, int cols); 163 164 int bsddialog_form(struct bsddialog_conf conf, char* text, int rows, int cols, 165 int formheight, int argc, char **argv); 166 167 int 168 bsddialog_fselect(struct bsddialog_conf conf, char* text, int rows, int cols); 169 170 int 171 bsddialog_gauge(struct bsddialog_conf conf, char* text, int rows, int cols, 172 int perc); 173 174 int 175 bsddialog_infobox(struct bsddialog_conf conf, char* text, int rows, int cols); 176 177 int 178 bsddialog_inputbox(struct bsddialog_conf conf, char* text, int rows, int cols); 179 180 int 181 bsddialog_inputmenu(struct bsddialog_conf conf, char* text, int rows, int cols); 182 183 int 184 bsddialog_menu(struct bsddialog_conf conf, char* text, int rows, int cols, 185 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 186 int *focusitem); 187 188 int 189 bsddialog_mixedform(struct bsddialog_conf conf, char* text, int rows, int cols, 190 int formheight, int argc, char **argv); 191 192 int 193 bsddialog_mixedgauge(struct bsddialog_conf conf, char* text, int rows, int cols, 194 unsigned int perc, int argc, char **argv); 195 196 int 197 bsddialog_mixedlist(struct bsddialog_conf conf, char* text, int rows, int cols, 198 unsigned int menurows, int ngroups, struct bsddialog_menugroup *groups, 199 int *focuslist, int *focusitem); 200 201 int 202 bsddialog_msgbox(struct bsddialog_conf conf, char* text, int rows, int cols); 203 204 int 205 bsddialog_passwordbox(struct bsddialog_conf conf, char* text, int rows, 206 int cols); 207 208 int 209 bsddialog_passwordform(struct bsddialog_conf conf, char* text, int rows, 210 int cols, int formheight, int argc, char **argv); 211 212 int 213 bsddialog_pause(struct bsddialog_conf conf, char* text, int rows, int cols, 214 int sec); 215 216 int 217 bsddialog_prgbox(struct bsddialog_conf conf, char* text, int rows, int cols, 218 char *command); 219 220 int 221 bsddialog_programbox(struct bsddialog_conf conf, char* text, int rows, 222 int cols); 223 224 int 225 bsddialog_progressbox(struct bsddialog_conf conf, char* text, int rows, 226 int cols); 227 228 int 229 bsddialog_radiolist(struct bsddialog_conf conf, char* text, int rows, int cols, 230 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 231 int *focusitem); 232 233 int 234 bsddialog_rangebox(struct bsddialog_conf conf, char* text, int rows, int cols, 235 int min, int max, int *value); 236 237 int 238 bsddialog_tailbox(struct bsddialog_conf conf, char* text, int rows, int cols); 239 240 int 241 bsddialog_tailboxbg(struct bsddialog_conf conf, char* text, int rows, int cols); 242 243 int 244 bsddialog_textbox(struct bsddialog_conf conf, char* text, int rows, int cols); 245 246 int 247 bsddialog_timebox(struct bsddialog_conf conf, char* text, int rows, int cols, 248 unsigned int *hh, unsigned int *mm, unsigned int *ss); 249 250 int 251 bsddialog_treeview(struct bsddialog_conf conf, char* text, int rows, int cols, 252 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 253 int *focusitem); 254 255 int bsddialog_yesno(struct bsddialog_conf conf, char* text, int rows, int cols); 256 257 #endif 258