nano-devel
[Top][All Lists]
Advanced

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

[PATCH] possible new feature: a position+portion indicator on the righth


From: Benno Schulenberg
Subject: [PATCH] possible new feature: a position+portion indicator on the righthand side
Date: Sun, 26 Apr 2020 12:09:10 +0200

[This scrollbar is optionless for the moment, for ease of testing.]

[The scrollbar is suppressed in softwrap mode, because it costs
too much computation to determine the total number of chunks, and
the number of displayed chunks is known only after the screen is
fully drawn, not while drawing it.]

This fulfills https://savannah.gnu.org/bugs/?57956.

Original-patch-by: Marco Diego Aurélio Mesquita <address@hidden>
---
 src/global.c |  2 ++
 src/help.c   | 10 +++++-----
 src/nano.c   | 18 ++++++++++++++----
 src/proto.h  |  1 +
 src/winio.c  | 41 ++++++++++++++++++++++++++++++++++++++---
 5 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/src/global.c b/src/global.c
index a6999e72..9d155c54 100644
--- a/src/global.c
+++ b/src/global.c
@@ -131,6 +131,8 @@ int editwincols = -1;
                /* The number of usable columns in the edit window: COLS - 
margin. */
 int margin = 0;
                /* The amount of space reserved at the left for line numbers. */
+int thebar = 0;
+               /* Becomes 1 when a scrollbar is shown. */
 #ifndef NANO_TINY
 ssize_t stripe_column = 0;
                /* The column at which a vertical bar will be drawn. */
diff --git a/src/help.c b/src/help.c
index 59a45a4d..664ade00 100644
--- a/src/help.c
+++ b/src/help.c
@@ -44,7 +44,7 @@ void wrap_help_text_into_buffer(void)
 {
        size_t sum = 0;
        /* Avoid overtight and overwide paragraphs in the introductory text. */
-       size_t wrapping_point = (COLS < 40) ? 40 : (COLS > 74) ? 74 : COLS;
+       size_t wrapping_point = ((COLS < 40) ? 40 : (COLS > 74) ? 74 : COLS) - 
thebar;
        const char *ptr = start_of_body;
 
        make_new_buffer();
@@ -55,7 +55,7 @@ void wrap_help_text_into_buffer(void)
                char *oneline;
 
                if (ptr == end_of_intro)
-                       wrapping_point = (COLS < 40) ? 40 : COLS;
+                       wrapping_point = ((COLS < 40) ? 40 : COLS) - thebar;
 
                if (ptr < end_of_intro || *(ptr - 1) == '\n') {
                        length = break_line(ptr, wrapping_point, TRUE);
@@ -63,7 +63,7 @@ void wrap_help_text_into_buffer(void)
                        shim = (*(ptr + length - 1) == ' ') ? 0 : 1;
                        snprintf(oneline, length + shim, "%s", ptr);
                } else {
-                       length = break_line(ptr, (COLS < 40) ? 22 : COLS - 18, 
TRUE);
+                       length = break_line(ptr, ((COLS < 40) ? 22 : COLS - 18) 
- thebar, TRUE);
                        oneline = nmalloc(length + 5);
                        snprintf(oneline, length + 5, "\t\t  %s", ptr);
                }
@@ -145,7 +145,7 @@ void show_help(void)
 
 #ifdef ENABLE_LINENUMBERS
        UNSET(LINE_NUMBERS);
-       editwincols = COLS;
+       editwincols = COLS - thebar;
        margin = 0;
 #endif
        tabsize = 8;
@@ -250,7 +250,7 @@ void show_help(void)
 
 #ifdef ENABLE_LINENUMBERS
        margin = was_margin;
-       editwincols = COLS - margin;
+       editwincols = COLS - margin - thebar;
 #endif
        tabsize = was_tabsize;
 #ifdef ENABLE_COLOR
diff --git a/src/nano.c b/src/nano.c
index 024a5f19..0a38a345 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1041,7 +1041,10 @@ void regenerate_screen(void)
        COLS = win.ws_col;
        LINES = win.ws_row;
 #endif
-       editwincols = COLS - margin;
+#ifndef NANO_TINY
+       thebar = (LINES > 9 && COLS > 9 && !ISSET(SOFTWRAP)) ? 1 : 0;
+#endif
+       editwincols = COLS - margin - thebar;
 
        /* Ensure that firstcolumn is the starting column of its chunk. */
        ensure_firstcolumn_is_aligned();
@@ -1082,8 +1085,12 @@ void do_toggle(int flag)
                        signal_init();
                        break;
                case SOFTWRAP:
-                       if (!ISSET(SOFTWRAP))
+                       if (!ISSET(SOFTWRAP)) {
+                               thebar = (LINES > 9 && COLS > 9) ? 1 : 0;
                                openfile->firstcolumn = 0;
+                       } else
+                               thebar  = 0;
+                       editwincols = COLS - margin - thebar;
                        refresh_needed = TRUE;
                        break;
                case WHITESPACE_DISPLAY:
@@ -1245,7 +1252,7 @@ void confirm_margin(void)
 
        if (needed_margin != margin) {
                margin = needed_margin;
-               editwincols = COLS - margin;
+               editwincols = COLS - margin - thebar;
 
 #ifndef NANO_TINY
                /* Ensure that firstcolumn is the starting column of its chunk. 
*/
@@ -2273,7 +2280,10 @@ int main(int argc, char **argv)
        window_init();
        curs_set(0);
 
-       editwincols = COLS;
+#ifndef NANO_TINY
+       thebar = (LINES > 9 && COLS > 9 && !ISSET(SOFTWRAP)) ? 1 : 0;
+#endif
+       editwincols = COLS - thebar;
 
        /* Set up the signal handlers. */
        signal_init();
diff --git a/src/proto.h b/src/proto.h
index 9ee22d6d..9eed0174 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -93,6 +93,7 @@ extern WINDOW *bottomwin;
 extern int editwinrows;
 extern int editwincols;
 extern int margin;
+extern int thebar;
 #ifndef NANO_TINY
 extern ssize_t stripe_column;
 #endif
diff --git a/src/winio.c b/src/winio.c
index eb89e16d..231fc881 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2780,7 +2780,7 @@ int update_line(linestruct *line, size_t index)
        }
        if (has_more) {
                wattron(edit, hilite_attribute);
-               mvwaddch(edit, row, COLS - 1, '>');
+               mvwaddch(edit, row, COLS - 1 - thebar, '>');
                wattroff(edit, hilite_attribute);
        }
 
@@ -2960,6 +2960,27 @@ bool less_than_a_screenful(size_t was_lineno, size_t 
was_leftedge)
                return (openfile->current->lineno - was_lineno < editwinrows);
 }
 
+#ifndef NANO_TINY
+/* Draw a scroll bar on the righthand side of the screen. */
+void draw_scrollbar(void)
+{
+       int totalrows = openfile->filebot->lineno;
+       int lowest = ((openfile->edittop->lineno - 1) * editwinrows) / 
totalrows;
+       int highest = lowest + (editwinrows * editwinrows) / totalrows;
+
+       if (editwinrows > totalrows)
+               highest = editwinrows;
+
+       for (int row = 0; row < editwinrows; row++) {
+               int style = A_REVERSE | ((row >= lowest && row <= highest) ? 0 
: A_DIM);
+
+               wattron(edit, style);
+               mvwaddch(edit, row, COLS - 1, ' ');
+               wattroff(edit, style);
+       }
+}
+#endif
+
 /* Scroll the edit window one row in the given direction, and
  * draw the relevant content on the resultant blank row. */
 void edit_scroll(bool direction)
@@ -3010,6 +3031,11 @@ void edit_scroll(bool direction)
                                                                                
openfile->current_x : 0);
                line = line->next;
        }
+
+#ifndef NANO_TINY
+       if (thebar)
+               draw_scrollbar();
+#endif
 }
 
 #ifndef NANO_TINY
@@ -3246,8 +3272,13 @@ void edit_redraw(linestruct *old_current, update_type 
manner)
         * differs from old_current and needs to be horizontally scrolled. */
        if (line_needs_update(was_pww, openfile->placewewant) ||
                                                (old_current != 
openfile->current &&
-                                               
get_page_start(openfile->placewewant) > 0))
+                                               
get_page_start(openfile->placewewant) > 0)) {
                update_line(openfile->current, openfile->current_x);
+#ifndef NANO_TINY
+               if (thebar)
+                       draw_scrollbar();
+#endif
+       }
 }
 
 /* Refresh the screen without changing the position of lines.  Use this
@@ -3280,6 +3311,10 @@ void edit_refresh(void)
        while (row < editwinrows)
                blank_row(edit, row++);
 
+#ifndef NANO_TINY
+       if (thebar)
+               draw_scrollbar();
+#endif
        place_the_cursor();
        wnoutrefresh(edit);
 
@@ -3426,7 +3461,7 @@ void spotlight(size_t from_col, size_t to_col)
        wattron(edit, interface_color_pair[SELECTED_TEXT]);
        waddnstr(edit, word, actual_x(word, to_col));
        if (overshoots)
-               mvwaddch(edit, openfile->current_y, COLS - 1, '>');
+               mvwaddch(edit, openfile->current_y, COLS - 1 - thebar, '>');
        wattroff(edit, interface_color_pair[SELECTED_TEXT]);
 
        free(word);
-- 
2.25.4




reply via email to

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