add some miscellaneous fixes for titlebar()

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2161 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-12-05 05:42:46 +00:00
parent 846658eb6b
commit f326ed7910
2 changed files with 21 additions and 14 deletions

View File

@ -92,6 +92,11 @@ CVS code -
the paragraph search left us on the magicline, so as to avoid the paragraph search left us on the magicline, so as to avoid
a segfault. (DLR) a segfault. (DLR)
- winio.c: - winio.c:
titlebar()
- Rename some variables for consistency, properly handle the
case where the prefix length plus the path length is greater
than the amount of space available, and fix a typo in an
assert(). (DLR)
unget_kbinput() unget_kbinput()
- Remove the wide character handling, as it didn't work properly - Remove the wide character handling, as it didn't work properly
with respect to function keys. (DLR) with respect to function keys. (DLR)

View File

@ -2239,11 +2239,11 @@ void titlebar(const char *path)
/* strlen(state) + 1. */ /* strlen(state) + 1. */
char *exppath = NULL; char *exppath = NULL;
/* The file name, expanded for display. */ /* The file name, expanded for display. */
size_t explen = 0; size_t exppathlen = 0;
/* strlen(exppath) + 1. */ /* strlen(exppath) + 1. */
int newbuffer = FALSE; bool newfie = FALSE;
/* Do we say "New Buffer"? */ /* Do we say "New Buffer"? */
int dots = FALSE; bool dots = FALSE;
/* Do we put an ellipsis before the path? */ /* Do we put an ellipsis before the path? */
assert(path != NULL || filename != NULL); assert(path != NULL || filename != NULL);
@ -2295,20 +2295,23 @@ void titlebar(const char *path)
#endif #endif
if (filename[0] == '\0') { if (filename[0] == '\0') {
prefix = _("New Buffer"); prefix = _("New Buffer");
newbuffer = TRUE; newfie = TRUE;
} else } else
prefix = _("File:"); prefix = _("File:");
assert(statelen < space); assert(statelen < space);
prefixlen = strnlen(prefix, space - statelen); prefixlen = strnlen(prefix, space - statelen);
/* If newbuffer is FALSE, we need a space after prefix. */ /* If newfie is FALSE, we need a space after prefix. */
if (!newbuffer && prefixlen + statelen < space) if (!newfie && prefixlen + statelen < space)
prefixlen++; prefixlen++;
if (path == NULL) if (path == NULL)
path = filename; path = filename;
if (space >= prefixlen + statelen)
space -= prefixlen + statelen; space -= prefixlen + statelen;
else
space = 0;
/* space is now the room we have for the file name. */ /* space is now the room we have for the file name. */
if (!newbuffer) { if (!newfie) {
size_t lenpt = strlenpt(path), start_col; size_t lenpt = strlenpt(path), start_col;
if (lenpt > space) if (lenpt > space)
@ -2317,14 +2320,14 @@ void titlebar(const char *path)
start_col = 0; start_col = 0;
exppath = display_string(path, start_col, space); exppath = display_string(path, start_col, space);
dots = (lenpt > space); dots = (lenpt > space);
explen = strlen(exppath); exppathlen = strlen(exppath);
} }
if (!dots) { if (!dots) {
/* There is room for the whole filename, so we center it. */ /* There is room for the whole filename, so we center it. */
waddnstr(topwin, hblank, (space - explen) / 3); waddnstr(topwin, hblank, (space - exppathlen) / 3);
waddnstr(topwin, prefix, prefixlen); waddnstr(topwin, prefix, prefixlen);
if (!newbuffer) { if (!newfie) {
assert(strlen(prefix) + 1 == prefixlen); assert(strlen(prefix) + 1 == prefixlen);
waddch(topwin, ' '); waddch(topwin, ' ');
waddstr(topwin, exppath); waddstr(topwin, exppath);
@ -2332,19 +2335,18 @@ void titlebar(const char *path)
} else { } else {
/* We will say something like "File: ...ename". */ /* We will say something like "File: ...ename". */
waddnstr(topwin, prefix, prefixlen); waddnstr(topwin, prefix, prefixlen);
if (space <= 0 || newbuffer) if (space == 0 || newfie)
goto the_end; goto the_end;
waddch(topwin, ' '); waddch(topwin, ' ');
waddnstr(topwin, "...", space); waddnstr(topwin, "...", space);
if (space <= 3) if (space <= 3)
goto the_end; goto the_end;
space -= 3; space -= 3;
assert(explen = space + 3); assert(exppathlen == space + 3);
waddnstr(topwin, exppath + 3, space); waddnstr(topwin, exppath + 3, space);
} }
the_end: the_end:
free(exppath); free(exppath);
if (COLS <= 1 || statelen >= COLS - 1) if (COLS <= 1 || statelen >= COLS - 1)