All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yann E. MORIN" <yann.morin.1998@free.fr>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Michal Marek <mmarek@suse.cz>,
	Dirk Gouders <dirk@gouders.net>,
	"Yann E. MORIN" <yann.morin.1998@free.fr>
Subject: [PATCH 06/15] nconf: use function calls instead of ncurses' variables LINES and COLS
Date: Mon, 24 Jun 2013 20:11:50 +0200	[thread overview]
Message-ID: <e0b42605e685a0833303e1d4dde277c99d9e17b5.1372097219.git.yann.morin.1998@free.fr> (raw)
In-Reply-To: <cover.1372097219.git.yann.morin.1998@free.fr>
In-Reply-To: <cover.1372097219.git.yann.morin.1998@free.fr>

From: Dirk Gouders <dirk@gouders.net>

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)

Signed-off-by: Dirk Gouders <dirk@gouders.net>
Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
[yann.morin.1998@free.fr: declare 'lines' and 'columns' on a single line]
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
---
 scripts/kconfig/nconf.c     | 21 ++++++++++++++-------
 scripts/kconfig/nconf.gui.c | 20 +++++++++++---------
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index dbf31ed..aac85d3 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -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,18 @@ static void conf_save(void)
 
 void setup_windows(void)
 {
+	int lines, 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 +1475,7 @@ void setup_windows(void)
 
 int main(int ac, char **av)
 {
+	int lines, columns;
 	char *mode;
 
 	setlocale(LC_ALL, "");
@@ -1495,7 +1501,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");
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
index 9f8c44e..8275f0e5 100644
--- a/scripts/kconfig/nconf.gui.c
+++ b/scripts/kconfig/nconf.gui.c
@@ -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);
-- 
1.8.1.2


  parent reply	other threads:[~2013-06-24 18:15 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-24 18:11 [pull request v2] Pull request for branch yem-kconfig-for-next Yann E. MORIN
2013-06-24 18:11 ` [PATCH 01/15] kconfig: Fix defconfig when one choice menu selects options that another choice menu depends on Yann E. MORIN
2013-06-24 18:11 ` [PATCH 02/15] kconfig/lxdialog: Add definitions for mininimum (re)size values Yann E. MORIN
2013-06-24 18:11 ` [PATCH 03/15] kconfig/lxdialog: Use new mininimum resize definitions in conf_choice() Yann E. MORIN
2013-06-24 18:11 ` [PATCH 04/15] kconfig/lxdialog: handle newline characters in print_autowrap() Yann E. MORIN
2013-06-24 18:11 ` [PATCH 05/15] mconf: use function calls instead of ncurses' variables LINES and COLS Yann E. MORIN
2013-06-24 18:11 ` Yann E. MORIN [this message]
2013-06-24 18:11 ` [PATCH 07/15] mconf/nconf: mark empty menus/menuconfigs different from non-empty ones Yann E. MORIN
2013-06-24 18:11 ` [PATCH 08/15] scripts/config: replace hard-coded script name by a dynamic value Yann E. MORIN
2013-06-24 18:11 ` [PATCH 09/15] kconfig/conf: fix randconfig setting multiple symbols in a choice Yann E. MORIN
2013-06-25  7:23   ` Sedat Dilek
2013-06-24 18:11 ` [PATCH 10/15] kconfig/conf: accept a base-16 seed for randconfig Yann E. MORIN
2013-06-24 18:11 ` [PATCH 11/15] kconfig/conf: print the seed used to initialise the RNG " Yann E. MORIN
2013-06-24 18:11 ` [PATCH 12/15] kconfig: sort found symbols by relevance Yann E. MORIN
2013-07-08 11:19   ` Jean Delvare
2013-07-08 17:35     ` Yann E. MORIN
2013-07-10 20:46       ` Yann E. MORIN
2013-07-12  9:07         ` Jean Delvare
2013-07-13 13:06           ` Yann E. MORIN
2013-07-12  8:57       ` Jean Delvare
2013-06-24 18:11 ` [PATCH 13/15] kconfig/[mn]conf: make it explicit in the search box that a regexp is possible Yann E. MORIN
2013-07-08 11:25   ` Jean Delvare
2013-07-08 17:37     ` Yann E. MORIN
2013-07-16 14:31       ` Jean Delvare
2013-07-16 14:39         ` Yann E. MORIN
2013-06-24 18:11 ` [PATCH 14/15] kconfig: loop as long as we changed some symbols in randconfig Yann E. MORIN
2013-06-24 18:11 ` [PATCH 15/15] kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG Yann E. MORIN
2013-06-25  8:01   ` Yann E. MORIN
2013-06-25  8:10     ` Sedat Dilek
2013-06-25 20:58   ` Yann E. MORIN
2013-06-25 21:37     ` [PATCH] Revert "kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG" Yann E. MORIN
2013-06-26 13:48       ` Michal Marek
2013-06-26 21:44         ` Yann E. MORIN
2013-06-27  6:23           ` Sedat Dilek
2013-06-28 17:19             ` Yann E. MORIN
2013-06-24 21:42 ` [pull request v2] Pull request for branch yem-kconfig-for-next Michal Marek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e0b42605e685a0833303e1d4dde277c99d9e17b5.1372097219.git.yann.morin.1998@free.fr \
    --to=yann.morin.1998@free.fr \
    --cc=dirk@gouders.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.