Skip to content

Commit 4f2de3e

Browse files
dgoudersyann-morin-1998
authored andcommitted
mconf: use function calls instead of ncurses' variables LINES and COLS
According to the documentation [1], LINES and COLS are initialized by initscr(); it does not say anything about the behavior when windows are resized. Do not rely on the current implementation of ncurses that updates these variables on resize, but use the propper function calls to get window dimensions. init_dialog() could make use of the variables, but for the sake of consistency we do not change it's current use of the macro getmaxyx(). [1] ncurses(3X) Signed-off-by: Dirk Gouders <dirk@gouders.net> Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
1 parent 1376391 commit 4f2de3e

6 files changed

Lines changed: 19 additions & 14 deletions

File tree

‎scripts/kconfig/lxdialog/checklist.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ int dialog_checklist(const char *title, const char *prompt, int height,
140140
max_choice = MIN(list_height, item_count());
141141

142142
/* center dialog box on screen */
143-
x = (COLS - width) / 2;
144-
y = (LINES - height) / 2;
143+
x = (getmaxx(stdscr) - width) / 2;
144+
y = (getmaxy(stdscr) - height) / 2;
145145

146146
draw_shadow(stdscr, y, x, height, width);
147147

‎scripts/kconfig/lxdialog/inputbox.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
6262
return -ERRDISPLAYTOOSMALL;
6363

6464
/* center dialog box on screen */
65-
x = (COLS - width) / 2;
66-
y = (LINES - height) / 2;
65+
x = (getmaxx(stdscr) - width) / 2;
66+
y = (getmaxy(stdscr) - height) / 2;
6767

6868
draw_shadow(stdscr, y, x, height, width);
6969

‎scripts/kconfig/lxdialog/menubox.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ int dialog_menu(const char *title, const char *prompt,
203203
max_choice = MIN(menu_height, item_count());
204204

205205
/* center dialog box on screen */
206-
x = (COLS - width) / 2;
207-
y = (LINES - height) / 2;
206+
x = (getmaxx(stdscr) - width) / 2;
207+
y = (getmaxy(stdscr) - height) / 2;
208208

209209
draw_shadow(stdscr, y, x, height, width);
210210

‎scripts/kconfig/lxdialog/textbox.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
9898
width = 0;
9999

100100
/* center dialog box on screen */
101-
x = (COLS - width) / 2;
102-
y = (LINES - height) / 2;
101+
x = (getmaxx(stdscr) - width) / 2;
102+
y = (getmaxy(stdscr) - height) / 2;
103103

104104
draw_shadow(stdscr, y, x, height, width);
105105

‎scripts/kconfig/lxdialog/util.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ void attr_clear(WINDOW * win, int height, int width, chtype attr)
254254

255255
void dialog_clear(void)
256256
{
257-
attr_clear(stdscr, LINES, COLS, dlg.screen.atr);
257+
int lines, columns;
258+
259+
lines = getmaxy(stdscr);
260+
columns = getmaxx(stdscr);
261+
262+
attr_clear(stdscr, lines, columns, dlg.screen.atr);
258263
/* Display background title if it exists ... - SLH */
259264
if (dlg.backtitle != NULL) {
260265
int i, len = 0, skip = 0;
@@ -269,10 +274,10 @@ void dialog_clear(void)
269274
}
270275

271276
wmove(stdscr, 1, 1);
272-
if (len > COLS - 2) {
277+
if (len > columns - 2) {
273278
const char *ellipsis = "[...] ";
274279
waddstr(stdscr, ellipsis);
275-
skip = len - (COLS - 2 - strlen(ellipsis));
280+
skip = len - (columns - 2 - strlen(ellipsis));
276281
}
277282

278283
for (pos = dlg.subtitles; pos != NULL; pos = pos->next) {
@@ -298,7 +303,7 @@ void dialog_clear(void)
298303
skip--;
299304
}
300305

301-
for (i = len + 1; i < COLS - 1; i++)
306+
for (i = len + 1; i < columns - 1; i++)
302307
waddch(stdscr, ACS_HLINE);
303308
}
304309
wnoutrefresh(stdscr);

‎scripts/kconfig/lxdialog/yesno.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
5151
return -ERRDISPLAYTOOSMALL;
5252

5353
/* center dialog box on screen */
54-
x = (COLS - width) / 2;
55-
y = (LINES - height) / 2;
54+
x = (getmaxx(stdscr) - width) / 2;
55+
y = (getmaxy(stdscr) - height) / 2;
5656

5757
draw_shadow(stdscr, y, x, height, width);
5858

0 commit comments

Comments
 (0)