nano-devel
[Top][All Lists]
Advanced

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

[PATCH] possible new feature: the option --zero for an interface without


From: Benno Schulenberg
Subject: [PATCH] possible new feature: the option --zero for an interface without bars
Date: Sat, 6 Nov 2021 12:15:12 +0100

With --zero or 'set zero', nano will hide the title bar or the minibar
(whichever is active) and will use all rows of the terminal for showing
the text of the buffer.  Only when there is an important message will
it be shown on the bottom row -- until the next keystroke.

The option can be toggled with M-Z.

I haven't tested everything, so if you like this feature, please test
the patch (against current git, 0346e63c), and report any issues that
you find with your workflow, other than the next two.

* In the browser: when the highlighted item is on the bottom row, it
  will get obscured by the prompt bar or the "Search Wrapped" message.
  The only solution seems to be to use one row less.

* In the edit window, when the search occurrence is on the bottom row,
  it can get obscured by the "This is the only occurence" message.  I
  don't yet know how to prevent this.

The feedback at startup ("Read nnn lines") is suppressed with --zero,
because it disrupts the fullscreen experience and is hardly useful.
The "Reading..." message then needs to be suppressed too, otherwise
it creates an annoying little flash.
---
 src/definitions.h |  3 ++-
 src/files.c       |  6 +++---
 src/global.c      |  3 +++
 src/nano.c        | 54 +++++++++++++++++++++++++++++++----------------
 src/rcfile.c      |  3 +++
 src/winio.c       | 15 ++++++++-----
 6 files changed, 57 insertions(+), 27 deletions(-)

diff --git a/src/definitions.h b/src/definitions.h
index 916585e4..af62659d 100644
--- a/src/definitions.h
+++ b/src/definitions.h
@@ -357,7 +357,8 @@ enum {
        BOOKSTYLE,
        STATEFLAGS,
        USE_MAGIC,
-       MINIBAR
+       MINIBAR,
+       ZERO
 };
 
 /* Structure types. */
diff --git a/src/files.c b/src/files.c
index 007bd168..dbd0fdd5 100644
--- a/src/files.c
+++ b/src/files.c
@@ -819,7 +819,7 @@ void read_file(FILE *f, int fd, const char *filename, bool 
undoable)
                                                "Read %zu lines (Converted from 
DOS format)",
                                                num_lines), num_lines);
 #endif
-       else
+       else if (!ISSET(ZERO))
                statusline(HUSH, P_("Read %zu line", "Read %zu lines",
                                                num_lines), num_lines);
 
@@ -898,7 +898,7 @@ int open_file(const char *filename, bool new_one, FILE **f)
                        statusline(ALERT, _("Error reading %s: %s"), filename, 
strerror(errno));
                        close(fd);
                        fd = -1;
-               } else
+               } else if (!ISSET(ZERO))
                        statusbar(_("Reading..."));
        }
 
@@ -2030,7 +2030,7 @@ bool write_file(const char *name, FILE *thefile, bool 
normal,
        }
 
 #ifndef NANO_TINY
-       if (ISSET(MINIBAR) && LINES > 1 && annotate)
+       if (ISSET(MINIBAR) && !ISSET(ZERO) && LINES > 1 && annotate)
                report_size = TRUE;
        else
 #endif
diff --git a/src/global.c b/src/global.c
index 6424181e..92c423d7 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1355,6 +1355,7 @@ void shortcut_init(void)
 #ifndef NANO_TINY
        /* Group of "Appearance" toggles. */
        add_to_sclist((MMOST|MBROWSER|MYESNO) & ~MFINDINHELP, "M-X", 0, 
do_toggle_void, NO_HELP);
+       add_to_sclist(MMAIN, "M-Z", 0, do_toggle_void, ZERO);
        add_to_sclist(MMAIN, "M-C", 0, do_toggle_void, CONSTANT_SHOW);
        add_to_sclist(MMAIN, "M-S", 0, do_toggle_void, SOFTWRAP);
        add_to_sclist(MMAIN, "M-$", 0, do_toggle_void, SOFTWRAP);  /* Legacy 
keystroke. */
@@ -1523,6 +1524,8 @@ const char *flagtostr(int flag)
                        return N_("Mouse support");
                case LINE_NUMBERS:
                        return N_("Line numbering");
+               case ZERO:
+                       return N_("Hidden interface");
                default:
                        die("Bad toggle -- please report a bug\n");
                        return "";
diff --git a/src/nano.c b/src/nano.c
index 51b3bad2..83e086bf 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -414,26 +414,26 @@ void window_init(void)
 
        /* If the terminal is very flat, don't set up a title bar. */
        if (LINES < 3) {
-               editwinrows = 1;
+               editwinrows = (ISSET(ZERO) ? LINES : 1);
                /* Set up two subwindows.  If the terminal is just one line,
                 * edit window and status-bar window will cover each other. */
-               edit = newwin(1, COLS, 0, 0);
+               edit = newwin(editwinrows, COLS, 0, 0);
                bottomwin = newwin(1, COLS, LINES - 1, 0);
        } else {
                int toprows = ((ISSET(EMPTY_LINE) && LINES > 5) ? 2 : 1);
                int bottomrows = ((ISSET(NO_HELP) || LINES < 5) ? 1 : 3);
 
 #ifndef NANO_TINY
-               if (ISSET(MINIBAR))
+               if (ISSET(MINIBAR) || ISSET(ZERO))
                        toprows = 0;
 #endif
-               editwinrows = LINES - toprows - bottomrows;
+               editwinrows = LINES - toprows - bottomrows + (ISSET(ZERO) ? 1 : 
0);
 
                /* Set up the normal three subwindows. */
                if (toprows > 0)
                        topwin = newwin(toprows, COLS, 0, 0);
                edit = newwin(editwinrows, COLS, toprows, 0);
-               bottomwin = newwin(bottomrows, COLS, toprows + editwinrows, 0);
+               bottomwin = newwin(bottomrows, COLS, LINES - bottomrows, 0);
        }
 
        /* In case the terminal shrunk, make sure the status line is clear. */
@@ -653,6 +653,7 @@ void usage(void)
        print_opt("-y", "--afterends", N_("Make Ctrl+Right stop at word ends"));
        print_opt("-%", "--stateflags", N_("Show some states on the title 
bar"));
        print_opt("-_", "--minibar", N_("Show a feedback bar at the bottom"));
+       print_opt("-0", "--zero", N_("Hide all bars, use whole terminal"));
 #endif
 #ifdef HAVE_LIBMAGIC
        print_opt("-!", "--magic", N_("Also try magic to determine syntax"));
@@ -1071,6 +1072,7 @@ void do_toggle(int flag)
 
        switch (flag) {
                case NO_HELP:
+               case ZERO:
                        window_init();
                        draw_all_subwindows();
                        break;
@@ -1096,7 +1098,10 @@ void do_toggle(int flag)
 #endif
        }
 
-       if (ISSET(STATEFLAGS) && (flag == AUTOINDENT ||
+       if (flag == ZERO)
+               return;
+
+       if (ISSET(STATEFLAGS) && !ISSET(ZERO) && (flag == AUTOINDENT ||
                                                        flag == 
BREAK_LONG_LINES ||     flag == SOFTWRAP)) {
                if (ISSET(MINIBAR))
                        return;
@@ -1104,12 +1109,16 @@ void do_toggle(int flag)
                        titlebar(NULL);
        }
 
-       if (ISSET(MINIBAR) && (flag == NO_HELP || flag == LINE_NUMBERS))
+       if ((ISSET(MINIBAR) || ISSET(ZERO)) && (flag == NO_HELP || flag == 
LINE_NUMBERS))
                return;
 
-       if (flag == CONSTANT_SHOW)
-               wipe_statusbar();
-       else {
+       if (flag == CONSTANT_SHOW) {
+               if (ISSET(ZERO)) {
+                       statusline(AHEM, _("Not possible in barless mode"));
+                       TOGGLE(flag);
+               } else if (!ISSET(MINIBAR))
+                       wipe_statusbar();
+       } else {
                bool enabled = ISSET(flag);
 
                if (flag == NO_HELP || flag == NO_SYNTAX)
@@ -1760,6 +1769,7 @@ int main(int argc, char **argv)
                {"afterends", 0, NULL, 'y'},
                {"stateflags", 0, NULL, '%'},
                {"minibar", 0, NULL, '_'},
+               {"zero", 0, NULL, '0'},
 #endif
 #ifdef HAVE_LIBMAGIC
                {"magic", 0, NULL, '!'},
@@ -1803,7 +1813,7 @@ int main(int argc, char **argv)
        if (*(tail(argv[0])) == 'r')
                SET(RESTRICTED);
 
-       while ((optchr = getopt_long(argc, argv, 
"ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z"
+       while ((optchr = getopt_long(argc, argv, 
"0ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z"
                                "abcdef:ghijklmno:pqr:s:tuvwxyz$%_!", 
long_options, NULL)) != -1) {
                switch (optchr) {
 #ifndef NANO_TINY
@@ -2046,6 +2056,9 @@ int main(int argc, char **argv)
                        case '_':
                                SET(MINIBAR);
                                break;
+                       case '0':
+                               SET(ZERO);
+                               break;
 #endif
 #ifdef HAVE_LIBMAGIC
                        case '!':
@@ -2514,25 +2527,30 @@ int main(int argc, char **argv)
                        bottombars(MMAIN);
 
 #ifndef NANO_TINY
-               if (ISSET(MINIBAR) && LINES > 1 && lastmessage < REMARK)
+               if (ISSET(MINIBAR) && !ISSET(ZERO) && LINES > 1 && lastmessage 
< REMARK)
                        minibar();
                else
 #endif
                /* Update the displayed current cursor position only when there
                 * is no message and no keys are waiting in the input buffer. */
                if (ISSET(CONSTANT_SHOW) && lastmessage == VACUUM && LINES > 1 
&&
-                                                                               
get_key_buffer_len() == 0)
+                                                               !ISSET(ZERO) && 
get_key_buffer_len() == 0)
                        report_cursor_position();
 
                as_an_at = TRUE;
 
-               /* Refresh just the cursor position or the entire edit window. 
*/
-               if (!refresh_needed) {
-                       place_the_cursor();
-                       wnoutrefresh(edit);
-               } else if (LINES > 1 || lastmessage == VACUUM)
+               if (refresh_needed && (LINES > 1 || lastmessage == VACUUM))
                        edit_refresh();
 
+               /* When there are no bars, redraw a relevant status message. */
+               if (ISSET(ZERO) && lastmessage > HUSH) {
+                       redrawwin(bottomwin);
+                       wnoutrefresh(bottomwin);
+               }
+
+               place_the_cursor();
+               wnoutrefresh(edit);
+
                errno = 0;
                focusing = TRUE;
 
diff --git a/src/rcfile.c b/src/rcfile.c
index 22016adf..1c6f8dcc 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -122,6 +122,7 @@ static const rcoption rcopts[] = {
        {"wordbounds", WORD_BOUNDS},
        {"wordchars", 0},
        {"zap", LET_THEM_ZAP},
+       {"zero", ZERO},
 #endif
 #ifdef ENABLE_COLOR
        {"titlecolor", 0},
@@ -451,6 +452,8 @@ keystruct *strtosc(const char *input)
                s->func = do_toggle_void;
                if (!strcmp(input, "nohelp"))
                        s->toggle = NO_HELP;
+               else if (!strcmp(input, "zero"))
+                       s->toggle = ZERO;
                else if (!strcmp(input, "constantshow"))
                        s->toggle = CONSTANT_SHOW;
                else if (!strcmp(input, "softwrap"))
diff --git a/src/winio.c b/src/winio.c
index d05c30de..235ea8a4 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -192,6 +192,9 @@ void read_keys_from(WINDOW *win)
        if (reveal_cursor && !hide_cursor && (LINES > 1 || lastmessage <= HUSH))
                curs_set(1);
 
+       if (ISSET(ZERO) && openfile->current_y == editwinrows - 1 && 
lastmessage > HUSH)
+               curs_set(0);
+
 #ifndef NANO_TINY
        if (currmenu == MMAIN && (spotlighted || ((ISSET(MINIBAR) || LINES == 
1) &&
                                                lastmessage > HUSH &&
@@ -224,7 +227,7 @@ void read_keys_from(WINDOW *win)
                                        wnoutrefresh(edit);
                                        curs_set(1);
                                }
-                               if (ISSET(MINIBAR) && LINES > 1)
+                               if (ISSET(MINIBAR) && !ISSET(ZERO) && LINES > 1)
                                        minibar();
                                as_an_at = TRUE;
                                place_the_cursor();
@@ -1699,14 +1702,14 @@ void check_statusblank(void)
        statusblank--;
 
        /* When editing and 'constantshow' is active, skip the blanking. */
-       if (currmenu == MMAIN && ISSET(CONSTANT_SHOW) && LINES > 1)
+       if (currmenu == MMAIN && ISSET(CONSTANT_SHOW) && !ISSET(MINIBAR) && 
LINES > 1)
                return;
 
        if (statusblank == 0)
                wipe_statusbar();
 
        /* If the subwindows overlap, make sure to show the edit window now. */
-       if (LINES == 1)
+       if (currmenu == MMAIN && (ISSET(ZERO) || LINES == 1))
                edit_refresh();
 }
 
@@ -3328,6 +3331,8 @@ bool current_is_above_screen(void)
                return (openfile->current->lineno < openfile->edittop->lineno);
 }
 
+#define SHIM  (ISSET(ZERO) && (currmenu == MREPLACEWITH || currmenu == MYESNO) 
? 1 : 0)
+
 /* Return TRUE if current[current_x] is beyond the viewport. */
 bool current_is_below_screen(void)
 {
@@ -3338,14 +3343,14 @@ bool current_is_below_screen(void)
 
                /* If current[current_x] is more than a screen's worth of lines 
after
                 * edittop at column firstcolumn, it's below the screen. */
-               return (go_forward_chunks(editwinrows - 1, &line, &leftedge) == 
0 &&
+               return (go_forward_chunks(editwinrows - 1 - SHIM, &line, 
&leftedge) == 0 &&
                                                (line->lineno < 
openfile->current->lineno ||
                                                (line->lineno == 
openfile->current->lineno &&
                                                leftedge < 
leftedge_for(xplustabs(), openfile->current))));
        } else
 #endif
                return (openfile->current->lineno >=
-                                               openfile->edittop->lineno + 
editwinrows);
+                                               openfile->edittop->lineno + 
editwinrows - SHIM);
 }
 
 /* Return TRUE if current[current_x] is outside the viewport. */
-- 
2.29.3




reply via email to

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