mconf: make extensive use of ncurses' variables LINES and COLS.
RFC 1/1 mconf: make extensive use of ncurses' variables LINES and COLS.
This (again) is a rather cosmetic change that I could not resist, while checking how to make print_autowrap() handle height-conflicts and also reading ncurses documentation.
Dirk
From 882aa6595cbb2683a43bf24f1b9741263641ec9b Mon Sep 17 00:00:00 2001
From: Dirk Gouders <[email protected]>
Date: Fri, 10 May 2013 12:26:23 +0200
Subject: [PATCH] mconf: make extensive use of ncurses' variables LINES and
COLS.
The manual page of ncurses states that the variables LINES and COLS are initialized by initscr(). So, in init_dialog() there is no need to use local variables height' and width' and initialize them using function calls.
Further, in other functions' `do_resize' cases getmaxx(stdscr)/COLS and getmaxy(stdscr)/LINES were used in mixture; the function calls were replaced with the respective variables.
Finally, to be consequent, show_help() used getmaxx(stdscr) which has been replaced by COLS.
--- scripts/kconfig/lxdialog/checklist.c | 4 ++-- scripts/kconfig/lxdialog/inputbox.c | 4 ++-- scripts/kconfig/lxdialog/menubox.c | 4 ++-- scripts/kconfig/lxdialog/textbox.c | 4 +++- scripts/kconfig/lxdialog/util.c | 5 +---- scripts/kconfig/lxdialog/yesno.c | 4 ++-- scripts/kconfig/mconf.c | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-)
scripts/kconfig/lxdialog/checklist.c +2 -2
@@ -132,9 +132,9 @@ int dialog_checklist(const char *title, const char *prompt, int height, } do_resize: -if (getmaxy (stdscr) < (height +6 )) +if (LINES < (height +6 ))return -ERRDISPLAYTOOSMALL ; -if (getmaxx (stdscr) < (width +6 )) +if (COLS < (width +6 ))return -ERRDISPLAYTOOSMALL ; max_choice =MIN (list_height,item_count ());
scripts/kconfig/lxdialog/inputbox.c +2 -2
@@ -56,9 +56,9 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int widthstrcpy (instr, init); do_resize: -if (getmaxy (stdscr) <= (height -2 )) +if (LINES <= (height -2 ))return -ERRDISPLAYTOOSMALL ; -if (getmaxx (stdscr) <= (width -2 )) +if (COLS <= (width -2 ))return -ERRDISPLAYTOOSMALL ;/* center dialog box on screen */
scripts/kconfig/lxdialog/menubox.c +2 -2
@@ -191,8 +191,8 @@ int dialog_menu(const char *title, const char *prompt,WINDOW *dialog, *menu; do_resize: - height =getmaxy (stdscr); - width =getmaxx (stdscr); + height =LINES ; + width =COLS ;if (height <15 || width <65 )return -ERRDISPLAYTOOSMALL ;
scripts/kconfig/lxdialog/textbox.c +3 -1
@@ -79,7 +79,9 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height, hscroll = *_hscroll; do_resize: -getmaxyx (stdscr, height, width); + height =LINES ; + width =COLS ; +if (height <8 || width <8 )return -ERRDISPLAYTOOSMALL ;if (initial_height !=0 )
scripts/kconfig/lxdialog/util.c +1 -4
@@ -309,15 +309,12 @@ void dialog_clear(void)*/ int init_dialog (const char *backtitle) { -int height, width; -initscr ();/* Init curses */ /* Get current cursor position for signal handler in mconf.c */ getyx (stdscr, saved_y, saved_x); -getmaxyx (stdscr, height, width); -if (height <19 || width <80 ) { +if (LINES <19 ||COLS <80 ) {endwin ();return -ERRDISPLAYTOOSMALL ; }
scripts/kconfig/lxdialog/yesno.c +2 -2
@@ -45,9 +45,9 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)WINDOW *dialog; do_resize: -if (getmaxy (stdscr) < (height +4 )) +if (LINES < (height +4 ))return -ERRDISPLAYTOOSMALL ; -if (getmaxx (stdscr) < (width +4 )) +if (COLS < (width +4 ))return -ERRDISPLAYTOOSMALL ;/* center dialog box on screen */
scripts/kconfig/mconf.c +1 -1
@@ -787,7 +787,7 @@ static void show_help(struct menu *menu) {struct gstr help =str_new (); - help.max_width =getmaxx (stdscr) -10 ; + help.max_width =COLS -10 ;menu_get_ext_help (menu, &help);show_helptext (_ (menu_get_prompt (menu)),str_get (&help));
Signature · 1 line
1.8.2.1
Dirk, All,
On 2013-05-10 14:59 +0200, Dirk Gouders spake thusly:
Quoted 10 lines
From
882aa6595cbb2683a43bf24f1b9741263641ec9bMon Sep 17 00:00:00 2001
From: Dirk Gouders <[email protected]>
Date: Fri, 10 May 2013 12:26:23 +0200
Subject: [PATCH] mconf: make extensive use of ncurses' variables LINES and
COLS.The manual page of ncurses states that the variables LINES and COLS are initialized by
initscr(). So, ininit_dialog()there is no need to use local variablesheight' andwidth' and initialize them using function calls.
If we read the manpage strictly, the LINES and COLS are set by initsrc, and nothing else updates them. So the manpage does not state what happens when the terminal is resized. The only mention of 'COLS' in the man page is this paragraph:
---8<---
The integer variables LINES and COLS are defined in <curses.h> and will be filled in by initscr with the size of the screen. ---8<---
After looking at the code of ncurses, the LINES and COLS are also updated upon a resize. But as this is not documented, I think we should *not* rely on that behaviour.
I believe we should use the functions, not the variables.
Also note that the getmaxyx() familly are not functions, they are macros.
Regards,
Yann E. MORIN.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
Quoted 10 lines · Yann E. MORIN
If we read the manpage strictly, the LINES and COLS are set by initsrc, and nothing else updates them. So the manpage does not state what happens when the terminal is resized. The only mention of 'COLS' in the man page is this paragraph:
---8<---
The integer variables LINES and COLS are defined in <curses.h> and will be filled in by initscr with the size of the screen. ---8<---
Quoted 7 lines
After looking at the code of ncurses, the LINES and COLS are also updated upon a resize. But as this is not documented, I think we should *not* rely on that behaviour.
I believe we should use the functions, not the variables.
Also note that the
getmaxyx()familly are not functions, they are macros.
Thank you for your review and comments.
I changed the patch so that the variables are used (or not used) strictly according to the documentation. Of course, the change of init_dialog() is not really necessary to comply with the documentation; I will send a v3 if it shold remain unchanged.
Dirk
From 178b894e8129ae7b199c5495091dafc89c203b00 Mon Sep 17 00:00:00 2001
From: Dirk Gouders <[email protected]>
Date: Sat, 11 May 2013 12:46:12 +0200
Subject: [PATCH v2] mconf: Use ncurses' variables LINES and COLS according to the
documentation.
According to the documentation [1], LINES and COLS are initialized by initscr(). So, use these variables in init_dialog().
The documentation 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.
[1] ncurses(3X)
--- scripts/kconfig/lxdialog/checklist.c | 4 ++-- scripts/kconfig/lxdialog/inputbox.c | 4 ++-- scripts/kconfig/lxdialog/menubox.c | 4 ++-- scripts/kconfig/lxdialog/textbox.c | 4 ++-- scripts/kconfig/lxdialog/util.c | 5 +---- scripts/kconfig/lxdialog/yesno.c | 4 ++-- 6 files changed, 11 insertions(+), 14 deletions(-)
scripts/kconfig/lxdialog/checklist.c +2 -2
@@ -140,8 +140,8 @@ do_resize: max_choice =MIN (list_height,item_count ());/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/inputbox.c +2 -2
@@ -62,8 +62,8 @@ do_resize:return -ERRDISPLAYTOOSMALL ;/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/menubox.c +2 -2
@@ -203,8 +203,8 @@ do_resize: max_choice =MIN (menu_height,item_count ());/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/textbox.c +2 -2
@@ -98,8 +98,8 @@ do_resize: width =0 ;/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/util.c +1 -4
@@ -309,15 +309,12 @@ void dialog_clear(void)*/ int init_dialog (const char *backtitle) { -int height, width; -initscr ();/* Init curses */ /* Get current cursor position for signal handler in mconf.c */ getyx (stdscr, saved_y, saved_x); -getmaxyx (stdscr, height, width); -if (height <19 || width <80 ) { +if (LINES <19 ||COLS <80 ) {endwin ();return -ERRDISPLAYTOOSMALL ; }
scripts/kconfig/lxdialog/yesno.c +2 -2
@@ -51,8 +51,8 @@ do_resize:return -ERRDISPLAYTOOSMALL ;/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
Signature · 1 line
1.8.2.1
Quoted 18 lines · Dirk Gouders
Quoted 16 lines · Yann E. MORIN
If we read the manpage strictly, the LINES and COLS are set by initsrc, and nothing else updates them. So the manpage does not state what happens when the terminal is resized. The only mention of 'COLS' in the man page is this paragraph:
---8<---
The integer variables LINES and COLS are defined in <curses.h> and will be filled in by initscr with the size of the screen. ---8<---After looking at the code of ncurses, the LINES and COLS are also updated upon a resize. But as this is not documented, I think we should *not* rely on that behaviour.
I believe we should use the functions, not the variables.
Quoted 8 lines
Quoted 1 line
Also note that the
getmaxyx()familly are not functions, they are macros.Thank you for your review and comments.
I changed the patch so that the variables are used (or not used) strictly according to the documentation. Of course, the change of
init_dialog()is not really necessary to comply with the documentation; I will send a v3 if it shold remain unchanged.
I'm sorry, I forgot to insert a Signed-off-by line, again.
Dirk
From a8f5ff2e666d467c84ece16e1fe783ac89ceaa60 Mon Sep 17 00:00:00 2001
From: Dirk Gouders <[email protected]>
Date: Sat, 11 May 2013 12:46:12 +0200
Subject: [PATCH v3] mconf: Use ncurses' variables LINES and COLS according to the
documentation.
According to the documentation [1], LINES and COLS are initialized by initscr(). So, use these variables in init_dialog().
The documentation 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.
[1] ncurses(3X)
--- scripts/kconfig/lxdialog/checklist.c | 4 ++-- scripts/kconfig/lxdialog/inputbox.c | 4 ++-- scripts/kconfig/lxdialog/menubox.c | 4 ++-- scripts/kconfig/lxdialog/textbox.c | 4 ++-- scripts/kconfig/lxdialog/util.c | 5 +---- scripts/kconfig/lxdialog/yesno.c | 4 ++-- 6 files changed, 11 insertions(+), 14 deletions(-)
scripts/kconfig/lxdialog/checklist.c +2 -2
@@ -140,8 +140,8 @@ do_resize: max_choice =MIN (list_height,item_count ());/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/inputbox.c +2 -2
@@ -62,8 +62,8 @@ do_resize:return -ERRDISPLAYTOOSMALL ;/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/menubox.c +2 -2
@@ -203,8 +203,8 @@ do_resize: max_choice =MIN (menu_height,item_count ());/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/textbox.c +2 -2
@@ -98,8 +98,8 @@ do_resize: width =0 ;/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/util.c +1 -4
@@ -309,15 +309,12 @@ void dialog_clear(void)*/ int init_dialog (const char *backtitle) { -int height, width; -initscr ();/* Init curses */ /* Get current cursor position for signal handler in mconf.c */ getyx (stdscr, saved_y, saved_x); -getmaxyx (stdscr, height, width); -if (height <19 || width <80 ) { +if (LINES <19 ||COLS <80 ) {endwin ();return -ERRDISPLAYTOOSMALL ; }
scripts/kconfig/lxdialog/yesno.c +2 -2
@@ -51,8 +51,8 @@ do_resize:return -ERRDISPLAYTOOSMALL ;/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
Signature · 1 line
1.8.2.1
Dirk, All,
On 2013-05-11 13:27 +0200, Dirk Gouders spake thusly:
Quoted 1 line
Dirk Gouders <[email protected]> writes:
[--SNIP--]
Quoted 6 lines
From
a8f5ff2e666d467c84ece16e1fe783ac89ceaa60Mon Sep 17 00:00:00 2001
From: Dirk Gouders <[email protected]>
Date: Sat, 11 May 2013 12:46:12 +0200
Subject: [PATCH v3] mconf: Use ncurses' variables LINES and COLS according to the
documentation.
Quoted 7 lines
According to the documentation [1], LINES and COLS are initialized by
initscr(). So, use these variables ininit_dialog().The documentation 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.
You missed three occurences of COLS in:
scripts/kconfig/lxdialog/util.c:dialog_clear
Quoted 8 lines
scripts/kconfig/lxdialog/util.c +0
-0@@ -309,15 +309,12 @@ void dialog_clear(void)*/ int init_dialog (const char *backtitle) {
scripts/kconfig/lxdialog/util.c void dialog_clear(void) · line 317
Quoted 10 lines
scripts/kconfig/lxdialog/util.c +1
-4-int height, width; -initscr ();/* Init curses */ /* Get current cursor position for signal handler in mconf.c */ getyx (stdscr, saved_y, saved_x); -getmaxyx (stdscr, height, width); -if (height <19 || width <80 ) { +if (LINES <19 ||COLS <80 ) {
I know that COLS and LINES are correct right here since we just called initscr, but for the sake of consistency, I think we'd better use the functions here, too.
Also, it's a pain to apply your patches, since 'git am' will use the entire body of the mail as the commit message.
I know you have issues using 'git send-email', but could you please at least add a scissor-line as the last line of your email body, which will make 'git am' ignore whatever is above that line (and that line itself):
---8<--- <- This is a scissor-line
And please do not attach the patch, add it in the body of the mail. Use 'git format-patch' to prepare your patch(es), and just send the resulting file(s) as the mail (hopefully, gnus is able to use an existing file as the mail to send).
Otherwise, LGTM.
Regards,
Yann E. MORIN.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH v4 1/1 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)
--- scripts/kconfig/lxdialog/checklist.c | 4 ++-- scripts/kconfig/lxdialog/inputbox.c | 4 ++-- scripts/kconfig/lxdialog/menubox.c | 4 ++-- scripts/kconfig/lxdialog/textbox.c | 4 ++-- scripts/kconfig/lxdialog/util.c | 13 +++++++++---- scripts/kconfig/lxdialog/yesno.c | 4 ++-- 6 files changed, 19 insertions(+), 14 deletions(-)
scripts/kconfig/lxdialog/checklist.c +2 -2
@@ -140,8 +140,8 @@ do_resize: max_choice =MIN (list_height,item_count ());/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/inputbox.c +2 -2
@@ -62,8 +62,8 @@ do_resize:return -ERRDISPLAYTOOSMALL ;/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/menubox.c +2 -2
@@ -203,8 +203,8 @@ do_resize: max_choice =MIN (menu_height,item_count ());/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/textbox.c +2 -2
@@ -98,8 +98,8 @@ do_resize: width =0 ;/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
scripts/kconfig/lxdialog/util.c +9 -4
@@ -254,7 +254,12 @@ void attr_clear(WINDOW * win, int height, int width, chtype attr)void dialog_clear (void ) { -attr_clear (stdscr,LINES ,COLS , dlg.screen.atr); +int lines, columns; + + lines =getmaxy (stdscr); + columns =getmaxx (stdscr); + +attr_clear (stdscr, lines, columns, dlg.screen.atr);/* Display background title if it exists ... - SLH */ if (dlg.backtitle !=NULL ) {int i, len =0 , skip =0 ;
@@ -269,10 +274,10 @@ void dialog_clear(void) }wmove (stdscr,1 ,1 ); -if (len >COLS -2 ) { +if (len > columns -2 ) {const char *ellipsis ="[...] " ;waddstr (stdscr, ellipsis); - skip = len - (COLS -2 -strlen (ellipsis)); + skip = len - (columns -2 -strlen (ellipsis)); }for (pos = dlg.subtitles; pos !=NULL ; pos = pos->next) {
@@ -298,7 +303,7 @@ void dialog_clear(void) skip--; } -for (i = len +1 ; i <COLS -1 ; i++) +for (i = len +1 ; i < columns -1 ; i++)waddch (stdscr,ACS_HLINE ); }wnoutrefresh (stdscr);
scripts/kconfig/lxdialog/yesno.c +2 -2
@@ -51,8 +51,8 @@ do_resize:return -ERRDISPLAYTOOSMALL ;/* center dialog box on screen */ - x = (COLS - width) /2 ; - y = (LINES - height) /2 ; + x = (getmaxx (stdscr) - width) /2 ; + y = (getmaxy (stdscr) - height) /2 ;draw_shadow (stdscr, y, x, height, width);
Signature · 1 line
1.8.2.1
Yann E. MORIN
AppliedRe: [PATCH v4] mconf: use function calls instead of ncurses' variables LINES and COLS
Dirk, All,
On 2013-05-12 12:30 +0200, Dirk Gouders spake thusly:
Quoted 8 lines
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.
Quoted 6 lines
init_dialog()could make use of the variables, but for the sake of consistency we do not change it's current use of the macrogetmaxyx().[1] ncurses(3X)
Signed-off-by Dirk Gouders <[email protected]>
I've queued it now. Thank you!
Regards,
Yann E. MORIN.
PS. That new mail was correctly formatted, now! Thanks! YEM.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
Re: [PATCH v4] mconf: use function calls instead of ncurses' variables LINES and COLS
Quoted 7 lines · Yann E. MORIN
I've queued it now. Thank you!
Regards,
Yann E. MORIN.PS. That new mail was correctly formatted, now! Thanks! YEM.
Thank you, Yann. Especially for your patience with me, wasting your time with sending misformatted patches and getting rather simple changes right.
Dirk
Re: [PATCH v4] mconf: use function calls instead of ncurses' variables LINES and COLS
Dirk, All,
On 2013-05-12 15:41 +0200, Dirk Gouders spake thusly:
Quoted 7 lines
Quoted 5 lines · Yann E. MORIN
I've queued it now. Thank you!
Regards,
Yann E. MORIN.
Quoted 6 lines
Quoted 2 lines
PS. That new mail was correctly formatted, now! Thanks! YEM.
Thank you, Yann. Especially for your patience with me, wasting your time with sending misformatted patches and getting rather simple changes right.
No problem! Thanks for staying with us during the iterations.
Now, since you seem to be interested in some cleanup and polishing, I've noticed that the nconf frontend also uses COLS and LINES, so if you've got some spare time... ;-)
Regards,
Yann E. MORIN.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 1/1 nconf: 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 or macros to get window dimensions.
The use of the variables in main() was OK, but for the sake of consistency it was modified to use the macro getmaxyx().
[1] ncurses(3X)
--- scripts/kconfig/nconf.c | 23 ++++++++++++++++------- scripts/kconfig/nconf.gui.c | 20 +++++++++++--------- 2 files changed, 27 insertions(+), 16 deletions(-)
scripts/kconfig/nconf.c +16 -7
@@ -365,15 +365,16 @@ static void print_function_line(void)int i;int offset =1 ;const int skip =1 ; +int lines =getmaxy (stdscr);for (i =0 ; i < function_keys_num; i++) { (void )wattrset (main_window, attributes[FUNCTION_HIGHLIGHT ]); -mvwprintw (main_window,LINES -3 , offset, +mvwprintw (main_window, lines-3 , offset,"%s" , function_keys[i].key_str); (void )wattrset (main_window, attributes[FUNCTION_TEXT ]); offset +=strlen (function_keys[i].key_str); -mvwprintw (main_window,LINES -3 , +mvwprintw (main_window, lines-3 , offset,"%s" , function_keys[i].func); offset +=strlen (function_keys[i].func) + skip;
@@ -954,7 +955,7 @@ static void show_menu(const char *prompt, const char *instructions,clear (); (void )wattrset (main_window, attributes[NORMAL ]); -print_in_middle (stdscr,1 ,0 ,COLS , +print_in_middle (stdscr,1 ,0 ,getmaxx (stdscr), menu_backtitle, attributes[MAIN_HEADING ]);
@@ -1455,14 +1456,19 @@ static void conf_save(void)void setup_windows (void ) { +int lines; +int columns; + +getmaxyx (stdscr, lines, columns); +if (main_window !=NULL )delwin (main_window);/* set up the menu and menu window */ - main_window =newwin (LINES -2 ,COLS -2 ,2 ,1 ); + main_window =newwin (lines-2 , columns-2 ,2 ,1 );keypad (main_window, TRUE); - mwin_max_lines =LINES -7 ; - mwin_max_cols =COLS -6 ; + mwin_max_lines = lines-7 ; + mwin_max_cols = columns-6 ;/* panels order is from bottom to top */ new_panel (main_window);
@@ -1470,6 +1476,8 @@ void setup_windows(void)int main (int ac,char **av) { +int lines; +int columns;char *mode;setlocale (LC_ALL ,"" );
@@ -1495,7 +1503,8 @@ int main(int ac, char **av)keypad (stdscr, TRUE);curs_set (0 ); -if (COLS <75 ||LINES <20 ) { +getmaxyx (stdscr, lines, columns); +if (columns <75 || lines <20 ) {endwin ();printf ("Your terminal should have at " "least 20 lines and 75 columns\n" );
scripts/kconfig/nconf.gui.c +11 -9
@@ -276,8 +276,8 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...) total_width =max (msg_width, btns_width);/* place dialog in middle of screen */ - y = (LINES -(msg_lines+4 ))/2 ; - x = (COLS -(total_width+4 ))/2 ; + y = (getmaxy (stdscr)-(msg_lines+4 ))/2 ; + x = (getmaxx (stdscr)-(total_width+4 ))/2 ;/* create the windows */
@@ -387,8 +387,8 @@ int dialog_inputbox(WINDOW *main_window, prompt_width =max (prompt_width,strlen (title));/* place dialog in middle of screen */ - y = (LINES -(prompt_lines+4 ))/2 ; - x = (COLS -(prompt_width+4 ))/2 ; + y = (getmaxy (stdscr)-(prompt_lines+4 ))/2 ; + x = (getmaxx (stdscr)-(prompt_width+4 ))/2 ;strncpy (result, init, *result_len);
@@ -545,7 +545,7 @@ void show_scroll_win(WINDOW *main_window, {int res;int total_lines =get_line_no (text); -int x, y; +int x, y, lines, columns;int start_x =0 , start_y =0 ;int text_lines =0 , text_cols =0 ;int total_cols =0 ;
@@ -556,6 +556,8 @@ void show_scroll_win(WINDOW *main_window,WINDOW *pad;PANEL *panel; +getmaxyx (stdscr, lines, columns); +/* find the widest line of msg: */ total_lines =get_line_no (text);for (i =0 ; i < total_lines; i++) {
@@ -569,14 +571,14 @@ void show_scroll_win(WINDOW *main_window, (void )wattrset (pad, attributes[SCROLLWIN_TEXT ]);fill_window (pad, text); - win_lines =min (total_lines+4 ,LINES -2 ); - win_cols =min (total_cols+2 ,COLS -2 ); + win_lines =min (total_lines+4 , lines-2 ); + win_cols =min (total_cols+2 , columns-2 ); text_lines =max (win_lines-4 ,0 ); text_cols =max (win_cols-2 ,0 );/* place window in middle of screen */ - y = (LINES -win_lines)/2 ; - x = (COLS -win_cols)/2 ; + y = (lines-win_lines)/2 ; + x = (columns-win_cols)/2 ; win =newwin (win_lines, win_cols, y, x);keypad (win, TRUE);
Signature · 1 line
1.8.2.1
Yann E. MORIN
AppliedRe: [PATCH] nconf: use function calls instead of ncurses' variables LINES and COLS
Dirk, All,
On 2013-05-13 11:23 +0200, Dirk Gouders spake thusly:
Quoted 8 lines
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 or macros to get window dimensions.
Quoted 6 lines
The use of the variables in
main()was OK, but for the sake of consistency it was modified to use the macrogetmaxyx().[1] ncurses(3X)
Signed-off-by Dirk Gouders <[email protected]>
Queued in my tree, with two very, very light changes:
scripts/kconfig/nconf.c
Quoted 4 lines
scripts/kconfig/nconf.c +0
-0
[--SMIP--]
scripts/kconfig/nconf.c static void conf_save(void) · line 1460
Quoted 6 lines
scripts/kconfig/nconf.c +2
-0@@ -1455,14 +1456,19 @@ static void conf_save(void)void setup_windows (void ) { +int lines; +int columns;
I've chamged this to be a single line:
int lines, columns;
[--SNIP--]
scripts/kconfig/nconf.c void setup_windows(void) · line 1480
Quoted 6 lines
scripts/kconfig/nconf.c +2
-0@@ -1470,6 +1476,8 @@ void setup_windows(void)int main (int ac,char **av) { +int lines; +int columns;
Ditto.
Thank you!
Regards,
Yann E. MORIN.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'