Commit 08718745 authored by Masahiro Yamada's avatar Masahiro Yamada

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.htmlSigned-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent 0a94768c
...@@ -953,7 +953,7 @@ static void show_menu(const char *prompt, const char *instructions, ...@@ -953,7 +953,7 @@ static void show_menu(const char *prompt, const char *instructions,
current_instructions = instructions; current_instructions = instructions;
clear(); clear();
print_in_middle(stdscr, 1, 0, getmaxx(stdscr), print_in_middle(stdscr, 1, getmaxx(stdscr),
menu_backtitle, menu_backtitle,
attr_main_heading); attr_main_heading);
......
...@@ -117,32 +117,10 @@ void set_colors(void) ...@@ -117,32 +117,10 @@ void set_colors(void)
} }
/* this changes the windows attributes !!! */ /* this changes the windows attributes !!! */
void print_in_middle(WINDOW *win, void print_in_middle(WINDOW *win, int y, int width, const char *str, int attrs)
int starty, {
int startx, wattrset(win, attrs);
int width, mvwprintw(win, y, (width - strlen(str)) / 2, "%s", str);
const char *string,
chtype color)
{ int length, x, y;
float temp;
if (win == NULL)
win = stdscr;
getyx(win, y, x);
if (startx != 0)
x = startx;
if (starty != 0)
y = starty;
if (width == 0)
width = 80;
length = strlen(string);
temp = (width - length) / 2;
x = startx + (int)temp;
wattrset(win, color);
mvwprintw(win, y, x, "%s", string);
refresh();
} }
int get_line_no(const char *text) int get_line_no(const char *text)
...@@ -577,7 +555,6 @@ void show_scroll_win(WINDOW *main_window, ...@@ -577,7 +555,6 @@ void show_scroll_win(WINDOW *main_window,
text_cols, 0); text_cols, 0);
print_in_middle(win, print_in_middle(win,
text_lines+2, text_lines+2,
0,
text_cols, text_cols,
"<OK>", "<OK>",
attr_dialog_menu_fore); attr_dialog_menu_fore);
......
...@@ -68,12 +68,7 @@ typedef enum { ...@@ -68,12 +68,7 @@ typedef enum {
void set_colors(void); void set_colors(void);
/* this changes the windows attributes !!! */ /* this changes the windows attributes !!! */
void print_in_middle(WINDOW *win, void print_in_middle(WINDOW *win, int y, int width, const char *str, int attrs);
int starty,
int startx,
int width,
const char *string,
chtype color);
int get_line_length(const char *line); int get_line_length(const char *line);
int get_line_no(const char *text); int get_line_no(const char *text);
const char *get_line(const char *text, int line_no); const char *get_line(const char *text, int line_no);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment