2018-12-18 20:13:35 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2009-11-25 18:28:43 +08:00
|
|
|
/*
|
2018-12-18 20:13:35 +08:00
|
|
|
* Copyright (C) 2008 Nir Tzachar <nir.tzachar@gmail.com>
|
2009-11-25 18:28:43 +08:00
|
|
|
*
|
|
|
|
* Derived from menuconfig.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2018-03-15 14:25:27 +08:00
|
|
|
#include <ncurses.h>
|
2009-11-25 18:28:43 +08:00
|
|
|
#include <menu.h>
|
|
|
|
#include <panel.h>
|
|
|
|
#include <form.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#define max(a, b) ({\
|
|
|
|
typeof(a) _a = a;\
|
|
|
|
typeof(b) _b = b;\
|
|
|
|
_a > _b ? _a : _b; })
|
|
|
|
|
|
|
|
#define min(a, b) ({\
|
|
|
|
typeof(a) _a = a;\
|
|
|
|
typeof(b) _b = b;\
|
|
|
|
_a < _b ? _a : _b; })
|
|
|
|
|
2021-04-11 03:45:34 +08:00
|
|
|
extern int attr_normal;
|
|
|
|
extern int attr_main_heading;
|
|
|
|
extern int attr_main_menu_box;
|
|
|
|
extern int attr_main_menu_fore;
|
|
|
|
extern int attr_main_menu_back;
|
|
|
|
extern int attr_main_menu_grey;
|
|
|
|
extern int attr_main_menu_heading;
|
|
|
|
extern int attr_scrollwin_text;
|
|
|
|
extern int attr_scrollwin_heading;
|
|
|
|
extern int attr_scrollwin_box;
|
|
|
|
extern int attr_dialog_text;
|
|
|
|
extern int attr_dialog_menu_fore;
|
|
|
|
extern int attr_dialog_menu_back;
|
|
|
|
extern int attr_dialog_box;
|
|
|
|
extern int attr_input_box;
|
|
|
|
extern int attr_input_heading;
|
|
|
|
extern int attr_input_text;
|
|
|
|
extern int attr_input_field;
|
|
|
|
extern int attr_function_text;
|
|
|
|
extern int attr_function_highlight;
|
2009-11-25 18:28:43 +08:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
F_HELP = 1,
|
|
|
|
F_SYMBOL = 2,
|
|
|
|
F_INSTS = 3,
|
|
|
|
F_CONF = 4,
|
|
|
|
F_BACK = 5,
|
|
|
|
F_SAVE = 6,
|
|
|
|
F_LOAD = 7,
|
2010-08-08 21:50:06 +08:00
|
|
|
F_SEARCH = 8,
|
|
|
|
F_EXIT = 9,
|
2009-11-25 18:28:43 +08:00
|
|
|
} function_key;
|
|
|
|
|
|
|
|
void set_colors(void);
|
|
|
|
|
|
|
|
/* this changes the windows attributes !!! */
|
kconfig: nconf: refactor in print_in_middle()
This helper is the same as the sample code in the NCURSES HOWTO [1],
but it is over-engineering to be used for nconf.
I do not see any good reason to use the 'float' type just for the
division by 2.
All the call-sites pass a non-NULL pointer to the first argument,
so 'if (win == NULL) win = stdscr;' is dead code.
'if (startx != 0) x = startx;' is dead code because 'x' will be
overridden some lines below, by 'x = startx + (int)temp;'.
All the call-sites pass a non-zero value to the second argument,
so 'if (starty != 0)' is always true.
getyx(win, y, x) is also dead-code because both 'y' and 'x' are
overridden.
All the call-sites pass 0 to the third parameter, so 'startx' can
be removed.
All the call-sites pass a non-zero value to the fourth parameter,
so 'if (width == 0) width = 80;' is dead code.
The window will be refreshed later, so there is no need to call
refresh() in this function.
Change the type of the last parameter from 'chtype' to 'int' to be
aligned with the prototype, 'int wattrset(WINDOW *win, int attrs);'
I also slightly cleaned up the indentation style.
[1]: https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/color.html
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-04-12 09:12:27 +08:00
|
|
|
void print_in_middle(WINDOW *win, int y, int width, const char *str, int attrs);
|
2009-11-25 18:28:43 +08:00
|
|
|
int get_line_length(const char *line);
|
|
|
|
int get_line_no(const char *text);
|
|
|
|
const char *get_line(const char *text, int line_no);
|
|
|
|
void fill_window(WINDOW *win, const char *text);
|
|
|
|
int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...);
|
|
|
|
int dialog_inputbox(WINDOW *main_window,
|
|
|
|
const char *title, const char *prompt,
|
2011-09-02 01:52:20 +08:00
|
|
|
const char *init, char **resultp, int *result_len);
|
2009-11-25 18:28:43 +08:00
|
|
|
void refresh_all_windows(WINDOW *main_window);
|
|
|
|
void show_scroll_win(WINDOW *main_window,
|
|
|
|
const char *title,
|
|
|
|
const char *text);
|