aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile11
-rw-r--r--lib/barbox.c75
-rw-r--r--lib/bsddialog.h80
-rw-r--r--lib/bsddialog_theme.h46
-rw-r--r--lib/formbox.c57
-rw-r--r--lib/infobox.c12
-rw-r--r--lib/lib_util.c190
-rw-r--r--lib/lib_util.h2
-rw-r--r--lib/libbsddialog.c52
-rw-r--r--lib/menubox.c194
-rw-r--r--lib/messagebox.c19
-rw-r--r--lib/textbox.c16
-rw-r--r--lib/theme.c266
-rw-r--r--lib/timebox.c18
14 files changed, 603 insertions, 435 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 99dfea4d77e0..08d8db5191dc 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -3,7 +3,7 @@
#
# Written in 2021 by Alfonso Sabato Siciliano
-VERSION = 0.1
+VERSION = 0.0.1
LIBRARY = bsddialog
LIBRARY_SO = lib${LIBRARY:=.so}
HEADERS = bsddialog.h bsddialog_theme.h
@@ -12,7 +12,12 @@ SOURCES = barbox.c formbox.c infobox.c libbsddialog.c lib_util.c menubox.c \
OBJECTS= ${SOURCES:.c=.o}
FBSDFLAGS= -O2 -pipe -std=gnu99 -Wno-format-zero-length \
-fstack-protector-strong -Qunused-arguments
-CFLAGS = -I/usr/local/include -fPIC -Wall -Wextra ${FBSDFLAGS}
+CFLAGS = -fPIC -Wall -Wextra
+.if defined(DEBUG)
+CFLAGS += -g
+.else
+CFLAGS += ${FBSDFLAGS}
+.endif
LDFLAGS = -fstack-protector-strong -shared -Wl,-x -Wl,--fatal-warnings \
-Wl,--warn-shared-textrel -Wl,-soname,${LIBRARY_SO}.${VERSION}
@@ -24,7 +29,7 @@ GZIP = gzip -cn
LDCONFIG = /sbin/ldconfig -m
.if defined(PORTNCURSES)
-# PORT ncurses `make -DPORTNCURSES` or `make -D PORTNCURSES`
+# PORT ncurses `make -DPORTNCURSES`
CFLAGS += -DPORTNCURSES -I/usr/local/include
LDFLAGS += -L/usr/local/lib -lform -lncurses -ltinfo
.else
diff --git a/lib/barbox.c b/lib/barbox.c
index b0d5c0febcf8..da4f0b72c1d6 100644
--- a/lib/barbox.c
+++ b/lib/barbox.c
@@ -32,9 +32,9 @@
#include <string.h>
#ifdef PORTNCURSES
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
#else
-#include <curses.h>
+#include <ncurses.h>
#endif
#include "bsddialog.h"
@@ -105,6 +105,8 @@ bar_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
*w = MAX(*w, MINWIDTH);
/* text size*/
*w = MAX((int)(maxline + VBORDERS + t.text.hmargin * 2), *w);
+ /* conf.auto_minwidth */
+ *w = MAX(*w, (int)conf->auto_minwidth);
/* avoid terminal overflow */
*w = MIN(*w, widget_max_width(conf));
}
@@ -113,6 +115,8 @@ bar_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
*h = MINHEIGHT;
if (maxword > 0)
*h += 1;
+ /* conf.auto_minheight */
+ *h = MAX(*h, (int)conf->auto_minheight);
/* avoid terminal overflow */
*h = MIN(*h, widget_max_height(conf));
}
@@ -211,36 +215,35 @@ bsddialog_gauge(struct bsddialog_conf *conf, char* text, int rows, int cols,
delwin(bar);
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
- return BSDDIALOG_YESOK;
+ return BSDDIALOG_OK;
}
int
-bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows, int cols,
- unsigned int mainperc, unsigned int nminbars, char **minibars)
+bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows,
+ int cols, unsigned int mainperc, unsigned int nminibars, char **minilabels,
+ int *minipercs)
{
WINDOW *widget, *textpad, *bar, *shadow;
int i, output, miniperc, y, x, h, w, max_minbarlen;
int maxword, maxline, nlines, htextpad, ypad;
- char states[11][16] = {
- "[ Succeeded ]",
- "[ Failed ]",
- "[ Passed ]",
- "[ Completed ]",
- "[ Checked ]",
- "[ Done ]",
- "[ Skipped ]",
- "[ In Progress ]",
- "!!! BLANK !!!",
- "[ N/A ]",
- "[ UNKNOWN ]",
+ char states[12][16] = {
+ "[ Succeeded ]", /* 0 */
+ "[ Failed ]", /* 1 */
+ "[ Passed ]", /* 2 */
+ "[ Completed ]", /* 3 */
+ "[ Checked ]", /* 4 */
+ "[ Done ]", /* 5 */
+ "[ Skipped ]", /* 6 */
+ "[ In Progress ]", /* 7 */
+ "(blank) ", /* 8 */
+ "[ N/A ]", /* 9 */
+ "[ Pending ]", /* 10 */
+ "[ UNKNOWN ]", /* 10+ */
};
- if (nminbars % 2 !=0)
- RETURN_ERROR("Mixedgauge wants a pair name/perc");
-
max_minbarlen = 0;
- for (i=0; i < (int)(nminbars/2); i++)
- max_minbarlen = MAX(max_minbarlen, (int) strlen(minibars[i*2]));
+ for (i=0; i < (int)nminibars; i++)
+ max_minbarlen = MAX(max_minbarlen, (int)strlen(minilabels[i]));
max_minbarlen += 3 + 16 /* seps + [...] or mainbar */;
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
@@ -253,19 +256,21 @@ bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows, int cols
if (cols == BSDDIALOG_AUTOSIZE) {
w = max_minbarlen + HBORDERS;
w = MAX(max_minbarlen, maxline + 4);
+ w = MAX(w, (int)conf->auto_minwidth);
w = MIN(w, widget_max_width(conf) - 1);
}
if (rows == BSDDIALOG_AUTOSIZE) {
h = 5; /* borders + mainbar */
- h += nminbars/2;
+ h += nminibars;
h += (strlen(text) > 0 ? 3 : 0);
+ h = MAX(h, (int)conf->auto_minheight);
h = MIN(h, widget_max_height(conf) -1);
}
/* mixedgauge checksize */
if (w < max_minbarlen + 2)
RETURN_ERROR("Few cols for this mixedgauge");
- if (h < 5 + (int)nminbars/2 + (strlen(text) > 0 ? 1 : 0))
+ if (h < 5 + (int)nminibars + (strlen(text) > 0 ? 1 : 0))
RETURN_ERROR("Few rows for this mixedgauge");
if (set_widget_position(conf, &y, &x, h, w) != 0)
@@ -277,16 +282,16 @@ bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows, int cols
return output;
/* mini bars */
- for (i=0; i < (int)nminbars/2; i++) {
- miniperc = atol(minibars[i*2 + 1]);
+ for (i=0; i < (int)nminibars; i++) {
+ miniperc = minipercs[i];
if (miniperc == 8)
continue;
- mvwaddstr(widget, i+1, 2, minibars[i*2]);
- if (miniperc > 9)
- mvwaddstr(widget, i+1, w-2-15, states[10]);
- else if (miniperc >= 0 && miniperc <= 9)
+ mvwaddstr(widget, i+1, 2, minilabels[i]);
+ if (miniperc > 10)
+ mvwaddstr(widget, i+1, w-2-15, states[11]);
+ else if (miniperc >= 0 && miniperc <= 10)
mvwaddstr(widget, i+1, w-2-15, states[miniperc]);
- else { //miniperc < 0
+ else { /* miniperc < 0 */
miniperc = abs(miniperc);
mvwaddstr(widget, i+1, w-2-15, "[ ]");
draw_perc_bar(widget, i+1, 1+w-2-15, 13, miniperc,
@@ -296,7 +301,7 @@ bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows, int cols
wrefresh(widget);
ypad = y + h - 5 - htextpad;
- ypad = ypad < y+(int)nminbars/2 ? y+nminbars/2 : ypad;
+ ypad = ypad < y+(int)nminibars ? y+nminibars : ypad;
prefresh(textpad, 0, 0, ypad, x+2, y+h-4, x+w-2);
/* main bar */
@@ -315,7 +320,7 @@ bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows, int cols
delwin(bar);
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
- return BSDDIALOG_YESOK;
+ return BSDDIALOG_OK;
}
int
@@ -438,7 +443,7 @@ bsddialog_rangebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
}
break;
case KEY_F(1):
- if (conf->hfile == NULL)
+ if (conf->f1_file == NULL && conf->f1_message == NULL)
break;
if (f1help(conf) != 0)
return BSDDIALOG_ERROR;
@@ -597,7 +602,7 @@ bsddialog_pause(struct bsddialog_conf *conf, char* text, int rows, int cols,
}
break;
case KEY_F(1):
- if (conf->hfile == NULL)
+ if (conf->f1_file == NULL && conf->f1_message == NULL)
break;
if (f1help(conf) != 0)
return BSDDIALOG_ERROR;
diff --git a/lib/bsddialog.h b/lib/bsddialog.h
index de6dc100b8c3..29b9b5240706 100644
--- a/lib/bsddialog.h
+++ b/lib/bsddialog.h
@@ -30,12 +30,14 @@
#include <stdbool.h>
-#define LIBBSDDIALOG_VERSION "0.1-devel"
+#define LIBBSDDIALOG_VERSION "0.0.1"
/* Exit status */
#define BSDDIALOG_ERROR -1
-#define BSDDIALOG_YESOK 0
-#define BSDDIALOG_NOCANCEL 1
+#define BSDDIALOG_OK 0
+#define BSDDIALOG_YES BSDDIALOG_OK
+#define BSDDIALOG_CANCEL 1
+#define BSDDIALOG_NO BSDDIALOG_CANCEL
#define BSDDIALOG_HELP 2
#define BSDDIALOG_EXTRA 3
#define BSDDIALOG_ITEM_HELP 4
@@ -51,62 +53,58 @@
struct bsddialog_conf {
bool ascii_lines;
- int aspect_ratio;
- int x;
- int y;
+ unsigned int aspect_ratio;
+ unsigned int auto_minheight;
+ unsigned int auto_minwidth;
+ char *bottomtitle;
bool clear;
+ char *f1_file;
+ char *f1_message;
int *get_height;
int *get_width;
- char *hfile;
- char *hline;
bool no_lines;
bool shadow;
- int sleep;
+ unsigned int sleep;
char *title;
-
+ int y;
+ int x;
struct {
bool colors;
- /* following members could be deleted in the future */
- bool cr_wrap;
- bool no_collapse;
- bool no_nl_expand;
- bool trim;
} text;
-
struct {
bool align_left;
char *default_item;
bool no_desc;
bool no_name;
+ bool shortcut_buttons;
} menu;
-
struct {
- int securech;
+ int securech;
+ bool value_withcancel;
+ bool value_withextra;
+ bool value_withhelp;
} form;
-
struct {
+ bool without_ok;
+ char *ok_label;
+ bool with_extra;
+ char *extra_label;
+ bool without_cancel;
char *cancel_label;
- bool defaultno;
- char *default_label;
+ bool default_cancel;
+ bool with_help;
+ char *help_label;
char *exit_label;
- bool extra_button;
- char *extra_label;
char *generic1_label;
char *generic2_label;
- bool help_button;
- char *help_label;
- bool no_cancel;
- char *no_label;
- bool no_ok;
- char *ok_label;
- char *yes_label;
+ char *default_label;
} button;
};
struct bsddialog_menuitem {
char *prefix;
bool on;
- int depth;
+ unsigned int depth;
char *name;
char *desc;
char *bottomdesc;
@@ -135,21 +133,19 @@ struct bsddialog_formitem {
unsigned int fieldlen;
unsigned int maxvaluelen;
char *value; /* allocated memory */
-#define BSDDIALOG_FIELDHIDDEN 0x1
-#define BSDDIALOG_FIELDREADONLY 0x2
+#define BSDDIALOG_FIELDHIDDEN 1U
+#define BSDDIALOG_FIELDREADONLY 2U
unsigned int flags;
- char *bottomdesc; /* unimplemented for now */
+ char *bottomdesc;
};
int bsddialog_init(void);
int bsddialog_end(void);
int bsddialog_backtitle(struct bsddialog_conf *conf, char *backtitle);
+int bsddialog_initconf(struct bsddialog_conf *conf);
+int bsddialog_clearterminal(void);
const char *bsddialog_geterror(void);
-void bsddialog_initconf(struct bsddialog_conf *conf);
-/* funcs for tzsetup(8), they will be deleted */
-int bsddialog_terminalheight(void);
-int bsddialog_terminalwidth(void);
/* widgets */
int
@@ -184,8 +180,9 @@ bsddialog_menu(struct bsddialog_conf *conf, char* text, int rows, int cols,
int *focusitem);
int
-bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows, int cols,
- unsigned int mainperc, unsigned int nminbars, char **minibars);
+bsddialog_mixedgauge(struct bsddialog_conf *conf, char* text, int rows,
+ int cols, unsigned int mainperc, unsigned int nminibars, char **minilabels,
+ int *minipercs);
int
bsddialog_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
@@ -215,6 +212,7 @@ int
bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
unsigned int *hh, unsigned int *mm, unsigned int *ss);
-int bsddialog_yesno(struct bsddialog_conf *conf, char* text, int rows, int cols);
+int
+bsddialog_yesno(struct bsddialog_conf *conf, char* text, int rows, int cols);
#endif
diff --git a/lib/bsddialog_theme.h b/lib/bsddialog_theme.h
index de44b456576a..d20985e66b18 100644
--- a/lib/bsddialog_theme.h
+++ b/lib/bsddialog_theme.h
@@ -28,29 +28,16 @@
#ifndef _LIBBSDDIALOG_THEME_H_
#define _LIBBSDDIALOG_THEME_H_
-enum bsddialog_color {
- BSDDIALOG_BLACK = 0,
- BSDDIALOG_RED,
- BSDDIALOG_GREEN,
- BSDDIALOG_YELLOW,
- BSDDIALOG_BLUE,
- BSDDIALOG_MAGENTA,
- BSDDIALOG_CYAN,
- BSDDIALOG_WHITE,
-};
-
-/* f_ for focus/selected/active/current element */
+/* f_ focus/active element */
struct bsddialog_theme {
struct {
int color;
} terminal;
-
struct {
int color;
unsigned int h;
unsigned int w;
} shadow;
-
struct {
int color;
bool delimtitle;
@@ -58,33 +45,31 @@ struct bsddialog_theme {
int lineraisecolor;
int linelowercolor;
int bottomtitlecolor;
- } widget;
-
+ } dialog;
struct {
unsigned int hmargin;
} text;
-
struct {
int arrowcolor;
+ int selectorcolor;
int f_namecolor;
int namecolor;
int f_desccolor;
int desccolor;
int namesepcolor;
int descsepcolor;
+ int f_shortcutcolor;
+ int shortcutcolor;
} menu;
-
struct {
int f_fieldcolor;
int fieldcolor;
int readonlycolor;
} form;
-
struct {
int f_color;
int color;
} bar;
-
struct {
unsigned int space;
int leftch;
@@ -105,11 +90,26 @@ enum bsddialog_default_theme {
BSDDIALOG_THEME_DIALOG,
};
+enum bsddialog_color {
+ BSDDIALOG_BLACK = 0,
+ BSDDIALOG_RED,
+ BSDDIALOG_GREEN,
+ BSDDIALOG_YELLOW,
+ BSDDIALOG_BLUE,
+ BSDDIALOG_MAGENTA,
+ BSDDIALOG_CYAN,
+ BSDDIALOG_WHITE,
+};
+
+#define BSDDIALOG_BOLD 1U
+#define BSDDIALOG_REVERSE 2U
+#define BSDDIALOG_UNDERLINE 4U
+
int
bsddialog_color(enum bsddialog_color background,
- enum bsddialog_color foreground);
-struct bsddialog_theme bsddialog_get_theme(void);
-void bsddialog_set_theme(struct bsddialog_theme theme);
+ enum bsddialog_color foreground, unsigned int flags);
+int bsddialog_get_theme(struct bsddialog_theme *theme);
int bsddialog_set_default_theme(enum bsddialog_default_theme theme);
+int bsddialog_set_theme(struct bsddialog_theme *theme);
#endif
diff --git a/lib/formbox.c b/lib/formbox.c
index 70e7d9498b90..fd497174a7ce 100644
--- a/lib/formbox.c
+++ b/lib/formbox.c
@@ -57,6 +57,7 @@ struct myfield {
int size;
bool secure;
int securech;
+ char *bottomdesc;
};
#define GETMYFIELD(field) ((struct myfield*)field_userptr(field))
#define GETMYFIELD2(form) ((struct myfield*)field_userptr(current_field(form)))
@@ -91,6 +92,17 @@ static void shiftleft(struct myfield *mf)
mf->len = last;
}
+static void print_bottomdesc(struct myfield *mf)
+{
+
+ move(LINES-1, 2);
+ clrtoeol();
+ if (mf->bottomdesc != NULL) {
+ addstr(mf->bottomdesc);
+ refresh();
+ }
+}
+
static int
form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
struct buttons bs, WINDOW *formwin, FORM *form, FIELD **cfield, int nitems,
@@ -107,6 +119,7 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
form_driver(form, REQ_END_LINE);
form_driver(form, REQ_END_LINE);
mf = GETMYFIELD2(form);
+ print_bottomdesc(mf);
mf->pos = mf->len;
while(loop) {
if (buttupdate) {
@@ -121,16 +134,31 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
case 10: /* Enter */
if (informwin)
break;
+ loop = false;
output = bs.value[bs.curr];
- if (output == BSDDIALOG_YESOK) {
- form_driver(form, REQ_NEXT_FIELD);
- form_driver(form, REQ_PREV_FIELD);
- for (i=0; i<nitems; i++) {
- mf = GETMYFIELD(cfield[i]);
- items[i].value = strdup(mf->buf);
- }
+ if (output == BSDDIALOG_HELP &&
+ conf->form.value_withhelp == false)
+ break;
+ if (output == BSDDIALOG_EXTRA &&
+ conf->form.value_withextra == false)
+ break;
+ if (output == BSDDIALOG_CANCEL &&
+ conf->form.value_withcancel == false)
+ break;
+ if (output == BSDDIALOG_GENERIC1 ||
+ output == BSDDIALOG_GENERIC2)
+ break;
+
+ /* BSDDIALOG_OK */
+ form_driver(form, REQ_NEXT_FIELD);
+ form_driver(form, REQ_PREV_FIELD);
+ for (i=0; i<nitems; i++) {
+ mf = GETMYFIELD(cfield[i]);
+ items[i].value = strdup(mf->buf);
+ if (items[i].value == NULL)
+ RETURN_ERROR("Cannot allocate memory "
+ "for form value");
}
- loop = false;
break;
case 27: /* Esc */
output = BSDDIALOG_ESC;
@@ -187,6 +215,7 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
form_driver(form, REQ_PREV_FIELD);
form_driver(form, REQ_END_LINE);
mf = GETMYFIELD2(form);
+ print_bottomdesc(mf);
mf->pos = mf->len;
set_field_fore(current_field(form), t.form.f_fieldcolor);
set_field_back(current_field(form), t.form.f_fieldcolor);
@@ -199,6 +228,7 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_END_LINE);
mf = GETMYFIELD2(form);
+ print_bottomdesc(mf);
mf->pos = mf->len;
set_field_fore(current_field(form), t.form.f_fieldcolor);
set_field_back(current_field(form), t.form.f_fieldcolor);
@@ -220,7 +250,7 @@ form_handler(struct bsddialog_conf *conf, WINDOW *widget, int y, int cols,
shiftleft(mf);
break;
case KEY_F(1):
- if (conf->hfile == NULL)
+ if (conf->f1_file == NULL && conf->f1_message == NULL)
break;
if (f1help(conf) != 0)
return BSDDIALOG_ERROR;
@@ -275,6 +305,8 @@ form_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
*w += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
/* line size */
*w = MAX(*w, linelen + 3);
+ /* conf.auto_minwidth */
+ *w = MAX(*w, (int)conf->auto_minwidth);
/*
* avoid terminal overflow,
* -1 fix false negative with big menu over the terminal and
@@ -296,6 +328,8 @@ form_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
else /* h autosize with a fixed formheight */
*h = *h + *formheight + 2;
+ /* conf.auto_minheight */
+ *h = MAX(*h, (int)conf->auto_minheight);
/* avoid terminal overflow */
*h = MIN(*h, widget_max_height(conf));
}
@@ -368,6 +402,7 @@ bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
myfields[i].buf = malloc(myfields[i].size);
memset(myfields[i].buf, 0, myfields[i].size);
strcpy(myfields[i].buf, items[i].init);
+ myfields[i].bottomdesc = items[i].bottomdesc;
set_field_userptr(cfield[i], &myfields[i]);
field_opts_off(cfield[i], O_AUTOSKIP);
@@ -401,8 +436,8 @@ bsddialog_form(struct bsddialog_conf *conf, char* text, int rows, int cols,
/* disable focus with 1 item (inputbox or passwordbox) */
if (formheight == 1 && nitems == 1 && strlen(items[0].label) == 0 &&
items[0].xfield == 1 ) {
- set_field_fore(cfield[0], t.widget.color);
- set_field_back(cfield[0], t.widget.color);
+ set_field_fore(cfield[0], t.dialog.color);
+ set_field_back(cfield[0], t.dialog.color);
}
get_buttons(conf, &bs, BUTTONLABEL(ok_label), BUTTONLABEL(extra_label),
diff --git a/lib/infobox.c b/lib/infobox.c
index 304e68a62107..7752d7eec190 100644
--- a/lib/infobox.c
+++ b/lib/infobox.c
@@ -28,9 +28,9 @@
#include <sys/param.h>
#ifdef PORTNCURSES
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
#else
-#include <curses.h>
+#include <ncurses.h>
#endif
#include "bsddialog.h"
@@ -55,6 +55,8 @@ infobox_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w
if (cols == BSDDIALOG_AUTOSIZE) {
/* text size */
*w = maxline + VBORDERS + t.text.hmargin * 2;
+ /* conf.auto_minwidth */
+ *w = MAX(*w, (int)conf->auto_minwidth);
/* avoid terminal overflow */
*w = MIN(*w, widget_max_width(conf));
}
@@ -62,8 +64,10 @@ infobox_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w
if (rows == BSDDIALOG_AUTOSIZE) {
*h = MIN_HEIGHT - 1;
if (maxword > 0)
- *h += MIN(nlines, (*w / GET_ASPECT_RATIO(conf)));
+ *h += MIN(nlines, (int)(*w / GET_ASPECT_RATIO(conf)));
*h = MAX(*h, MIN_HEIGHT);
+ /* conf.auto_minheight */
+ *h = MAX(*h, (int)conf->auto_minheight);
/* avoid terminal overflow */
*h = MIN(*h, widget_max_height(conf));
}
@@ -109,6 +113,6 @@ bsddialog_infobox(struct bsddialog_conf *conf, char* text, int rows, int cols)
end_widget_withtextpad(conf, widget, h, w, textpad, shadow);
- return (BSDDIALOG_YESOK);
+ return (BSDDIALOG_OK);
}
diff --git a/lib/lib_util.c b/lib/lib_util.c
index 0751a666de92..b9bb29ba58cf 100644
--- a/lib/lib_util.c
+++ b/lib/lib_util.c
@@ -32,9 +32,9 @@
#include <unistd.h>
#ifdef PORTNCURSES
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
#else
-#include <curses.h>
+#include <ncurses.h>
#endif
#include "bsddialog.h"
@@ -83,23 +83,27 @@ int hide_widget(int y, int x, int h, int w, bool withshadow)
/* F1 help */
int f1help(struct bsddialog_conf *conf)
{
- char *file = conf->hfile;
- char *title = conf->title;
int output;
-
- conf->hfile = NULL;
- conf->clear = true;
- conf->y = BSDDIALOG_CENTER;
- conf->x = BSDDIALOG_CENTER;
- conf->title = "HELP";
- conf->sleep = 0;
-
- output = bsddialog_textbox(conf, file, BSDDIALOG_AUTOSIZE,
- BSDDIALOG_AUTOSIZE);
- conf->hfile = file;
- conf->title = title;
-
- return output;
+ struct bsddialog_conf hconf;
+
+ //memcpy(&hconf, conf, sizeof(struct bsddialog_conf));
+ bsddialog_initconf(&hconf);
+ hconf.title = "HELP";
+ hconf.button.ok_label = "EXIT";
+ hconf.clear = true;
+ hconf.ascii_lines = conf->ascii_lines;
+ hconf.no_lines = conf->no_lines;
+ hconf.shadow = conf->shadow;
+ hconf.text.colors = conf->text.colors;
+
+ output = BSDDIALOG_OK;
+ if (conf->f1_message != NULL)
+ output = bsddialog_msgbox(&hconf, conf->f1_message, 0, 0);
+
+ if (output != BSDDIALOG_ERROR && conf->f1_file != NULL)
+ output = bsddialog_textbox(&hconf, conf->f1_file, 0, 0);
+
+ return (output == BSDDIALOG_ERROR ? BSDDIALOG_ERROR : 0);
}
/* Buttons */
@@ -164,34 +168,34 @@ get_buttons(struct bsddialog_conf *conf, struct buttons *bs, char *yesoklabel,
int i;
#define SIZEBUTTON 8
#define DEFAULT_BUTTON_LABEL LABEL_ok_label
-#define DEFAULT_BUTTON_VALUE BSDDIALOG_YESOK
+#define DEFAULT_BUTTON_VALUE BSDDIALOG_OK
bs->nbuttons = 0;
bs->curr = 0;
bs->sizebutton = 0;
- if (yesoklabel != NULL && conf->button.no_ok == false) {
+ if (yesoklabel != NULL && conf->button.without_ok == false) {
bs->label[0] = yesoklabel;
- bs->value[0] = BSDDIALOG_YESOK;
+ bs->value[0] = BSDDIALOG_OK;
bs->nbuttons += 1;
}
- if (extralabel != NULL && conf->button.extra_button) {
+ if (extralabel != NULL && conf->button.with_extra) {
bs->label[bs->nbuttons] = extralabel;
bs->value[bs->nbuttons] = BSDDIALOG_EXTRA;
bs->nbuttons += 1;
}
- if (nocancellabel != NULL && conf->button.no_cancel == false) {
+ if (nocancellabel != NULL && conf->button.without_cancel == false) {
bs->label[bs->nbuttons] = nocancellabel;
- bs->value[bs->nbuttons] = BSDDIALOG_NOCANCEL;
- if (conf->button.defaultno)
+ bs->value[bs->nbuttons] = BSDDIALOG_CANCEL;
+ if (conf->button.default_cancel)
bs->curr = bs->nbuttons;
bs->nbuttons += 1;
}
- if (helplabel != NULL && conf->button.help_button) {
+ if (helplabel != NULL && conf->button.with_help) {
bs->label[bs->nbuttons] = helplabel;
bs->value[bs->nbuttons] = BSDDIALOG_HELP;
bs->nbuttons += 1;
@@ -248,7 +252,7 @@ static bool check_set_ncurses_attr(WINDOW *win, char *text)
return false;
if ((text[2] - '0') >= 0 && (text[2] - '0') < 8) {
- wattron(win, bsddialog_color( text[2] - '0', COLOR_WHITE) );
+ wattron(win, bsddialog_color( text[2] - '0', COLOR_WHITE, 0));
return true;
}
@@ -322,77 +326,24 @@ print_str(WINDOW *win, int *rows, int *y, int *x, int cols, char *str, bool colo
}
}
-static void prepare_text(struct bsddialog_conf *conf, char *text, char *buf)
-{
- int i, j;
-
- i = j = 0;
- while (text[i] != '\0') {
- switch (text[i]) {
- case '\\':
- buf[j] = '\\';
- switch (text[i+1]) {
- case '\\':
- i++;
- break;
- case 'n':
- if (conf->text.no_nl_expand) {
- j++;
- buf[j] = 'n';
- } else
- buf[j] = '\n';
- i++;
- break;
- case 't':
- if (conf->text.no_collapse) {
- j++;
- buf[j] = 't';
- } else
- buf[j] = '\t';
- i++;
- break;
- }
- break;
- case '\n':
- buf[j] = conf->text.cr_wrap ? ' ' : '\n';
- break;
- case '\t':
- buf[j] = conf->text.no_collapse ? '\t' : ' ';
- break;
- default:
- buf[j] = text[i];
- }
- i++;
- j += (buf[j] == ' ' && conf->text.trim && j > 0 && buf[j-1] == ' ') ?
- 0 : 1;
- }
- buf[j] = '\0';
-}
-
int
get_text_properties(struct bsddialog_conf *conf, char *text, int *maxword,
int *maxline, int *nlines)
{
- char *buf;
int i, buflen, wordlen, linelen;
- if ((buf = malloc(strlen(text) + 1)) == NULL)
- RETURN_ERROR("Cannot building a buffer to find the properties "\
- "of the text properties");
- prepare_text(conf, text, buf);
-
- buflen = strlen(buf) + 1;
+ buflen = strlen(text) + 1;
*maxword = 0;
wordlen = 0;
for (i=0; i < buflen; i++) {
- if (buf[i] == '\t' || buf[i] == '\n' || buf[i] == ' ' || buf[i] == '\0')
+ if (text[i] == '\t' || text[i] == '\n' || text[i] == ' ' || text[i] == '\0')
if (wordlen != 0) {
*maxword = MAX(*maxword, wordlen);
wordlen = 0;
continue;
}
- if (conf->text.colors && is_ncurses_attr(buf + i))
+ if (conf->text.colors && is_ncurses_attr(text + i))
i += 3;
else
wordlen++;
@@ -401,7 +352,7 @@ get_text_properties(struct bsddialog_conf *conf, char *text, int *maxword,
*maxline = linelen = 0;
*nlines = 1;
for (i=0; i < buflen; i++) {
- switch (buf[i]) {
+ switch (text[i]) {
case '\n':
*nlines = *nlines + 1;
case '\0':
@@ -409,7 +360,7 @@ get_text_properties(struct bsddialog_conf *conf, char *text, int *maxword,
linelen = 0;
break;
default:
- if (conf->text.colors && is_ncurses_attr(buf + i))
+ if (conf->text.colors && is_ncurses_attr(text + i))
i += 3;
else
linelen++;
@@ -418,7 +369,7 @@ get_text_properties(struct bsddialog_conf *conf, char *text, int *maxword,
if (*nlines == 1 && *maxline == 0)
*nlines = 0;
- free(buf);
+ //free(buf);
return 0;
}
@@ -427,33 +378,28 @@ int
print_textpad(struct bsddialog_conf *conf, WINDOW *pad, int *rows, int cols,
char *text)
{
- char *buf, *string;
+ char *string;
int i, j, x, y;
bool loop;
- if ((buf = malloc(strlen(text) + 1)) == NULL)
+ if ((string = malloc(strlen(text) + 1)) == NULL)
RETURN_ERROR("Cannot build (analyze) text");
- prepare_text(conf, text, buf);
-
- if ((string = malloc(strlen(text) + 1)) == NULL) {
- free(buf);
- RETURN_ERROR("Cannot build (analyze) text");
- }
i = j = x = y = 0;
loop = true;
while (loop) {
- string[j] = buf[i];
+ string[j] = text[i];
if (string[j] == '\0' || string[j] == '\n' ||
string[j] == '\t' || string[j] == ' ') {
if (j != 0) {
string[j] = '\0';
- print_str(pad, rows, &y, &x, cols, string, conf->text.colors);
+ print_str(pad, rows, &y, &x, cols, string,
+ conf->text.colors);
}
}
- switch (buf[i]) {
+ switch (text[i]) {
case '\0':
loop = false;
break;
@@ -491,7 +437,6 @@ print_textpad(struct bsddialog_conf *conf, WINDOW *pad, int *rows, int cols,
}
free(string);
- free(buf);
return 0;
}
@@ -626,8 +571,10 @@ draw_borders(struct bsddialog_conf *conf, WINDOW *win, int rows, int cols,
ts = bs = '-';
tl = tr = bl = br = ltee = rtee = '+';
}
- leftcolor = elev == RAISED ? t.widget.lineraisecolor : t.widget.linelowercolor;
- rightcolor = elev == RAISED ? t.widget.linelowercolor : t.widget.lineraisecolor;
+ leftcolor = elev == RAISED ?
+ t.dialog.lineraisecolor : t.dialog.linelowercolor;
+ rightcolor = elev == RAISED ?
+ t.dialog.linelowercolor : t.dialog.lineraisecolor;
wattron(win, leftcolor);
wborder(win, ls, rs, ts, bs, tl, tr, bl, br);
wattroff(win, leftcolor);
@@ -652,7 +599,7 @@ new_boxed_window(struct bsddialog_conf *conf, int y, int x, int rows, int cols,
return NULL;
}
- wbkgd(win, t.widget.color);
+ wbkgd(win, t.dialog.color);
draw_borders(conf, win, rows, cols, elev);
@@ -669,12 +616,13 @@ draw_widget_withtextpad(struct bsddialog_conf *conf, WINDOW *shadow,
WINDOW *textpad, int *htextpad, char *text, bool buttons)
{
int ts, ltee, rtee;
- int colorsurroundtitle;
+ int colordelimtitle;
ts = conf->ascii_lines ? '-' : ACS_HLINE;
ltee = conf->ascii_lines ? '+' : ACS_LTEE;
rtee = conf->ascii_lines ? '+' : ACS_RTEE;
- colorsurroundtitle = elev == RAISED ? t.widget.lineraisecolor : t.widget.linelowercolor;
+ colordelimtitle = elev == RAISED ?
+ t.dialog.lineraisecolor : t.dialog.linelowercolor;
if (shadow != NULL)
wnoutrefresh(shadow);
@@ -683,42 +631,42 @@ draw_widget_withtextpad(struct bsddialog_conf *conf, WINDOW *shadow,
draw_borders(conf, widget, h, w, elev);
if (conf->title != NULL) {
- if (t.widget.delimtitle && conf->no_lines == false) {
- wattron(widget, colorsurroundtitle);
+ if (t.dialog.delimtitle && conf->no_lines == false) {
+ wattron(widget, colordelimtitle);
mvwaddch(widget, 0, w/2 - strlen(conf->title)/2 - 1, rtee);
- wattroff(widget, colorsurroundtitle);
+ wattroff(widget, colordelimtitle);
}
- wattron(widget, t.widget.titlecolor);
+ wattron(widget, t.dialog.titlecolor);
mvwaddstr(widget, 0, w/2 - strlen(conf->title)/2, conf->title);
- wattroff(widget, t.widget.titlecolor);
- if (t.widget.delimtitle && conf->no_lines == false) {
- wattron(widget, colorsurroundtitle);
+ wattroff(widget, t.dialog.titlecolor);
+ if (t.dialog.delimtitle && conf->no_lines == false) {
+ wattron(widget, colordelimtitle);
waddch(widget, ltee);
- wattroff(widget, colorsurroundtitle);
+ wattroff(widget, colordelimtitle);
}
}
- if (conf->hline != NULL) {
- wattron(widget, t.widget.bottomtitlecolor);
- wmove(widget, h - 1, w/2 - strlen(conf->hline)/2 - 1);
+ if (conf->bottomtitle != NULL) {
+ wattron(widget, t.dialog.bottomtitlecolor);
+ wmove(widget, h - 1, w/2 - strlen(conf->bottomtitle)/2 - 1);
waddch(widget, '[');
- waddstr(widget, conf->hline);
+ waddstr(widget, conf->bottomtitle);
waddch(widget, ']');
- wattroff(widget, t.widget.bottomtitlecolor);
+ wattroff(widget, t.dialog.bottomtitlecolor);
}
//if (textpad == NULL && text != NULL) /* no pad, text null for textbox */
// print_text(conf, widget, 1, 2, w-3, text);
if (buttons && conf->no_lines == false) {
- wattron(widget, t.widget.lineraisecolor);
+ wattron(widget, t.dialog.lineraisecolor);
mvwaddch(widget, h-3, 0, ltee);
mvwhline(widget, h-3, 1, ts, w-2);
- wattroff(widget, t.widget.lineraisecolor);
+ wattroff(widget, t.dialog.lineraisecolor);
- wattron(widget, t.widget.linelowercolor);
+ wattron(widget, t.dialog.linelowercolor);
mvwaddch(widget, h-3, w-1, rtee);
- wattroff(widget, t.widget.linelowercolor);
+ wattroff(widget, t.dialog.linelowercolor);
}
wnoutrefresh(widget);
@@ -792,7 +740,7 @@ new_widget_withtextpad(struct bsddialog_conf *conf, WINDOW **shadow,
delwin(*shadow);
RETURN_ERROR("Cannot build the pad window for text");
}
- wbkgd(*textpad, t.widget.color);
+ wbkgd(*textpad, t.dialog.color);
}
error = draw_widget_withtextpad(conf, *shadow, *widget, h, w, elev,
diff --git a/lib/lib_util.h b/lib/lib_util.h
index b3598e900e9e..2c552a36c6a9 100644
--- a/lib/lib_util.h
+++ b/lib/lib_util.h
@@ -61,9 +61,7 @@ void set_error_string(char *string);
#define LABEL_exit_label "EXIT"
#define LABEL_extra_label "Extra"
#define LABEL_help_label "Help"
-#define LABEL_no_label "No"
#define LABEL_ok_label "OK"
-#define LABEL_yes_label "Yes"
#define BUTTONLABEL(l) (conf->button.l != NULL ? conf->button.l : LABEL_ ##l)
#define MAXBUTTONS 6 /* yes|ok + extra + no|cancel + help + 2 generics */
diff --git a/lib/libbsddialog.c b/lib/libbsddialog.c
index bcc811a02e45..a3cbe6bf9748 100644
--- a/lib/libbsddialog.c
+++ b/lib/libbsddialog.c
@@ -30,9 +30,9 @@
#include <unistd.h>
#ifdef PORTNCURSES
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
#else
-#include <curses.h>
+#include <ncurses.h>
#endif
#include "bsddialog.h"
@@ -40,10 +40,10 @@
#include "bsddialog_theme.h"
/*
- * This file implements some public function not related to a specific widget.
- * utils.h/c provides private functions to implement the library.
- * theme.h/c is public API related to theme.
- * Widgets implementation:
+ * This file implements public functions not related to a specific dialog.
+ * utils.h/c: private functions to implement the library.
+ * theme.h/c: public API related to themes.
+ * Dialogs implementation:
* infobox.c infobox
* messgebox.c msgbox - yesno
* menubox.c buildlist - checklist - menu - mixedlist - radiolist
@@ -85,10 +85,12 @@ int bsddialog_init(void)
RETURN_ERROR("Cannot init ncurses (colors)");
}
- if (bsddialog_set_default_theme(BSDDIALOG_THEME_DIALOG) != 0)
- error = BSDDIALOG_ERROR;
+ if (bsddialog_set_default_theme(BSDDIALOG_THEME_DEFAULT) != 0) {
+ bsddialog_end();
+ return (BSDDIALOG_ERROR);
+ }
- return error;
+ return (0);
}
int bsddialog_end(void)
@@ -97,7 +99,7 @@ int bsddialog_end(void)
if (endwin() != OK)
RETURN_ERROR("Cannot end ncurses (endwin)");
- return 0;
+ return (0);
}
int bsddialog_backtitle(struct bsddialog_conf *conf, char *backtitle)
@@ -109,31 +111,37 @@ int bsddialog_backtitle(struct bsddialog_conf *conf, char *backtitle)
refresh();
- return 0;
+ return (0);
}
const char *bsddialog_geterror(void)
{
- return get_error_string();
+ return (get_error_string());
}
-int bsddialog_terminalheight(void)
+int bsddialog_initconf(struct bsddialog_conf *conf)
{
- return LINES;
-}
+ if (conf == NULL)
+ RETURN_ERROR("conf is NULL");
+ if (sizeof(*conf) != sizeof(struct bsddialog_conf))
+ RETURN_ERROR("Bad conf size");
-int bsddialog_terminalwidth(void)
-{
+ memset(conf, 0, sizeof(struct bsddialog_conf));
+ conf->y = BSDDIALOG_CENTER;
+ conf->x = BSDDIALOG_CENTER;
+ conf->shadow = true;
- return COLS;
+ return (0);
}
-void bsddialog_initconf(struct bsddialog_conf *conf)
+int bsddialog_clearterminal(void)
{
- memset(conf, 0, sizeof(struct bsddialog_conf));
- conf->x = conf->y = BSDDIALOG_CENTER;
- conf->shadow = true;
+ if (clear() != OK)
+ RETURN_ERROR("Cannot clear the terminal");
+ refresh();
+
+ return (0);
}
diff --git a/lib/menubox.c b/lib/menubox.c
index 72038d4b0246..147fa66c8c27 100644
--- a/lib/menubox.c
+++ b/lib/menubox.c
@@ -31,9 +31,9 @@
#include <string.h>
#ifdef PORTNCURSES
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
#else
-#include <curses.h>
+#include <ncurses.h>
#endif
#include "bsddialog.h"
@@ -271,6 +271,61 @@ getfastprev(int menurows, struct bsddialog_menugroup *groups, int *abs,
} while (*abs != a && *abs > start - menurows && i > 0);
}
+static bool
+getnextshortcut(struct bsddialog_conf *conf, enum menumode mode, int ngroups,
+ struct bsddialog_menugroup *groups, int *abs, int *group, int *rel,
+ int key)
+{
+ int i, j, a, ch, ng, nr, na;
+ bool mainloop;
+
+ if (*abs < 0 || ngroups < 0 || *rel < 0 || mode == BUILDLISTMODE)
+ return false;
+
+ na = a = -1;
+ mainloop = true;
+ for (i = 0; i < ngroups && mainloop; i++) {
+ if (groups[i].type == BSDDIALOG_SEPARATOR) {
+ a += groups[i].nitems;
+ continue;
+ }
+ for (j = 0; j < (int)groups[i].nitems; j++) {
+ a++;
+ if (a == *abs)
+ continue;
+
+ if (conf->menu.no_name)
+ ch = groups[i].items[j].desc[0];
+ else
+ ch = groups[i].items[j].name[0];
+
+ if (ch == key) {
+ if (a < *abs && na == -1) {
+ na = a;
+ ng = i;
+ nr = j;
+ }
+ if (a > *abs) {
+ na = a;
+ ng = i;
+ nr = j;
+ mainloop = false;
+ break;
+ }
+ }
+ }
+ }
+
+ if (na != -1) {
+ *abs = na;
+ *group = ng;
+ *rel = nr;
+ return (true);
+ }
+
+ return (false);
+}
+
static enum menumode
getmode(enum menumode mode, struct bsddialog_menugroup group)
{
@@ -292,10 +347,8 @@ drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
struct bsddialog_menuitem item, enum menumode mode, struct lineposition pos,
bool curr)
{
- int color, colorname, linech;
-
- color = curr ? t.menu.f_desccolor : t.menu.desccolor;
- colorname = curr ? t.menu.f_namecolor : t.menu.namecolor;
+ int colordesc, colorname, colorshortcut, linech;
+ char *shortcut;
if (mode == SEPARATORMODE) {
if (conf->no_lines == false) {
@@ -322,14 +375,15 @@ drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
/* selector */
wmove(pad, y, pos.xselector);
- wattron(pad, color);
+ wattron(pad, t.menu.selectorcolor);
if (mode == CHECKLISTMODE)
wprintw(pad, "[%c]", item.on ? 'X' : ' ');
if (mode == RADIOLISTMODE)
wprintw(pad, "(%c)", item.on ? '*' : ' ');
- wattroff(pad, color);
+ wattroff(pad, t.menu.selectorcolor);
/* name */
+ colorname = curr ? t.menu.f_namecolor : t.menu.namecolor;
if (mode != BUILDLISTMODE && conf->menu.no_name == false) {
wattron(pad, colorname);
mvwaddstr(pad, y, pos.xname + item.depth * DEPTHSPACE, item.name);
@@ -337,23 +391,47 @@ drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
}
/* description */
- if (conf->menu.no_desc == false) {
- if ((mode == BUILDLISTMODE || conf->menu.no_name) && curr == false)
- color = item.on ? t.menu.namecolor : t.menu.desccolor;
- wattron(pad, color);
+ if (mode == BUILDLISTMODE) {
+ if (curr == false)
+ colordesc = item.on ? t.menu.namecolor : t.menu.desccolor;
+ else
+ colordesc = t.menu.f_namecolor;
+ }
+ else {
+ if (conf->menu.no_name)
+ colordesc = curr ? t.menu.f_namecolor : t.menu.namecolor;
+ else
+ colordesc = curr ? t.menu.f_desccolor : t.menu.desccolor;
+ }
+ if (mode == BUILDLISTMODE || conf->menu.no_desc == false) {
+ wattron(pad, colordesc);
if (conf->menu.no_name)
mvwaddstr(pad, y, pos.xname + item.depth * DEPTHSPACE, item.desc);
else
mvwaddstr(pad, y, pos.xdesc, item.desc);
- wattroff(pad, color);
+ wattroff(pad, colordesc);
}
- /* bottom desc (item help) */
- if (item.bottomdesc != NULL && item.bottomdesc[0] != '\0') {
- move(LINES-1, 2);
- clrtoeol();
- addstr(item.bottomdesc);
+ /* shortcut */
+ if (mode != BUILDLISTMODE && conf->menu.shortcut_buttons == false) {
+ colorshortcut = curr ? t.menu.f_shortcutcolor : t.menu.shortcutcolor;
+ wattron(pad, colorshortcut);
+
+ if (conf->menu.no_name)
+ shortcut = item.desc;
+ else
+ shortcut = item.name;
+ wmove(pad, y, pos.xname + item.depth * DEPTHSPACE);
+ if (shortcut != NULL && shortcut[0] != '\0')
+ waddch(pad, shortcut[0]);
+ wattroff(pad, colorshortcut);
+}
+ /* bottom description */
+ move(LINES-1, 2);
+ clrtoeol();
+ if (item.bottomdesc != NULL) {
+ addstr(item.bottomdesc);
refresh();
}
}
@@ -374,6 +452,8 @@ menu_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
*w += bs.nbuttons > 0 ? (bs.nbuttons-1) * t.button.space : 0;
/* line size */
*w = MAX(*w, linelen + 6);
+ /* conf.auto_minwidth */
+ *w = MAX(*w, (int)conf->auto_minwidth);
/*
* avoid terminal overflow,
* -1 fix false negative with big menu over the terminal and
@@ -395,8 +475,13 @@ menu_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
else /* h autosize with a fixed menurows */
*h = *h + *menurows + 2;
+ /* conf.auto_minheight */
+ *h = MAX(*h, (int)conf->auto_minheight);
/* avoid terminal overflow */
*h = MIN(*h, widget_max_height(conf));
+ /* avoid menurows overflow */
+ /* manual: with rows=autosize menurows!=0 is maxmenurows */
+ *menurows = MIN(*h - 6 - textrow, (int)*menurows);
}
else {
if (*menurows == 0)
@@ -440,9 +525,9 @@ update_menuwin(struct bsddialog_conf *conf, WINDOW *menuwin, int h, int w,
int totnitems, unsigned int menurows, int ymenupad)
{
- if (totnitems > (int) menurows) {
- draw_borders(conf, menuwin, h, w, LOWERED);
+ draw_borders(conf, menuwin, h, w, LOWERED);
+ if (totnitems > (int) menurows) {
wattron(menuwin, t.menu.arrowcolor);
if (ymenupad > 0)
@@ -466,12 +551,14 @@ do_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
WINDOW *shadow, *widget, *textpad, *menuwin, *menupad;
int i, j, y, x, h, w, htextpad, output, input;
int ymenupad, ys, ye, xs, xe, abs, g, rel, totnitems;
- bool loop, automenurows;
+ bool loop, automenurows, shortcut_buttons;
struct buttons bs;
struct bsddialog_menuitem *item;
enum menumode currmode;
struct lineposition pos = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
+
+ shortcut_buttons = conf->menu.shortcut_buttons;
+
automenurows = menurows == BSDDIALOG_AUTOSIZE ? true : false;
totnitems = 0;
@@ -497,7 +584,7 @@ do_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
}
pos.maxprefix = MAX(pos.maxprefix, strlen(item->prefix));
- pos.maxdepth = MAX((int) pos.maxdepth, item->depth);
+ pos.maxdepth = MAX(pos.maxdepth, item->depth);
pos.maxname = MAX(pos.maxname, strlen(item->name));
pos.maxdesc = MAX(pos.maxdesc, strlen(item->desc));
}
@@ -536,19 +623,22 @@ do_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
menurows+2, w-4, LOWERED);
menupad = newpad(totnitems, pos.line);
- wbkgd(menupad, t.widget.color);
+ wbkgd(menupad, t.dialog.color);
- getfirst_with_default(conf, ngroups, groups, &abs, &g, &rel);
ymenupad = 0;
for (i=0; i<ngroups; i++) {
currmode = getmode(mode, groups[i]);
for (j=0; j < (int) groups[i].nitems; j++) {
item = &groups[i].items[j];
- drawitem(conf, menupad, ymenupad, *item, currmode,
- pos, ymenupad == abs);
+ drawitem(conf, menupad, ymenupad, *item, currmode, pos,
+ false);
ymenupad++;
}
}
+ getfirst_with_default(conf, ngroups, groups, &abs, &g, &rel);
+ currmode = getmode(mode, groups[g]);
+ item = &groups[g].items[rel];
+ drawitem(conf, menupad, abs, *item, currmode, pos, true);
ys = y + h - 5 - menurows + 1;
ye = y + h - 5 ;
@@ -568,11 +658,9 @@ do_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
wrefresh(menuwin);
prefresh(menupad, ymenupad, 0, ys, xs, ye, xe);
- draw_buttons(widget, h-2, w, bs, true);
+ draw_buttons(widget, h-2, w, bs, shortcut_buttons);
wrefresh(widget);
- item = &groups[g].items[rel];
- currmode = getmode(mode, groups[g]);
loop = true;
while(loop) {
input = getch();
@@ -590,26 +678,26 @@ do_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
break;
case '\t': /* TAB */
bs.curr = (bs.curr + 1) % bs.nbuttons;
- draw_buttons(widget, h-2, w, bs, true);
+ draw_buttons(widget, h-2, w, bs, shortcut_buttons);
wrefresh(widget);
break;
case KEY_LEFT:
if (bs.curr > 0) {
bs.curr--;
- draw_buttons(widget, h-2, w, bs, true);
+ draw_buttons(widget, h-2, w, bs, shortcut_buttons);
wrefresh(widget);
}
break;
case KEY_RIGHT:
if (bs.curr < (int) bs.nbuttons - 1) {
bs.curr++;
- draw_buttons(widget, h-2, w, bs, true);
+ draw_buttons(widget, h-2, w, bs, shortcut_buttons);
wrefresh(widget);
}
break;
case KEY_CTRL('E'): /* add conf->menu.extrahelpkey ? */
case KEY_F(1):
- if (conf->hfile == NULL)
+ if (conf->f1_file == NULL && conf->f1_message == NULL)
break;
if (f1help(conf) != 0)
return BSDDIALOG_ERROR;
@@ -649,7 +737,7 @@ do_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
RAISED, textpad, &htextpad, text, true) != 0)
return BSDDIALOG_ERROR;
- draw_buttons(widget, h-2, w, bs, true);
+ draw_buttons(widget, h-2, w, bs, shortcut_buttons);
wrefresh(widget);
prefresh(textpad, 0, 0, y + 1, x + 1 + t.text.hmargin,
@@ -680,12 +768,6 @@ do_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
refresh();
break;
- default:
- for (i = 0; i < (int) bs.nbuttons; i++)
- if (tolower(input) == tolower((bs.label[i])[0])) {
- output = bs.value[i];
- loop = false;
- }
}
if (abs < 0)
@@ -752,6 +834,32 @@ do_mixedlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
}
drawitem(conf, menupad, abs, *item, currmode, pos, true);
prefresh(menupad, ymenupad, 0, ys, xs, ye, xe);
+ default:
+ if (shortcut_buttons) {
+ for (i = 0; i < (int) bs.nbuttons; i++)
+ if (tolower(input) == tolower((bs.label[i])[0])) {
+ output = bs.value[i];
+ if (currmode == MENUMODE)
+ item->on = true;
+ loop = false;
+ }
+ break;
+ }
+
+ drawitem(conf, menupad, abs, *item, currmode, pos, false);
+ getnextshortcut(conf, currmode, ngroups, groups, &abs,
+ &g, &rel, input);
+ item = &groups[g].items[rel];
+ currmode = getmode(mode, groups[g]);
+ drawitem(conf, menupad, abs, *item, currmode, pos, true);
+ if (ymenupad > abs && ymenupad > 0)
+ ymenupad = abs;
+ if ((int)(ymenupad + menurows) <= abs)
+ ymenupad = abs - menurows + 1;
+ update_menuwin(conf, menuwin, menurows+2, w-4, totnitems,
+ menurows, ymenupad);
+ wrefresh(menuwin);
+ prefresh(menupad, ymenupad, 0, ys, xs, ye, xe);
}
}
@@ -926,8 +1034,8 @@ bsddialog_buildlist(struct bsddialog_conf *conf, char* text, int rows, int cols,
padscols = (w-5)/2 - 2;
leftpad = newpad(nitems, pos.line);
rightpad = newpad(nitems, pos.line);
- wbkgd(leftpad, t.widget.color);
- wbkgd(rightpad, t.widget.color);
+ wbkgd(leftpad, t.dialog.color);
+ wbkgd(rightpad, t.dialog.color);
currH = 0;
currV = startleft ? LEFT : RIGHT;
diff --git a/lib/messagebox.c b/lib/messagebox.c
index 0f04eed11473..e2b91e1bdc5c 100644
--- a/lib/messagebox.c
+++ b/lib/messagebox.c
@@ -31,9 +31,9 @@
#include <string.h>
#ifdef PORTNCURSES
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
#else
-#include <curses.h>
+#include <ncurses.h>
#endif
#include "bsddialog.h"
@@ -70,6 +70,8 @@ message_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w
line = MIN(maxline + VBORDERS + t.text.hmargin * 2, AUTO_WIDTH);
line = MAX(line, (int) (maxword + VBORDERS + t.text.hmargin * 2));
*w = MAX(*w, line);
+ /* conf.auto_minwidth */
+ *w = MAX(*w, (int)conf->auto_minwidth);
/* avoid terminal overflow */
*w = MIN(*w, widget_max_width(conf));
}
@@ -77,8 +79,10 @@ message_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w
if (rows == BSDDIALOG_AUTOSIZE) {
*h = MIN_HEIGHT - 1;
if (maxword > 0)
- *h += MAX(nlines, (*w / GET_ASPECT_RATIO(conf)));
+ *h += MAX(nlines, (int)(*w / GET_ASPECT_RATIO(conf)));
*h = MAX(*h, MIN_HEIGHT);
+ /* conf.auto_minheight */
+ *h = MAX(*h, (int)conf->auto_minheight);
/* avoid terminal overflow */
*h = MIN(*h, widget_max_height(conf));
}
@@ -167,7 +171,7 @@ do_widget(struct bsddialog_conf *conf, char *text, int rows, int cols,
buttonsupdate(widget, h, w, bs, shortkey);
break;
case KEY_F(1):
- if (conf->hfile == NULL)
+ if (conf->f1_file == NULL && conf->f1_message == NULL)
break;
if (f1help(conf) != 0)
return BSDDIALOG_ERROR;
@@ -271,8 +275,11 @@ bsddialog_yesno(struct bsddialog_conf *conf, char* text, int rows, int cols)
{
struct buttons bs;
- get_buttons(conf, &bs, BUTTONLABEL(yes_label), BUTTONLABEL(extra_label),
- BUTTONLABEL(no_label), BUTTONLABEL(help_label));
+ get_buttons(conf, &bs,
+ conf->button.ok_label == NULL ? "Yes" : conf->button.ok_label,
+ BUTTONLABEL(extra_label),
+ conf->button.cancel_label == NULL ? "No" : conf->button.cancel_label,
+ BUTTONLABEL(help_label));
return (do_widget(conf, text, rows, cols, bs, true));
}
diff --git a/lib/textbox.c b/lib/textbox.c
index 481256fefc8a..22dd21470c3a 100644
--- a/lib/textbox.c
+++ b/lib/textbox.c
@@ -31,9 +31,9 @@
#include <string.h>
#ifdef PORTNCURSES
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
#else
-#include <curses.h>
+#include <ncurses.h>
#endif
#include "bsddialog.h"
@@ -42,7 +42,7 @@
/* "Text": textbox */
-#define BUTTON_TEXTBOX "HELP"
+#define BUTTON_TEXTBOX "EXIT"
extern struct bsddialog_theme t;
@@ -57,12 +57,16 @@ textbox_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w
*w += strlen(BUTTON_TEXTBOX) + 2 /* text delims*/;
/* text size */
*w = MAX(*w, wpad + VBORDERS);
+ /* conf.auto_minwidth */
+ *w = MAX(*w, (int)conf->auto_minwidth);
/* avoid terminal overflow */
*w = MIN(*w, widget_max_width(conf)-1); /* again -1, fix util.c */
}
if (rows == BSDDIALOG_AUTOSIZE) {
*h = hpad + 4; /* HBORDERS + button border */
+ /* conf.auto_minheight */
+ *h = MAX(*h, (int)conf->auto_minheight);
/* avoid terminal overflow */
*h = MIN(*h, widget_max_height(conf));
}
@@ -99,7 +103,7 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
hpad = 1;
wpad = 1;
pad = newpad(hpad, wpad);
- wbkgd(pad, t.widget.color);
+ wbkgd(pad, t.dialog.color);
i = 0;
while(fgets(buf, BUFSIZ, fp) != NULL) {
if ((int) strlen(buf) > wpad) {
@@ -146,7 +150,7 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
switch(input) {
case KEY_ENTER:
case 10: /* Enter */
- output = BSDDIALOG_YESOK;
+ output = BSDDIALOG_OK;
loop = false;
break;
case 27: /* Esc */
@@ -187,7 +191,7 @@ bsddialog_textbox(struct bsddialog_conf *conf, char* file, int rows, int cols)
ypad = ypad + printrows <= hpad -1 ? ypad + 1 : ypad;
break;
case KEY_F(1):
- if (conf->hfile == NULL)
+ if (conf->f1_file == NULL && conf->f1_message == NULL)
break;
if (f1help(conf) != 0)
return BSDDIALOG_ERROR;
diff --git a/lib/theme.c b/lib/theme.c
index f204729ab4c1..3bcd8ee8fc53 100644
--- a/lib/theme.c
+++ b/lib/theme.c
@@ -26,9 +26,9 @@
*/
#ifdef PORTNCURSES
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
#else
-#include <curses.h>
+#include <ncurses.h>
#endif
#include "bsddialog.h"
@@ -42,27 +42,31 @@ struct bsddialog_theme t;
static struct bsddialog_theme bsddialogtheme = {
#define bgwidget COLOR_WHITE
#define bgcurr COLOR_YELLOW
- .shadow.color = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
- .shadow.h = 1,
- .shadow.w = 2,
-
- .terminal.color = GET_COLOR(COLOR_BLACK, COLOR_CYAN),
- .widget.delimtitle = true,
- .widget.titlecolor = GET_COLOR(COLOR_YELLOW, bgwidget),
- .widget.lineraisecolor = GET_COLOR(COLOR_BLACK, bgwidget),
- .widget.linelowercolor = GET_COLOR(COLOR_BLACK, bgwidget),
- .widget.color = GET_COLOR(COLOR_BLACK, bgwidget),
- .widget.bottomtitlecolor = GET_COLOR(COLOR_BLACK, bgwidget),
+ .terminal.color = GET_COLOR(COLOR_BLACK, COLOR_CYAN),
+
+ .shadow.color = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
+ .shadow.h = 1,
+ .shadow.w = 2,
+
+ .dialog.delimtitle = true,
+ .dialog.titlecolor = GET_COLOR(COLOR_YELLOW, bgwidget),
+ .dialog.lineraisecolor = GET_COLOR(COLOR_BLACK, bgwidget),
+ .dialog.linelowercolor = GET_COLOR(COLOR_BLACK, bgwidget),
+ .dialog.color = GET_COLOR(COLOR_BLACK, bgwidget),
+ .dialog.bottomtitlecolor = GET_COLOR(COLOR_BLACK, bgwidget),
.text.hmargin = 1,
- .menu.arrowcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
- .menu.f_desccolor = GET_COLOR(COLOR_WHITE, bgcurr),
- .menu.desccolor = GET_COLOR(COLOR_BLACK, bgwidget),
- .menu.f_namecolor = GET_COLOR(COLOR_BLACK, bgcurr),
- .menu.namecolor = GET_COLOR(COLOR_YELLOW, bgwidget),
- .menu.namesepcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
- .menu.descsepcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
+ .menu.arrowcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
+ .menu.selectorcolor = GET_COLOR(COLOR_BLACK, bgwidget) | A_BOLD,
+ .menu.f_desccolor = GET_COLOR(COLOR_WHITE, bgcurr),
+ .menu.desccolor = GET_COLOR(COLOR_BLACK, bgwidget),
+ .menu.f_namecolor = GET_COLOR(COLOR_BLACK, bgcurr),
+ .menu.namecolor = GET_COLOR(COLOR_YELLOW, bgwidget),
+ .menu.namesepcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
+ .menu.descsepcolor = GET_COLOR(COLOR_YELLOW, bgwidget),
+ .menu.f_shortcutcolor = GET_COLOR(COLOR_RED, bgcurr),
+ .menu.shortcutcolor = GET_COLOR(COLOR_RED, bgwidget),
.form.f_fieldcolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE),
.form.fieldcolor = GET_COLOR(COLOR_WHITE, COLOR_CYAN),
@@ -85,27 +89,31 @@ static struct bsddialog_theme bsddialogtheme = {
static struct bsddialog_theme blackwhite = {
#define bk COLOR_BLACK
#define fg COLOR_WHITE
- .shadow.color = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
- .shadow.h = 1,
- .shadow.w = 2,
-
- .terminal.color = GET_COLOR(fg, bk),
- .widget.delimtitle = true,
- .widget.titlecolor = GET_COLOR(fg, bk),
- .widget.lineraisecolor = GET_COLOR(fg, bk),
- .widget.linelowercolor = GET_COLOR(fg, bk),
- .widget.color = GET_COLOR(fg, bk),
- .widget.bottomtitlecolor = GET_COLOR(fg, bk),
+ .terminal.color = GET_COLOR(fg, bk),
+
+ .shadow.color = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
+ .shadow.h = 1,
+ .shadow.w = 2,
+
+ .dialog.delimtitle = true,
+ .dialog.titlecolor = GET_COLOR(fg, bk),
+ .dialog.lineraisecolor = GET_COLOR(fg, bk),
+ .dialog.linelowercolor = GET_COLOR(fg, bk),
+ .dialog.color = GET_COLOR(fg, bk),
+ .dialog.bottomtitlecolor = GET_COLOR(fg, bk),
.text.hmargin = 1,
- .menu.arrowcolor = GET_COLOR(fg, bk),
- .menu.f_desccolor = GET_COLOR(fg, bk) | A_REVERSE,
- .menu.desccolor = GET_COLOR(fg, bk),
- .menu.f_namecolor = GET_COLOR(fg, bk) | A_REVERSE,
- .menu.namecolor = GET_COLOR(fg, bk),
- .menu.namesepcolor = GET_COLOR(fg, bk),
- .menu.descsepcolor = GET_COLOR(fg, bk),
+ .menu.arrowcolor = GET_COLOR(fg, bk),
+ .menu.selectorcolor = GET_COLOR(fg, bk),
+ .menu.f_desccolor = GET_COLOR(fg, bk) | A_REVERSE,
+ .menu.desccolor = GET_COLOR(fg, bk),
+ .menu.f_namecolor = GET_COLOR(fg, bk) | A_REVERSE,
+ .menu.namecolor = GET_COLOR(fg, bk),
+ .menu.namesepcolor = GET_COLOR(fg, bk),
+ .menu.descsepcolor = GET_COLOR(fg, bk),
+ .menu.f_shortcutcolor = GET_COLOR(fg, bk) | A_UNDERLINE | A_REVERSE,
+ .menu.shortcutcolor = GET_COLOR(fg, bk) | A_UNDERLINE,
.form.f_fieldcolor = GET_COLOR(fg, bk) | A_REVERSE,
.form.fieldcolor = GET_COLOR(fg, bk),
@@ -126,27 +134,31 @@ static struct bsddialog_theme blackwhite = {
};
static struct bsddialog_theme dialogtheme = {
- .shadow.color = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
- .shadow.h = 1,
- .shadow.w = 2,
-
- .terminal.color = GET_COLOR(COLOR_CYAN, COLOR_BLUE) | A_BOLD,
- .widget.delimtitle = false,
- .widget.titlecolor = GET_COLOR(COLOR_BLUE, COLOR_WHITE) | A_BOLD,
- .widget.lineraisecolor = GET_COLOR(COLOR_WHITE, COLOR_WHITE) | A_BOLD,
- .widget.linelowercolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
- .widget.color = GET_COLOR(COLOR_BLACK, COLOR_WHITE),
- .widget.bottomtitlecolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
+ .terminal.color = GET_COLOR(COLOR_CYAN, COLOR_BLUE) | A_BOLD,
+
+ .shadow.color = GET_COLOR(COLOR_BLACK, COLOR_BLACK),
+ .shadow.h = 1,
+ .shadow.w = 2,
+
+ .dialog.delimtitle = false,
+ .dialog.titlecolor = GET_COLOR(COLOR_BLUE, COLOR_WHITE) | A_BOLD,
+ .dialog.lineraisecolor = GET_COLOR(COLOR_WHITE, COLOR_WHITE) | A_BOLD,
+ .dialog.linelowercolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
+ .dialog.color = GET_COLOR(COLOR_BLACK, COLOR_WHITE),
+ .dialog.bottomtitlecolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
.text.hmargin = 1,
- .menu.arrowcolor = GET_COLOR(COLOR_GREEN, COLOR_WHITE),
- .menu.f_desccolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE) | A_BOLD,
- .menu.desccolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
- .menu.f_namecolor = GET_COLOR(COLOR_YELLOW,COLOR_BLUE) | A_BOLD,
- .menu.namecolor = GET_COLOR(COLOR_BLUE, COLOR_WHITE) | A_BOLD,
- .menu.namesepcolor = GET_COLOR(COLOR_RED, COLOR_WHITE),
- .menu.descsepcolor = GET_COLOR(COLOR_RED, COLOR_WHITE),
+ .menu.arrowcolor = GET_COLOR(COLOR_GREEN, COLOR_WHITE),
+ .menu.selectorcolor = GET_COLOR(COLOR_BLACK, bgwidget) | A_BOLD,
+ .menu.f_desccolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE) | A_BOLD,
+ .menu.desccolor = GET_COLOR(COLOR_BLACK, COLOR_WHITE) | A_BOLD,
+ .menu.f_namecolor = GET_COLOR(COLOR_YELLOW, COLOR_BLUE) | A_BOLD,
+ .menu.namecolor = GET_COLOR(COLOR_BLUE, COLOR_WHITE) | A_BOLD,
+ .menu.namesepcolor = GET_COLOR(COLOR_RED, COLOR_WHITE),
+ .menu.descsepcolor = GET_COLOR(COLOR_RED, COLOR_WHITE),
+ .menu.f_shortcutcolor = GET_COLOR(COLOR_RED, COLOR_BLUE) | A_BOLD,
+ .menu.shortcutcolor = GET_COLOR(COLOR_RED, COLOR_WHITE) | A_BOLD,
.form.f_fieldcolor = GET_COLOR(COLOR_WHITE, COLOR_BLUE) | A_BOLD,
.form.fieldcolor = GET_COLOR(COLOR_WHITE, COLOR_CYAN) | A_BOLD,
@@ -166,79 +178,111 @@ static struct bsddialog_theme dialogtheme = {
.button.shortcutcolor = GET_COLOR(COLOR_RED, COLOR_WHITE) | A_BOLD
};
-void bsddialog_set_theme(struct bsddialog_theme newtheme)
+static void
+set_theme(struct bsddialog_theme *dst, struct bsddialog_theme *src)
{
- t.shadow.color = newtheme.shadow.color;
- t.shadow.h = newtheme.shadow.h;
- t.shadow.w = newtheme.shadow.w;
-
- t.terminal.color = newtheme.terminal.color;
- t.widget.delimtitle = newtheme.widget.delimtitle;
- t.widget.titlecolor = newtheme.widget.titlecolor;
- t.widget.lineraisecolor = newtheme.widget.lineraisecolor;
- t.widget.linelowercolor = newtheme.widget.linelowercolor;
- t.widget.color = newtheme.widget.color;
- t.widget.bottomtitlecolor = newtheme.widget.bottomtitlecolor;
-
- t.text.hmargin = newtheme.text.hmargin;
-
- t.menu.arrowcolor = newtheme.menu.arrowcolor;
- t.menu.f_desccolor = newtheme.menu.f_desccolor;
- t.menu.desccolor = newtheme.menu.desccolor;
- t.menu.f_namecolor = newtheme.menu.f_namecolor;
- t.menu.namecolor = newtheme.menu.namecolor;
- t.menu.namesepcolor = newtheme.menu.namesepcolor;
- t.menu.descsepcolor = newtheme.menu.descsepcolor;
-
- t.form.f_fieldcolor = newtheme.form.f_fieldcolor;
- t.form.fieldcolor = newtheme.form.fieldcolor;
- t.form.readonlycolor = newtheme.form.readonlycolor;
-
- t.bar.f_color = newtheme.bar.f_color;
- t.bar.color = newtheme.bar.color;
-
- t.button.space = newtheme.button.space;
- t.button.leftch = newtheme.button.leftch;
- t.button.rightch = newtheme.button.rightch;
- t.button.f_delimcolor = newtheme.button.f_delimcolor;
- t.button.delimcolor = newtheme.button.delimcolor;
- t.button.f_color = newtheme.button.f_color;
- t.button.color = newtheme.button.color;
- t.button.f_shortcutcolor = newtheme.button.f_shortcutcolor;
- t.button.shortcutcolor = newtheme.button.shortcutcolor;
-
- bkgd(t.terminal.color);
-
+ dst->shadow.color = src->shadow.color;
+ dst->shadow.h = src->shadow.h;
+ dst->shadow.w = src->shadow.w;
+
+ dst->terminal.color = src->terminal.color;
+ dst->dialog.delimtitle = src->dialog.delimtitle;
+ dst->dialog.titlecolor = src->dialog.titlecolor;
+ dst->dialog.lineraisecolor = src->dialog.lineraisecolor;
+ dst->dialog.linelowercolor = src->dialog.linelowercolor;
+ dst->dialog.color = src->dialog.color;
+ dst->dialog.bottomtitlecolor = src->dialog.bottomtitlecolor;
+
+ dst->text.hmargin = src->text.hmargin;
+
+ dst->menu.arrowcolor = src->menu.arrowcolor;
+ dst->menu.selectorcolor = src->menu.selectorcolor;
+ dst->menu.f_desccolor = src->menu.f_desccolor;
+ dst->menu.desccolor = src->menu.desccolor;
+ dst->menu.f_namecolor = src->menu.f_namecolor;
+ dst->menu.namecolor = src->menu.namecolor;
+ dst->menu.namesepcolor = src->menu.namesepcolor;
+ dst->menu.descsepcolor = src->menu.descsepcolor;
+ dst->menu.f_shortcutcolor = src->menu.f_shortcutcolor;
+ dst->menu.shortcutcolor = src->menu.shortcutcolor;
+
+ dst->form.f_fieldcolor = src->form.f_fieldcolor;
+ dst->form.fieldcolor = src->form.fieldcolor;
+ dst->form.readonlycolor = src->form.readonlycolor;
+
+ dst->bar.f_color = src->bar.f_color;
+ dst->bar.color = src->bar.color;
+
+ dst->button.space = src->button.space;
+ dst->button.leftch = src->button.leftch;
+ dst->button.rightch = src->button.rightch;
+ dst->button.f_delimcolor = src->button.f_delimcolor;
+ dst->button.delimcolor = src->button.delimcolor;
+ dst->button.f_color = src->button.f_color;
+ dst->button.color = src->button.color;
+ dst->button.f_shortcutcolor = src->button.f_shortcutcolor;
+ dst->button.shortcutcolor = src->button.shortcutcolor;
+
+ bkgd(dst->terminal.color);
refresh();
}
+/* API */
+int bsddialog_get_theme(struct bsddialog_theme *theme)
+{
+ if (theme == NULL)
+ RETURN_ERROR("theme is NULL");
+ if (sizeof(*theme) != sizeof(struct bsddialog_theme))
+ RETURN_ERROR("Bad suze struct bsddialog_theme");
+
+ set_theme(theme, &t);
+
+ return (0);
+}
+
+int bsddialog_set_theme(struct bsddialog_theme *theme)
+{
+ if (theme == NULL)
+ RETURN_ERROR("theme is NULL");
+ if (sizeof(*theme) != sizeof(struct bsddialog_theme))
+ RETURN_ERROR("Bad size struct bsddialog_theme");
+
+ set_theme(&t, theme);
+
+ return (0);
+}
+
int bsddialog_set_default_theme(enum bsddialog_default_theme newtheme)
{
- if (newtheme == BSDDIALOG_THEME_DEFAULT)
- bsddialog_set_theme(dialogtheme);
+ if (newtheme == BSDDIALOG_THEME_DEFAULT) {
+ bsddialog_set_theme(&dialogtheme);
+ t.dialog.lineraisecolor = t.dialog.linelowercolor;
+ }
else if (newtheme == BSDDIALOG_THEME_BSDDIALOG)
- bsddialog_set_theme(bsddialogtheme);
+ bsddialog_set_theme(&bsddialogtheme);
else if (newtheme == BSDDIALOG_THEME_BLACKWHITE)
- bsddialog_set_theme(blackwhite);
+ bsddialog_set_theme(&blackwhite);
else if (newtheme == BSDDIALOG_THEME_DIALOG)
- bsddialog_set_theme(dialogtheme);
+ bsddialog_set_theme(&dialogtheme);
else
RETURN_ERROR("Unknow default theme");
- return 0;
+ return (0);
}
int
bsddialog_color(enum bsddialog_color background,
- enum bsddialog_color foreground)
+ enum bsddialog_color foreground, unsigned int flags)
{
+ unsigned int cursesflags = 0;
- return GET_COLOR(background, foreground);
-}
-
-struct bsddialog_theme bsddialog_get_theme()
-{
+ if (flags & BSDDIALOG_BOLD)
+ cursesflags |= A_BOLD;
+ if (flags & BSDDIALOG_REVERSE)
+ cursesflags |= A_REVERSE;
+ if (flags & BSDDIALOG_UNDERLINE)
+ cursesflags |= A_UNDERLINE;
- return t;
+ return (GET_COLOR(background, foreground) | cursesflags);
}
diff --git a/lib/timebox.c b/lib/timebox.c
index 4b1b8ee989a6..2597cbf0c152 100644
--- a/lib/timebox.c
+++ b/lib/timebox.c
@@ -28,9 +28,9 @@
#include <sys/param.h>
#ifdef PORTNCURSES
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
#else
-#include <curses.h>
+#include <ncurses.h>
#endif
#include <ctype.h>
@@ -68,6 +68,8 @@ datetime_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h,
*w = MAX(*w, line);
/* date windows */
*w = MAX(*w, minw);
+ /* conf.auto_minwidth */
+ *w = MAX(*w, (int)conf->auto_minwidth);
/* avoid terminal overflow */
*w = MIN(*w, widget_max_width(conf) -1);
}
@@ -75,7 +77,9 @@ datetime_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h,
if (rows == BSDDIALOG_AUTOSIZE) {
*h = MINHEIGHT;
if (maxword > 0)
- *h += MAX(nlines, (*w / GET_ASPECT_RATIO(conf)));
+ *h += MAX(nlines, (int)(*w / GET_ASPECT_RATIO(conf)));
+ /* conf.auto_minheight */
+ *h = MAX(*h, (int)conf->auto_minheight);
/* avoid terminal overflow */
*h = MIN(*h, widget_max_height(conf) -1);
}
@@ -175,7 +179,7 @@ int bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int col
case KEY_ENTER:
case 10: /* Enter */
output = bs.value[bs.curr];
- if (output == BSDDIALOG_YESOK) {
+ if (output == BSDDIALOG_OK) {
*hh = c[0].value;
*mm = c[1].value;
*ss = c[2].value;
@@ -210,7 +214,7 @@ int bsddialog_timebox(struct bsddialog_conf *conf, char* text, int rows, int col
c[sel].value = c[sel].value > 0 ? c[sel].value - 1 : c[sel].max;
break;
case KEY_F(1):
- if (conf->hfile == NULL)
+ if (conf->f1_file == NULL && conf->f1_message == NULL)
break;
curs_set(0);
if (f1help(conf) != 0)
@@ -393,7 +397,7 @@ bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
case KEY_ENTER:
case 10: /* Enter */
output = bs.value[bs.curr];
- if (output == BSDDIALOG_YESOK) {
+ if (output == BSDDIALOG_OK) {
*yy = c[0].value;
*mm = c[1].value;
*dd = c[2].value;
@@ -444,7 +448,7 @@ bsddialog_datebox(struct bsddialog_conf *conf, char* text, int rows, int cols,
c[2].value = c[2].max;
break;
case KEY_F(1):
- if (conf->hfile == NULL)
+ if (conf->f1_file == NULL && conf->f1_message == NULL)
break;
curs_set(0);
if (f1help(conf) != 0)