>From ee42fb6f45c33206f29a67ca106e70b96bca9acb Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Tue, 13 Mar 2018 16:29:33 -0600 Subject: [PATCH] add vertical scroll arrows Signed-off-by: Brand Huntsman --- src/winio.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 17 deletions(-) diff --git a/src/winio.c b/src/winio.c index 9257fe79..cdf4ac06 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1986,6 +1986,53 @@ int buffer_number(openfilestruct *buffer) return count; } +/* Draw up/down arrows or percentage on right side of titlebar. */ +static void scrollbar(bool refresh){ + bool at_top = (openfile->edittop == openfile->fileage); + bool at_bot = (openfile->edittop->lineno + editwinrows >= + openfile->filebot->lineno); + + wattron(topwin, interface_color_pair[TITLE_BAR]); + + wmove(topwin, 0, COLS - 3); + + /* sblen in titlebar() is scrollbar width + 1 */ + + if (at_top && at_bot) { + waddstr(topwin, " "); + } else if (at_top) { +#ifdef ENABLE_UTF8 + if(using_utf8()) + waddstr(topwin, " \xE2\x96\xbc "); /* down arrow */ + else +#endif + waddstr(topwin, " + "); +// waddstr(topwin, " v "); + } else if (at_bot) { +#ifdef ENABLE_UTF8 + if(using_utf8()) + waddstr(topwin, " \xE2\x96\xb2 "); /* up arrow */ + else +#endif + waddstr(topwin, " - "); +// waddstr(topwin, " ^ "); + } else { + char pctstr[4]; + int pct = 100 * openfile->edittop->lineno / + (openfile->filebot->lineno - editwinrows); + if (pct < 10) + snprintf(pctstr, sizeof(pctstr), " %d%%", pct); + else + snprintf(pctstr, sizeof(pctstr), "%d%%", pct); + waddstr(topwin, pctstr); + } + + wattroff(topwin, interface_color_pair[TITLE_BAR]); + + if(refresh) + wrefresh(topwin); +} + /* If path is NULL, we're in normal editing mode, so display the current * version of nano, the current filename, and whether the current file * has been modified on the titlebar. If path isn't NULL, we're either @@ -1999,6 +2046,8 @@ void titlebar(const char *path) /* The width that "Modified" would take up. */ size_t offset = 0; /* The position at which the center part of the titlebar starts. */ + const size_t sblen = 4; + /* The width always reserved for scrollbar. */ const char *upperleft = ""; /* What is shown in the top left corner. */ const char *prefix = ""; @@ -2058,36 +2107,35 @@ void titlebar(const char *path) if (prefixlen > 0) prefixlen++; pathlen = strlenpt(path); - statelen = strlenpt(state) + 2; - if (statelen > 2) { + statelen = strlenpt(state); + if (statelen > 0) { pathlen++; pluglen = 0; } /* Only print the version message when there is room for it. */ - if (verlen + prefixlen + pathlen + pluglen + statelen <= COLS) + if (verlen + prefixlen + pathlen + pluglen + statelen + sblen <= COLS) mvwaddstr(topwin, 0, 2, upperleft); else { verlen = 2; /* If things don't fit yet, give up the placeholder. */ - if (verlen + prefixlen + pathlen + pluglen + statelen > COLS) + if (verlen + prefixlen + pathlen + pluglen + statelen + sblen > COLS) pluglen = 0; - /* If things still don't fit, give up the side spaces. */ - if (verlen + prefixlen + pathlen + pluglen + statelen > COLS) { + /* If things still don't fit, give up the left side space. */ + if (verlen + prefixlen + pathlen + pluglen + statelen + sblen > COLS) verlen = 0; - statelen -= 2; - } } free(indicator); /* If we have side spaces left, center the path name. */ if (verlen > 0) - offset = verlen + (COLS - (verlen + pluglen + statelen) - - (prefixlen + pathlen)) / 2; + offset = verlen + (COLS - + (verlen + pluglen + statelen + sblen) - + (prefixlen + pathlen)) / 2; /* Only print the prefix when there is room for it. */ - if (verlen + prefixlen + pathlen + pluglen + statelen <= COLS) { + if (verlen + prefixlen + pathlen + pluglen + statelen + sblen <= COLS) { mvwaddstr(topwin, 0, offset, prefix); if (prefixlen > 0) waddstr(topwin, " "); @@ -2095,26 +2143,29 @@ void titlebar(const char *path) wmove(topwin, 0, offset); /* Print the full path if there's room; otherwise, dottify it. */ - if (pathlen + pluglen + statelen <= COLS) { + if (pathlen + pluglen + statelen + sblen <= COLS) { caption = display_string(path, 0, pathlen, FALSE); waddstr(topwin, caption); free(caption); - } else if (5 + statelen <= COLS) { + } else if (5 + statelen + sblen <= COLS) { waddstr(topwin, "..."); - caption = display_string(path, 3 + pathlen - COLS + statelen, - COLS - statelen, FALSE); + caption = display_string(path, + 3 + pathlen - COLS + statelen + sblen, + COLS - (statelen + sblen), FALSE); waddstr(topwin, caption); free(caption); } /* Right-align the state if there's room; otherwise, trim it. */ - if (statelen > 0 && statelen <= COLS) - mvwaddstr(topwin, 0, COLS - statelen, state); + if (statelen > 0 && statelen + sblen <= COLS) + mvwaddstr(topwin, 0, COLS - (statelen + sblen), state); else if (statelen > 0) mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS)); wattroff(topwin, interface_color_pair[TITLE_BAR]); + scrollbar(FALSE); + wrefresh(topwin); } @@ -3207,6 +3258,8 @@ void edit_redraw(filestruct *old_current, update_type manner) (old_current != openfile->current && get_page_start(openfile->placewewant) > 0)) update_line(openfile->current, openfile->current_x); + + scrollbar(TRUE); } /* Refresh the screen without changing the position of lines. Use this @@ -3239,6 +3292,8 @@ void edit_refresh(void) while (row < editwinrows) blank_row(edit, row++, 0, COLS); + scrollbar(TRUE); + place_the_cursor(); wnoutrefresh(edit); @@ -3300,6 +3355,8 @@ void total_refresh(void) edit_refresh(); wipe_statusbar(); bottombars(currmenu); + + scrollbar(TRUE); } /* Display the main shortcut list on the last two rows of the bottom -- 2.16.1