Commit 99c87ccb authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

in browser_refresh(), fix problems where translated versions of "(dir)"

could be truncated, and where file sizes could be too long


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3694 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 46 additions and 30 deletions
+46 -30
...@@ -15,6 +15,8 @@ CVS code - ...@@ -15,6 +15,8 @@ CVS code -
- Remove unneeded call to blank_edit(). (DLR) - Remove unneeded call to blank_edit(). (DLR)
browser_refresh() browser_refresh()
- Simplify. (DLR) - Simplify. (DLR)
- Fix problems where translated versions of "(dir)" could be
truncated, and where file sizes could be too long. (DLR)
- doc/syntax/c.nanorc: - doc/syntax/c.nanorc:
- Since .i and .ii are preprocessed C and C++ output, colorize - Since .i and .ii are preprocessed C and C++ output, colorize
them here. (Mike Frysinger) them here. (Mike Frysinger)
......
...@@ -522,11 +522,13 @@ void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key) ...@@ -522,11 +522,13 @@ void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key)
* files. */ * files. */
void browser_refresh(void) void browser_refresh(void)
{ {
struct stat st; static int uimax_digits = -1;
size_t i; size_t i;
int col = 0, line = 0, filecols = 0; int col = 0, line = 0, filecols = 0;
size_t foo_len = mb_cur_max() * 7; char *foo;
char *foo = charalloc(foo_len + 1);
if (uimax_digits == -1)
uimax_digits = digits(UINT_MAX);
blank_edit(); blank_edit();
...@@ -536,6 +538,7 @@ void browser_refresh(void) ...@@ -536,6 +538,7 @@ void browser_refresh(void)
editwinrows) : 0; editwinrows) : 0;
for (; i < filelist_len && line < editwinrows; i++) { for (; i < filelist_len && line < editwinrows; i++) {
struct stat st;
char *disp = display_string(tail(filelist[i]), 0, longest, char *disp = display_string(tail(filelist[i]), 0, longest,
FALSE); FALSE);
...@@ -550,36 +553,49 @@ void browser_refresh(void) ...@@ -550,36 +553,49 @@ void browser_refresh(void)
col += longest; col += longest;
filecols++; filecols++;
/* Show file info also. We don't want to report file sizes for /* Show information about the file. We don't want to report
* links, so we use lstat(). Also, stat() and lstat() return an * file sizes for links, so we use lstat(). */
* error if, for example, the file is deleted while the file
* browser is open. In that case, we report "--" as the file
* info. */
if (lstat(filelist[i], &st) == -1 || S_ISLNK(st.st_mode)) { if (lstat(filelist[i], &st) == -1 || S_ISLNK(st.st_mode)) {
/* Aha! It's a symlink! Now, is it a dir? If so, mark it /* If the file doesn't exist (i.e, it's been deleted while
* as such. */ * the file browser is open), or it's a symlink that doesn't
if (stat(filelist[i], &st) == 0 && S_ISDIR(st.st_mode)) { * point to a directory, display "--". */
strncpy(foo, _("(dir)"), foo_len); if (stat(filelist[i], &st) == -1 || !S_ISDIR(st.st_mode))
foo[foo_len] = '\0'; foo = mallocstrcpy(NULL, "--");
} else /* If the file is a symlink that points to a directory,
strcpy(foo, "--"); * display it as a directory. */
} else if (S_ISDIR(st.st_mode)) { else
strncpy(foo, _("(dir)"), foo_len); foo = mallocstrcpy(NULL, _("(dir)"));
foo[foo_len] = '\0'; } else if (S_ISDIR(st.st_mode))
} else if (st.st_size < (1 << 10)) /* less than 1 k. */ /* If the file is a directory, display it as such. */
sprintf(foo, "%4u B", (unsigned int)st.st_size); foo = mallocstrcpy(NULL, _("(dir)"));
else if (st.st_size < (1 << 20)) /* less than 1 meg. */ else {
sprintf(foo, "%4u KB", (unsigned int)(st.st_size >> 10)); foo = charalloc(uimax_digits + 4);
else if (st.st_size < (1 << 30)) /* less than 1 gig. */
sprintf(foo, "%4u MB", (unsigned int)(st.st_size >> 20)); /* Bytes. */
else if (st.st_size < (1 << 10))
sprintf(foo, "%4u GB", (unsigned int)(st.st_size >> 30)); sprintf(foo, "%4u B", (unsigned int)st.st_size);
/* Kilobytes. */
mvwaddnstr(edit, line, col - strlen(foo), foo, foo_len); else if (st.st_size < (1 << 20))
sprintf(foo, "%4u KB",
(unsigned int)(st.st_size >> 10));
/* Megabytes. */
else if (st.st_size < (1 << 30))
sprintf(foo, "%4u MB",
(unsigned int)(st.st_size >> 20));
/* Gigabytes. */
else
sprintf(foo, "%4u GB",
(unsigned int)(st.st_size >> 30));
}
mvwaddnstr(edit, line, col - strlenpt(foo), foo,
actual_x(foo, 7));
if (i == selected) if (i == selected)
wattroff(edit, reverse_attr); wattroff(edit, reverse_attr);
free(foo);
/* Add some space between the columns. */ /* Add some space between the columns. */
col += 2; col += 2;
...@@ -598,8 +614,6 @@ void browser_refresh(void) ...@@ -598,8 +614,6 @@ void browser_refresh(void)
wmove(edit, line, col); wmove(edit, line, col);
} }
free(foo);
wnoutrefresh(edit); wnoutrefresh(edit);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment