nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 3f494e359d3dd035c7079c9eec0ef82596f9cdc1
parent 8a06f70379851b00a04e665864dccd56f08819f4
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Mon, 31 Jan 2022 15:23:22 +0100

tweaks: stop asking the terminal for its new size -- let ncurses do it

When re-entering curses mode, ncurses will pick up the new size of
the terminal and set the LINES and COLS variables appropriately.

(We don't ask the terminal for its size when nano starts up, so why
would we need to do it when the terminal is resized?)

Diffstat:
Msrc/nano.c | 27++++-----------------------
1 file changed, 4 insertions(+), 23 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -1022,38 +1022,19 @@ void handle_sigwinch(int signal) /* Reinitialize and redraw the screen completely. */ void regenerate_screen(void) { - const char *tty = ttyname(0); - int fd, result = 0; - struct winsize win; - /* Reset the trigger. */ the_window_resized = FALSE; - if (tty == NULL) - return; - fd = open(tty, O_RDWR); - if (fd == -1) - return; - result = ioctl(fd, TIOCGWINSZ, &win); - close(fd); - if (result == -1) - return; + /* Leave and immediately reenter curses mode, so that ncurses notices + * the new screen dimensions and sets LINES and COLS accordingly. */ + endwin(); + refresh(); - /* We could check whether COLS or LINES changed, and return otherwise, - * but it seems curses does not always update these global variables. */ -#ifdef REDEFINING_MACROS_OK - COLS = win.ws_col; - LINES = win.ws_row; -#endif thebar = (ISSET(INDICATOR) && LINES > 5 && COLS > 9) ? 1 : 0; bardata = nrealloc(bardata, LINES * sizeof(int)); editwincols = COLS - margin - thebar; - /* Do as the website suggests: leave and immediately reenter curses mode. */ - endwin(); - doupdate(); - /* Put the terminal in the desired state again, and * recreate the subwindows with their (new) sizes. */ terminal_init();