in browser_refresh(), if a filename is too long, truncate and display an

ellipsis before it, as titlebar() does; also add various miscellaneous
minor fixes


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3719 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2006-07-02 18:29:49 +00:00
parent fef3c8679d
commit 85ffaeeefc
3 changed files with 34 additions and 21 deletions

View File

@ -26,6 +26,8 @@ CVS code -
truncated, and where file sizes could be too long. (DLR)
- For the ".." entry, display "(parent dir)" instead of "(dir)",
as Pico does. (DLR)
- If a filename is too long, truncate and display an ellipsis
before it, as titlebar() does. (DLR)
browser_select_filename()
- New function, used to select a specific filename in the list.
(DLR)

View File

@ -35,7 +35,7 @@ static char **filelist = NULL;
static size_t filelist_len = 0;
/* The number of files in the list. */
static int width = 0;
/* The number of columns to display the list in. */
/* The number of columns to display per filename. */
static int longest = 0;
/* The number of columns in the longest filename in the list. */
static size_t selected = 0;
@ -446,7 +446,7 @@ char *do_browse_from(const char *inpath)
/* Set filelist to the list of files contained in the directory path,
* set filelist_len to the number of files in that list, and set longest
* to the width in columns of the longest filename in that list, up to
* COLS (but at least 15). Assume path exists and is a directory. */
* COLS (but at least 16). Assume path exists and is a directory. */
void browser_init(const char *path, DIR *dir)
{
const struct dirent *nextdir;
@ -472,7 +472,7 @@ void browser_init(const char *path, DIR *dir)
filelist_len = i;
rewinddir(dir);
longest += 10;
longest += 11;
filelist = (char **)nmalloc(filelist_len * sizeof(char *));
@ -498,8 +498,8 @@ void browser_init(const char *path, DIR *dir)
if (longest > COLS)
longest = COLS;
if (longest < 15)
longest = 15;
if (longest < 16)
longest = 16;
}
/* Determine the shortcut key corresponding to the values of kbinput
@ -568,15 +568,24 @@ void browser_refresh(void)
for (; i < filelist_len && line < editwinrows; i++) {
struct stat st;
const char *filetail = tail(filelist[i]);
char *disp = display_string(filetail, 0, longest, FALSE);
size_t foo_col;
size_t filetaillen = strlenpt(filetail), foo_col;
bool dots = (filetaillen > longest);
/* Do we put an ellipsis before the filename? */
char *disp = display_string(filetail, dots ? filetaillen -
longest + 11 : 0, longest, FALSE);
/* Highlight the currently selected file or directory. */
if (i == selected)
wattron(edit, reverse_attr);
blank_line(edit, line, col, longest);
mvwaddstr(edit, line, col, disp);
/* If dots is TRUE, we will display something like
* "...ename". */
if (dots)
mvwaddstr(edit, line, col, "...");
mvwaddstr(edit, line, dots ? col + 3 : col, disp);
free(disp);
col += longest;
@ -621,7 +630,7 @@ void browser_refresh(void)
foo_col = col - strlenpt(foo);
mvwaddnstr(edit, line, foo_col, foo, actual_x(foo, longest -
foo_col) + 1);
foo_col));
if (i == selected)
wattroff(edit, reverse_attr);

View File

@ -1975,6 +1975,7 @@ void titlebar(const char *path)
assert(path != NULL || openfile->filename != NULL);
wattron(topwin, reverse_attr);
blank_titlebar();
/* space has to be at least 4: two spaces before the version message,
@ -2061,7 +2062,19 @@ void titlebar(const char *path)
exppath = display_string(path, start_col, space, FALSE);
}
if (!dots) {
/* If dots is TRUE, we will display something like "File:
* ...ename". */
if (dots) {
mvwaddnstr(topwin, 0, verlen - 1, prefix, actual_x(prefix,
prefixlen));
if (space <= -3 || newfie)
goto the_end;
waddch(topwin, ' ');
waddnstr(topwin, "...", space + 3);
if (space <= 0)
goto the_end;
waddstr(topwin, exppath);
} else {
size_t exppathlen = newfie ? 0 : strlenpt(exppath);
/* The length of the expanded filename. */
@ -2072,17 +2085,6 @@ void titlebar(const char *path)
waddch(topwin, ' ');
waddstr(topwin, exppath);
}
} else {
/* We will say something like "File: ...ename". */
mvwaddnstr(topwin, 0, verlen - 1, prefix, actual_x(prefix,
prefixlen));
if (space <= -3 || newfie)
goto the_end;
waddch(topwin, ' ');
waddnstr(topwin, "...", space + 3);
if (space <= 0)
goto the_end;
waddstr(topwin, exppath);
}
the_end: