Skip to content

Commit

Permalink
Replace magic number by a descriptive macro (icon length)
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-arch committed Aug 10, 2024
1 parent 1ddc0ae commit c7d5d6b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ extern time_t curdir_mtime;
#define SIMPLE_STAT 1
#define FULL_STAT 2

/* Length to be added to a filename length if icons are enabled. */
#define ICON_LEN 3

/* Function macros */
#define atoi xatoi /* xatoi is just a secure atoi */

Expand Down
8 changes: 4 additions & 4 deletions src/listing.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ get_longest_filename(const filesn_t n, const size_t pad)
}

if (conf.long_view == 0 && conf.icons == 1 && conf.columned == 1)
longest.name_len += 3;
longest.name_len += ICON_LEN;

/* LONGEST.FC_LEN stores the amount of digits taken by the files counter of
* the longest file name, provided it is a directory.
Expand Down Expand Up @@ -1048,7 +1048,7 @@ print_long_mode(size_t *counter, int *reset_pager, const int pad,
int space_left = (int)term_cols - (prop_fields.len + have_xattr
+ maxes.files_counter + maxes.size + maxes.links + maxes.inode
+ maxes.id_user + (prop_fields.no_group == 0 ? maxes.id_group : 0)
+ maxes.blocks + (conf.icons == 1 ? 3 : 0));
+ maxes.blocks + (conf.icons == 1 ? ICON_LEN : 0));

if (space_left < conf.min_name_trim)
space_left = conf.min_name_trim;
Expand All @@ -1059,7 +1059,7 @@ print_long_mode(size_t *counter, int *reset_pager, const int pad,
if (longest.name_len < (size_t)space_left)
space_left = (int)longest.name_len;

maxes.name = space_left + (conf.icons == 1 ? 3 : 0);
maxes.name = space_left + (conf.icons == 1 ? ICON_LEN : 0);
pager_quit = pager_help = 0;

filesn_t i, k = files;
Expand Down Expand Up @@ -1608,7 +1608,7 @@ pad_filename(const int ind_char, const filesn_t i, const int pad,
int cur_len = 0;

#ifndef _NO_ICONS
cur_len = pad + 1 + (conf.icons == 1 ? 3 : 0) + (int)file_info[i].len
cur_len = pad + 1 + (conf.icons == 1 ? ICON_LEN : 0) + (int)file_info[i].len
+ (ind_char ? 1 : 0);
#else
cur_len = pad + 1 + (int)file_info[i].len + (ind_char ? 1 : 0);
Expand Down
2 changes: 1 addition & 1 deletion src/long_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ construct_and_print_filename(const struct fileinfo *props,
? (filesn_t)max_files : files;

size_t cur_len = (size_t)DIGINUM(n) + 1 + plen
+ (conf.icons == 1 ? 3 : 0);
+ (conf.icons == 1 ? ICON_LEN : 0);

int diff = 0;
char *name = wname ? wname : props->name;
Expand Down
4 changes: 2 additions & 2 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ get_glob_longest(struct search_t *matches, int *longest_eln,
}

if (conf.icons == 1)
*longest_match += 3;
*longest_match += ICON_LEN;

int longest_name = 0;
for (i = 0; matches[i].name; i++) {
Expand Down Expand Up @@ -754,7 +754,7 @@ load_entry_info(struct dirent **reg_dirlist, const int index)
list.name = name;
list.eln = reg_dirlist ? -1 : index + 1;
list.len = wc_xstrlen(name);
list.len += (!reg_dirlist && conf.icons == 1) ? 3 : 0;
list.len += (!reg_dirlist && conf.icons == 1) ? ICON_LEN : 0;
list.len += reg_dirlist ? 0 : (size_t)(DIGINUM(list.eln) + 1);

return list;
Expand Down

0 comments on commit c7d5d6b

Please sign in to comment.