nano

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

commit 7b48458380ea0554d508faba351679fc88f13b58
parent 1e16a3f4113f80454768d4898d7bc2c6032b37a3
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 29 Dec 2020 13:21:07 +0100

minibar: suppress some elements when there is no room to show them

This fixes https://savannah.gnu.org/bugs/?59767.

Bug existed since last week, since the mini-bar code was merged.

Diffstat:
Msrc/nano.c | 4++--
Msrc/winio.c | 41++++++++++++++++++++++++++++++++++-------
2 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -409,7 +409,7 @@ void window_init(void) int bottomrows = ((ISSET(NO_HELP) || LINES < 5) ? 1 : 3); #ifndef NANO_TINY - if (ISSET(MINIBAR) && COLS > 48) + if (ISSET(MINIBAR)) toprows = 0; #endif editwinrows = LINES - toprows - bottomrows; @@ -2516,7 +2516,7 @@ int main(int argc, char **argv) bottombars(MMAIN); #ifndef NANO_TINY - if (ISSET(MINIBAR) && COLS > 48 && lastmessage < REMARK) + if (ISSET(MINIBAR) && lastmessage < REMARK) minibar(); else #endif diff --git a/src/winio.c b/src/winio.c @@ -2073,6 +2073,8 @@ void minibar(void) char *hexadecimal = nmalloc(9); char *location = nmalloc(44); char *thename = NULL, *number_of_lines = NULL, *ranking = NULL; + size_t namewidth, placewidth; + size_t padding = 2; wchar_t widecode; /* Draw a colored bar over the full width of the screen. */ @@ -2082,33 +2084,53 @@ void minibar(void) /* Display the name of the current file, plus a star when modified. */ if (openfile->filename[0] != '\0') { as_an_at = FALSE; - thename = display_string(openfile->filename, 0, COLS - 18, FALSE, FALSE); + thename = display_string(openfile->filename, 0, HIGHEST_POSITIVE, FALSE, FALSE); } else thename = copy_of(_("(nameless)")); - mvwaddstr(bottomwin, 0, 2, thename); + + sprintf(location, "%zi,%lu", openfile->current->lineno, xplustabs() + 1); + placewidth = strlen(location); + namewidth = breadth(thename); + + if (COLS < 12 || namewidth > COLS - 11) + padding = 0; + + if (COLS > 4) { + /* If the full file name doesn't fit, dottify it. */ + if (namewidth > COLS - 2) { + thename = display_string(thename, namewidth - COLS + 5, COLS - 5, FALSE, FALSE); + mvwaddstr(bottomwin, 0, 0, "..."); + waddstr(bottomwin, thename); + } else + mvwaddstr(bottomwin, 0, padding, thename); + waddstr(bottomwin, openfile->modified ? " *" : " "); + } - if (report_size) { + if (report_size && COLS > 35) { size_t count = openfile->filebot->lineno - (openfile->filebot->data[0] == '\0'); number_of_lines = nmalloc(44); sprintf(number_of_lines, P_(" (%zu line)", " (%zu lines)", count), count); + if (namewidth + placewidth + breadth(number_of_lines) < COLS - 32) waddstr(bottomwin, number_of_lines); report_size = FALSE; } #ifdef ENABLE_MULTIBUFFER - else if (openfile->next != openfile) { + else if (openfile->next != openfile && COLS > 35) { ranking = nmalloc(24); sprintf(ranking, " [%i/%i]", buffer_number(openfile), buffer_number(startfile->prev)); + if (namewidth + placewidth + breadth(ranking) < COLS - 32) waddstr(bottomwin, ranking); } #endif /* Display the line/column position of the cursor. */ - sprintf(location, "%zi,%lu", openfile->current->lineno, xplustabs() + 1); - mvwaddstr(bottomwin, 0, COLS - 27 - strlen(location), location); + if (namewidth + placewidth < COLS - 32 && COLS > 35) + mvwaddstr(bottomwin, 0, COLS - 27 - placewidth, location); /* Display the hexadecimal code of the character under the cursor. */ + if (namewidth < COLS - 27 && COLS > 29) { if (thisline[openfile->current_x] == '\0') sprintf(hexadecimal, openfile->current->next ? "U+000A" : "------"); else if (thisline[openfile->current_x] == '\n') @@ -2119,14 +2141,19 @@ void minibar(void) else sprintf(hexadecimal, "U+%04X", (unsigned char)thisline[openfile->current_x]); mvwaddstr(bottomwin, 0, COLS - 23, hexadecimal); + } /* Display the state of three flags, and the state of macro and mark. */ + if (namewidth < COLS - 17 && COLS > 19) { wmove(bottomwin, 0, COLS - 13); show_states_at(bottomwin); + } /* Display how many percent the current line is into the file. */ + if (namewidth < COLS - 6 && COLS > 7) { sprintf(location, "%3li%%", 100 * openfile->current->lineno / openfile->filebot->lineno); - mvwaddstr(bottomwin, 0, COLS - 6, location); + mvwaddstr(bottomwin, 0, COLS - 4 - padding, location); + } wattroff(bottomwin, interface_color_pair[TITLE_BAR]); wrefresh(bottomwin);