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 _LIBBSDDIALOG_H_ 29 #define _LIBBSDDIALOG_H_ 30 31 #include <stdbool.h> 32 33 #define LIBBSDDIALOG_VERSION "0.0.1" 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_ITEM_HELP 4 44 #define BSDDIALOG_TIMEOUT 5 45 #define BSDDIALOG_ESC 6 46 #define BSDDIALOG_GENERIC1 7 47 #define BSDDIALOG_GENERIC2 8 48 49 /* size and position */ 50 #define BSDDIALOG_FULLSCREEN -1 51 #define BSDDIALOG_AUTOSIZE 0 52 #define BSDDIALOG_CENTER -1 53 54 struct bsddialog_conf { 55 bool ascii_lines; 56 unsigned int aspect_ratio; 57 unsigned int auto_minheight; 58 unsigned int auto_minwidth; 59 char *bottomtitle; 60 bool clear; 61 char *f1_file; 62 char *f1_message; 63 int *get_height; 64 int *get_width; 65 bool no_lines; 66 bool shadow; 67 unsigned int sleep; 68 char *title; 69 int y; 70 int x; 71 struct { 72 bool colors; 73 } text; 74 struct { 75 bool align_left; 76 char *default_item; 77 bool no_desc; 78 bool no_name; 79 bool shortcut_buttons; 80 } menu; 81 struct { 82 int securech; 83 bool value_withcancel; 84 bool value_withextra; 85 bool value_withhelp; 86 } form; 87 struct { 88 bool without_ok; 89 char *ok_label; 90 bool with_extra; 91 char *extra_label; 92 bool without_cancel; 93 char *cancel_label; 94 bool default_cancel; 95 bool with_help; 96 char *help_label; 97 char *exit_label; 98 char *generic1_label; 99 char *generic2_label; 100 char *default_label; 101 } button; 102 }; 103 104 struct bsddialog_menuitem { 105 char *prefix; 106 bool on; 107 unsigned int depth; 108 char *name; 109 char *desc; 110 char *bottomdesc; 111 }; 112 113 enum bsddialog_grouptype { 114 BSDDIALOG_CHECKLIST, 115 BSDDIALOG_RADIOLIST, 116 BSDDIALOG_SEPARATOR, 117 }; 118 119 struct bsddialog_menugroup { 120 enum bsddialog_grouptype type; 121 unsigned int nitems; 122 struct bsddialog_menuitem *items; 123 }; 124 125 struct bsddialog_formitem { 126 char *label; 127 unsigned int ylabel; 128 unsigned int xlabel; 129 130 char *init; 131 unsigned int yfield; 132 unsigned int xfield; 133 unsigned int fieldlen; 134 unsigned int maxvaluelen; 135 char *value; /* allocated memory */ 136 #define BSDDIALOG_FIELDHIDDEN 1U 137 #define BSDDIALOG_FIELDREADONLY 2U 138 unsigned int flags; 139 140 char *bottomdesc; 141 }; 142 143 int bsddialog_init(void); 144 int bsddialog_end(void); 145 int bsddialog_backtitle(struct bsddialog_conf *conf, char *backtitle); 146 int bsddialog_initconf(struct bsddialog_conf *conf); 147 int bsddialog_clearterminal(void); 148 const char *bsddialog_geterror(void); 149 150 /* widgets */ 151 int 152 bsddialog_buildlist(struct bsddialog_conf *conf, char* text, int rows, int cols, 153 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 154 int *focusitem); 155 156 int 157 bsddialog_checklist(struct bsddialog_conf *conf, char* text, int rows, int cols, 158 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 159 int *focusitem); 160 161 int 162 bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols, 163 unsigned int *yy, unsigned int *mm, unsigned int *dd); 164 165 int 166 bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols, 167 unsigned int formheight, unsigned int nitems, 168 struct bsddialog_formitem *items); 169 170 int 171 bsddialog_gauge(struct bsddialog_conf *conf, char* text, int rows, int cols, 172 unsigned int perc); 173 174 int 175 bsddialog_infobox(struct bsddialog_conf *conf, char* text, int rows, int cols); 176 177 int 178 bsddialog_menu(struct bsddialog_conf *conf, char* text, int rows, int cols, 179 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 180 int *focusitem); 181 182 int 183 bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows, 184 int cols, unsigned int mainperc, unsigned int nminibars, char **minilabels, 185 int *minipercs); 186 187 int 188 bsddialog_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols, 189 unsigned int menurows, int ngroups, struct bsddialog_menugroup *groups, 190 int *focuslist, int *focusitem); 191 192 int 193 bsddialog_msgbox(struct bsddialog_conf *conf, char* text, int rows, int cols); 194 195 int 196 bsddialog_pause(struct bsddialog_conf *conf, char* text, int rows, int cols, 197 unsigned int sec); 198 199 int 200 bsddialog_radiolist(struct bsddialog_conf *conf, char* text, int rows, int cols, 201 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 202 int *focusitem); 203 204 int 205 bsddialog_rangebox(struct bsddialog_conf *conf, char* text, int rows, int cols, 206 int min, int max, int *value); 207 208 int 209 bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols); 210 211 int 212 bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int cols, 213 unsigned int *hh, unsigned int *mm, unsigned int *ss); 214 215 int 216 bsddialog_yesno(struct bsddialog_conf *conf, char* text, int rows, int cols); 217 218 #endif 219