diff options
author | Alfonso Siciliano <alfsiciliano@gmail.com> | 2022-01-28 08:14:55 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2022-01-28 08:14:55 +0000 |
commit | 02db4a1234b3bd9cf153e567827fd387cf91bfb2 (patch) | |
tree | 6a8d148a11a4a9d58ba1adb078d72e491339652b /lib/libbsddialog.c | |
parent | 77a55d2c3b4dd48a9a608736a9ba7ebce700bae1 (diff) |
Diffstat (limited to 'lib/libbsddialog.c')
-rw-r--r-- | lib/libbsddialog.c | 57 |
1 files changed, 21 insertions, 36 deletions
diff --git a/lib/libbsddialog.c b/lib/libbsddialog.c index aea3b152adfd..65134eabe5f3 100644 --- a/lib/libbsddialog.c +++ b/lib/libbsddialog.c @@ -1,7 +1,7 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2021 Alfonso Sabato Siciliano + * Copyright (c) 2021-2022 Alfonso Sabato Siciliano * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -25,43 +25,26 @@ * SUCH DAMAGE. */ -#ifdef PORTNCURSES -#include <ncurses/ncurses.h> -#else -#include <ncurses.h> -#endif +#include <curses.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "bsddialog.h" -#include "lib_util.h" #include "bsddialog_theme.h" - -/* - * This file implements public functions not related to a specific dialog. - * lib_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 - * formbox.c inputbox - passwordbox - form - passwordform - mixedform - * barbox.c gauge - mixedgauge - rangebox - pause - progressview - * textbox.c textbox - * timebox.c timebox - calendar - */ +#include "lib_util.h" extern struct bsddialog_theme t; int bsddialog_init(void) { int i, j, c, error; + enum bsddialog_default_theme theme; set_error_string(""); - if(initscr() == NULL) - RETURN_ERROR("Cannot init ncurses (initscr)"); + if (initscr() == NULL) + RETURN_ERROR("Cannot init curses (initscr)"); error = OK; error += keypad(stdscr, TRUE); @@ -69,24 +52,25 @@ int bsddialog_init(void) error += cbreak(); error += noecho(); curs_set(0); - if(error != OK) { + if (error != OK) { bsddialog_end(); - RETURN_ERROR("Cannot init ncurses (keypad and cursor)"); + RETURN_ERROR("Cannot init curses (keypad and cursor)"); } c = 1; error += start_color(); - for (i=0; i<8; i++) - for(j=0; j<8; j++) { + for (i = 0; i < 8; i++) + for (j = 0; j < 8; j++) { error += init_pair(c, i, j); c++; } - if(error != OK) { - bsddialog_end(); - RETURN_ERROR("Cannot init ncurses (colors)"); - } - if (bsddialog_set_default_theme(BSDDIALOG_THEME_DEFAULT) != 0) { + if (error == OK) + theme = BSDDIALOG_THEME_DEFAULT; + else + theme = BSDDIALOG_THEME_BLACKWHITE; + + if (bsddialog_set_default_theme(theme) != 0) { bsddialog_end(); return (BSDDIALOG_ERROR); } @@ -97,16 +81,17 @@ int bsddialog_init(void) int bsddialog_end(void) { if (endwin() != OK) - RETURN_ERROR("Cannot end ncurses (endwin)"); + RETURN_ERROR("Cannot end curses (endwin)"); return (BSDDIALOG_OK); } -int bsddialog_backtitle(struct bsddialog_conf *conf, char *backtitle) +int bsddialog_backtitle(struct bsddialog_conf *conf, const char *backtitle) { mvaddstr(0, 1, backtitle); if (conf->no_lines != true) - mvhline(1, 1, conf->ascii_lines ? '-' : ACS_HLINE, COLS-2); + mvhline(1, 1, conf->ascii_lines ? '-' : ACS_HLINE, + SCREENCOLS - 2); refresh(); @@ -140,4 +125,4 @@ int bsddialog_clearterminal(void) refresh(); return (BSDDIALOG_OK); -} +}
\ No newline at end of file |