tweaks: remove an unneeded cursor movement, and rename a variable
There is no need to place the cursor up front, as the drawing of each name includes the coordinates where the name must be drawn. Also, trim two comments and reshuffle a free().master
parent
29d493a986
commit
a2fdf6c486
|
@ -451,8 +451,7 @@ void read_the_list(const char *path, DIR *dir)
|
||||||
width = (COLS + 2) / (longest + 2);
|
width = (COLS + 2) / (longest + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set width to the number of files that we can display per screen row,
|
/* Display at most a screenful of filenames from the gleaned filelist. */
|
||||||
* if necessary, and display the list of files. */
|
|
||||||
void browser_refresh(void)
|
void browser_refresh(void)
|
||||||
{
|
{
|
||||||
int row = 0, col = 0;
|
int row = 0, col = 0;
|
||||||
|
@ -465,11 +464,8 @@ void browser_refresh(void)
|
||||||
titlebar(present_path);
|
titlebar(present_path);
|
||||||
blank_edit();
|
blank_edit();
|
||||||
|
|
||||||
wmove(edit, 0, 0);
|
|
||||||
|
|
||||||
for (size_t index = selected - selected % (editwinrows * width);
|
for (size_t index = selected - selected % (editwinrows * width);
|
||||||
index < filelist_len && row < editwinrows; index++) {
|
index < filelist_len && row < editwinrows; index++) {
|
||||||
struct stat st;
|
|
||||||
const char *thename = tail(filelist[index]);
|
const char *thename = tail(filelist[index]);
|
||||||
/* The filename we display, minus the path. */
|
/* The filename we display, minus the path. */
|
||||||
size_t namelen = breadth(thename);
|
size_t namelen = breadth(thename);
|
||||||
|
@ -486,6 +482,7 @@ void browser_refresh(void)
|
||||||
namelen + infomaxlen + 4 - longest : 0, longest, FALSE, FALSE);
|
namelen + infomaxlen + 4 - longest : 0, longest, FALSE, FALSE);
|
||||||
/* The filename (or a fragment of it) in displayable format.
|
/* The filename (or a fragment of it) in displayable format.
|
||||||
* When a fragment, account for dots plus one space padding. */
|
* When a fragment, account for dots plus one space padding. */
|
||||||
|
struct stat state;
|
||||||
|
|
||||||
/* If this is the selected item, draw its highlighted bar upfront, and
|
/* If this is the selected item, draw its highlighted bar upfront, and
|
||||||
* remember its location to be able to place the cursor on it. */
|
* remember its location to be able to place the cursor on it. */
|
||||||
|
@ -501,20 +498,18 @@ void browser_refresh(void)
|
||||||
mvwaddstr(edit, row, col, "...");
|
mvwaddstr(edit, row, col, "...");
|
||||||
mvwaddstr(edit, row, dots ? col + 3 : col, disp);
|
mvwaddstr(edit, row, dots ? col + 3 : col, disp);
|
||||||
|
|
||||||
free(disp);
|
|
||||||
|
|
||||||
col += longest;
|
col += longest;
|
||||||
|
|
||||||
/* Show information about the file: "--" for symlinks (except when
|
/* Show information about the file: "--" for symlinks (except when
|
||||||
* they point to a directory) and for files that have disappeared,
|
* they point to a directory) and for files that have disappeared,
|
||||||
* "(dir)" for directories, and the file size for normal files. */
|
* "(dir)" for directories, and the file size for normal files. */
|
||||||
if (lstat(filelist[index], &st) == -1 || S_ISLNK(st.st_mode)) {
|
if (lstat(filelist[index], &state) == -1 || S_ISLNK(state.st_mode)) {
|
||||||
if (stat(filelist[index], &st) == -1 || !S_ISDIR(st.st_mode))
|
if (stat(filelist[index], &state) == -1 || !S_ISDIR(state.st_mode))
|
||||||
info = copy_of("--");
|
info = copy_of("--");
|
||||||
else
|
else
|
||||||
/* TRANSLATORS: Try to keep this at most 7 characters. */
|
/* TRANSLATORS: Try to keep this at most 7 characters. */
|
||||||
info = copy_of(_("(dir)"));
|
info = copy_of(_("(dir)"));
|
||||||
} else if (S_ISDIR(st.st_mode)) {
|
} else if (S_ISDIR(state.st_mode)) {
|
||||||
if (strcmp(thename, "..") == 0) {
|
if (strcmp(thename, "..") == 0) {
|
||||||
/* TRANSLATORS: Try to keep this at most 12 characters. */
|
/* TRANSLATORS: Try to keep this at most 12 characters. */
|
||||||
info = copy_of(_("(parent dir)"));
|
info = copy_of(_("(parent dir)"));
|
||||||
|
@ -522,18 +517,18 @@ void browser_refresh(void)
|
||||||
} else
|
} else
|
||||||
info = copy_of(_("(dir)"));
|
info = copy_of(_("(dir)"));
|
||||||
} else {
|
} else {
|
||||||
off_t result = st.st_size;
|
off_t result = state.st_size;
|
||||||
char modifier;
|
char modifier;
|
||||||
|
|
||||||
info = charalloc(infomaxlen + 1);
|
info = charalloc(infomaxlen + 1);
|
||||||
|
|
||||||
/* Massage the file size into a human-readable form. */
|
/* Massage the file size into a human-readable form. */
|
||||||
if (st.st_size < (1 << 10))
|
if (state.st_size < (1 << 10))
|
||||||
modifier = ' '; /* bytes */
|
modifier = ' '; /* bytes */
|
||||||
else if (st.st_size < (1 << 20)) {
|
else if (state.st_size < (1 << 20)) {
|
||||||
result >>= 10;
|
result >>= 10;
|
||||||
modifier = 'K'; /* kilobytes */
|
modifier = 'K'; /* kilobytes */
|
||||||
} else if (st.st_size < (1 << 30)) {
|
} else if (state.st_size < (1 << 30)) {
|
||||||
result >>= 20;
|
result >>= 20;
|
||||||
modifier = 'M'; /* megabytes */
|
modifier = 'M'; /* megabytes */
|
||||||
} else {
|
} else {
|
||||||
|
@ -563,13 +558,13 @@ void browser_refresh(void)
|
||||||
if (index == selected)
|
if (index == selected)
|
||||||
wattroff(edit, interface_color_pair[SELECTED_TEXT]);
|
wattroff(edit, interface_color_pair[SELECTED_TEXT]);
|
||||||
|
|
||||||
|
free(disp);
|
||||||
free(info);
|
free(info);
|
||||||
|
|
||||||
/* Add some space between the columns. */
|
/* Add some space between the columns. */
|
||||||
col += 2;
|
col += 2;
|
||||||
|
|
||||||
/* If the next entry isn't going to fit on the current row,
|
/* If the next entry will not fit on this row, move to next row. */
|
||||||
* move to the next row. */
|
|
||||||
if (col > COLS - longest) {
|
if (col > COLS - longest) {
|
||||||
row++;
|
row++;
|
||||||
col = 0;
|
col = 0;
|
||||||
|
|
Loading…
Reference in New Issue