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.1-devel" 34 35 /* Exit status */ 36 #define BSDDIALOG_ERROR -1 37 #define BSDDIALOG_YESOK 0 38 #define BSDDIALOG_NOCANCEL 1 39 #define BSDDIALOG_HELP 2 40 #define BSDDIALOG_EXTRA 3 41 #define BSDDIALOG_ITEM_HELP 4 42 #define BSDDIALOG_TIMEOUT 5 43 #define BSDDIALOG_ESC 6 44 #define BSDDIALOG_GENERIC1 7 45 #define BSDDIALOG_GENERIC2 8 46 47 /* size and position */ 48 #define BSDDIALOG_FULLSCREEN -1 49 #define BSDDIALOG_AUTOSIZE 0 50 #define BSDDIALOG_CENTER -1 51 52 struct bsddialog_conf { 53 bool ascii_lines; 54 int aspect_ratio; 55 int x; 56 int y; 57 bool clear; 58 int *get_height; 59 int *get_width; 60 char *hfile; 61 char *hline; 62 bool no_lines; 63 bool shadow; 64 int sleep; 65 char *title; 66 67 struct { 68 bool colors; 69 /* following members could be deleted in the future */ 70 bool cr_wrap; 71 bool no_collapse; 72 bool no_nl_expand; 73 bool trim; 74 } text; 75 76 struct { 77 bool align_left; 78 char *default_item; 79 bool no_desc; 80 bool no_name; 81 } menu; 82 83 struct { 84 int securech; 85 } form; 86 87 struct { 88 char *cancel_label; 89 bool defaultno; 90 char *default_label; 91 char *exit_label; 92 bool extra_button; 93 char *extra_label; 94 char *generic1_label; 95 char *generic2_label; 96 bool help_button; 97 char *help_label; 98 bool no_cancel; 99 char *no_label; 100 bool no_ok; 101 char *ok_label; 102 char *yes_label; 103 } button; 104 }; 105 106 struct bsddialog_menuitem { 107 char *prefix; 108 bool on; 109 int depth; 110 char *name; 111 char *desc; 112 char *bottomdesc; 113 }; 114 115 enum bsddialog_grouptype { 116 BSDDIALOG_CHECKLIST, 117 BSDDIALOG_RADIOLIST, 118 BSDDIALOG_SEPARATOR, 119 }; 120 121 struct bsddialog_menugroup { 122 enum bsddialog_grouptype type; 123 unsigned int nitems; 124 struct bsddialog_menuitem *items; 125 }; 126 127 struct bsddialog_formitem { 128 char *label; 129 unsigned int ylabel; 130 unsigned int xlabel; 131 132 char *init; 133 unsigned int yfield; 134 unsigned int xfield; 135 unsigned int fieldlen; 136 unsigned int maxvaluelen; 137 char *value; /* allocated memory */ 138 #define BSDDIALOG_FIELDHIDDEN 0x1 139 #define BSDDIALOG_FIELDREADONLY 0x2 140 unsigned int flags; 141 142 char *bottomdesc; /* unimplemented for now */ 143 }; 144 145 int bsddialog_init(void); 146 int bsddialog_end(void); 147 int bsddialog_backtitle(struct bsddialog_conf *conf, char *backtitle); 148 const char *bsddialog_geterror(void); 149 void bsddialog_initconf(struct bsddialog_conf *conf); 150 /* funcs for tzsetup(8), they will be deleted */ 151 int bsddialog_terminalheight(void); 152 int bsddialog_terminalwidth(void); 153 154 /* widgets */ 155 int 156 bsddialog_buildlist(struct bsddialog_conf *conf, char* text, int rows, int cols, 157 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 158 int *focusitem); 159 160 int 161 bsddialog_checklist(struct bsddialog_conf *conf, char* text, int rows, int cols, 162 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 163 int *focusitem); 164 165 int 166 bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols, 167 unsigned int *yy, unsigned int *mm, unsigned int *dd); 168 169 int 170 bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols, 171 unsigned int formheight, unsigned int nitems, 172 struct bsddialog_formitem *items); 173 174 int 175 bsddialog_gauge(struct bsddialog_conf *conf, char* text, int rows, int cols, 176 unsigned int perc); 177 178 int 179 bsddialog_infobox(struct bsddialog_conf *conf, char* text, int rows, int cols); 180 181 int 182 bsddialog_menu(struct bsddialog_conf *conf, char* text, int rows, int cols, 183 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 184 int *focusitem); 185 186 int 187 bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows, int cols, 188 unsigned int mainperc, unsigned int nminbars, char **minibars); 189 190 int 191 bsddialog_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols, 192 unsigned int menurows, int ngroups, struct bsddialog_menugroup *groups, 193 int *focuslist, int *focusitem); 194 195 int 196 bsddialog_msgbox(struct bsddialog_conf *conf, char* text, int rows, int cols); 197 198 int 199 bsddialog_pause(struct bsddialog_conf *conf, char* text, int rows, int cols, 200 unsigned int sec); 201 202 int 203 bsddialog_radiolist(struct bsddialog_conf *conf, char* text, int rows, int cols, 204 unsigned int menurows, int nitems, struct bsddialog_menuitem *items, 205 int *focusitem); 206 207 int 208 bsddialog_rangebox(struct bsddialog_conf *conf, char* text, int rows, int cols, 209 int min, int max, int *value); 210 211 int 212 bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols); 213 214 int 215 bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int cols, 216 unsigned int *hh, unsigned int *mm, unsigned int *ss); 217 218 int bsddialog_yesno(struct bsddialog_conf *conf, char* text, int rows, int cols); 219 220 #endif 221