nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH 2/2] screen: continue to function also in a terminal


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 2/2] screen: continue to function also in a terminal with very few lines
Date: Mon, 15 Aug 2016 19:49:10 +0200

This fixes https://savannah.gnu.org/bugs/?48787.
---
 src/nano.c  | 33 +++++++++++++++++++++------------
 src/winio.c |  8 ++++++--
 2 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/src/nano.c b/src/nano.c
index b9f00c9..8990b9f 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -686,28 +686,37 @@ void die_save_file(const char *die_filename, struct stat 
*die_stat)
     free(targetname);
 }
 
-#define TOP_ROWS    (ISSET(MORE_SPACE) ? 1 : 2)
-#define BOTTOM_ROWS    (ISSET(NO_HELP) ? 1 : 3)
-
 /* Initialize the three window portions nano uses. */
 void window_init(void)
 {
+    int toprows = (ISSET(MORE_SPACE) ? 1 : 2);
+    int bottomrows = (ISSET(NO_HELP) ? 1 : 3);
+
     /* First delete existing windows, in case of resizing. */
     delwin(topwin);
+    topwin = NULL;
     delwin(edit);
     delwin(bottomwin);
 
-    /* Compute how many lines the edit subwindow will have. */
-    editwinrows = LINES - TOP_ROWS - BOTTOM_ROWS;
+    /* If the terminal is very flat, don't set up a titlebar.  If there is
+     * just one line, let edit window and statusbar overlap each other. */
+    if (LINES < 3) {
+       editwinrows = 1;
+       edit = newwin(1, COLS, 0, 0);
+       bottomwin = newwin(1, COLS, LINES - 1, 0);
+    } else {
+       if (LINES < 6)
+          toprows = 1;
+       if (LINES < 5)
+          bottomrows = 1;
 
-    /* If there is no room to show anything, give up. */
-    if (editwinrows <= 0)
-       die(_("Window size is too small for nano...\n"));
+       editwinrows = LINES - toprows - bottomrows;
 
-    /* Set up the windows. */
-    topwin = newwin(TOP_ROWS, COLS, 0, 0);
-    edit = newwin(editwinrows, COLS, TOP_ROWS, 0);
-    bottomwin = newwin(BOTTOM_ROWS, COLS, TOP_ROWS + editwinrows, 0);
+       /* Set up the three subwindows. */
+       topwin = newwin(toprows, COLS, 0, 0);
+       edit = newwin(editwinrows, COLS, toprows, 0);
+       bottomwin = newwin(bottomrows, COLS, toprows + editwinrows, 0);
+    }
 
     /* Turn the keypad on for the windows, if necessary. */
     if (!ISSET(REBIND_KEYPAD)) {
diff --git a/src/winio.c b/src/winio.c
index faf69b3..7581214 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1639,7 +1639,7 @@ void blank_statusbar(void)
  * portion of the window. */
 void blank_bottombars(void)
 {
-    if (!ISSET(NO_HELP)) {
+    if (!ISSET(NO_HELP) && LINES > 4) {
        blank_line(bottomwin, 1, 0, COLS);
        blank_line(bottomwin, 2, 0, COLS);
     }
@@ -1840,6 +1840,10 @@ void titlebar(const char *path)
     char *fragment;
        /* The tail part of the pathname when dottified. */
 
+    /* If the screen is too small, there is no titlebar. */
+    if (topwin == NULL)
+       return;
+
     assert(path != NULL || openfile->filename != NULL);
 
     wattron(topwin, interface_color_pair[TITLE_BAR]);
@@ -2033,7 +2037,7 @@ void bottombars(int menu)
     /* Set the global variable to the given menu. */
     currmenu = menu;
 
-    if (ISSET(NO_HELP))
+    if (ISSET(NO_HELP) || LINES < 5)
        return;
 
     if (menu == MMAIN) {
-- 
2.9.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]