statusbar: leave out the brackets when the message is very long

This also prevents the message from spilling into the help lines
when the terminal is less than four columns wide.  (Not that one
can read anything then, but it looks better.)
master
Benno Schulenberg 2016-08-15 22:25:52 +02:00
parent c22cd03f18
commit ea9aaee8c7
1 changed files with 11 additions and 7 deletions

View File

@ -1958,6 +1958,7 @@ void statusline(message_type importance, const char *msg, ...)
va_list ap; va_list ap;
char *bar, *foo; char *bar, *foo;
size_t start_x; size_t start_x;
bool bracketed;
#ifndef NANO_TINY #ifndef NANO_TINY
bool old_whitespace = ISSET(WHITESPACE_DISPLAY); bool old_whitespace = ISSET(WHITESPACE_DISPLAY);
@ -1993,24 +1994,27 @@ void statusline(message_type importance, const char *msg, ...)
blank_statusbar(); blank_statusbar();
bar = charalloc(mb_cur_max() * (COLS - 3)); bar = charalloc(mb_cur_max() * (COLS + 1));
vsnprintf(bar, mb_cur_max() * (COLS - 3), msg, ap); vsnprintf(bar, mb_cur_max() * (COLS + 1), msg, ap);
va_end(ap); va_end(ap);
foo = display_string(bar, 0, COLS - 4, FALSE); foo = display_string(bar, 0, COLS, FALSE);
free(bar); free(bar);
#ifndef NANO_TINY #ifndef NANO_TINY
if (old_whitespace) if (old_whitespace)
SET(WHITESPACE_DISPLAY); SET(WHITESPACE_DISPLAY);
#endif #endif
start_x = (COLS - strlenpt(foo) - 4) / 2; start_x = (COLS - strlenpt(foo)) / 2;
bracketed = (start_x > 1);
wmove(bottomwin, 0, start_x); wmove(bottomwin, 0, (bracketed ? start_x - 2 : start_x));
wattron(bottomwin, interface_color_pair[STATUS_BAR]); wattron(bottomwin, interface_color_pair[STATUS_BAR]);
waddstr(bottomwin, "[ "); if (bracketed)
waddstr(bottomwin, "[ ");
waddstr(bottomwin, foo); waddstr(bottomwin, foo);
free(foo); free(foo);
waddstr(bottomwin, " ]"); if (bracketed)
waddstr(bottomwin, " ]");
wattroff(bottomwin, interface_color_pair[STATUS_BAR]); wattroff(bottomwin, interface_color_pair[STATUS_BAR]);
/* Push the message to the screen straightaway. */ /* Push the message to the screen straightaway. */