sfm

simple file manager
git clone git://git.afify.dev/sfm
Log | Files | Refs | README | LICENSE

commit dc5b052073d2fac59596babc476e3d5cbd68e441
parent 66bc20ac4ddd176d159d9403503b27dd0ae08c49
Author: afify <hassan@afify.dev>
Date:   Sat, 31 Jul 2021 20:19:57 +0300

[feat] support colors for all files types

- use switch case to detect file type
- remove chech_execf()
- add all types in config.def.h

Diffstat:
Mconfig.def.h | 14++++++++++----
Msfm.c | 40++++++++++++++++++++++++++--------------
2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -4,14 +4,20 @@ #define CONFIG_H /* colors fg, bg */ -static const Cpair cdir = { 33, 0 }; -static const Cpair cerr = { 124, 0 }; -static const Cpair cexec = { 2, 0 }; +static const Cpair cdir = { 31, 0 }; static const Cpair cfile = { 243, 0 }; +static const Cpair clnk = { 96, 0 }; +static const Cpair cblk = { 95, 0 }; +static const Cpair cchr = { 94, 0 }; +static const Cpair cifo = { 93, 0 }; +static const Cpair csock = { 92, 0 }; +static const Cpair cexec = { 91, 0 }; +static const Cpair cother = { 90, 0 }; + static const Cpair cframe = { 233, 233 }; -static const Cpair cother = { 3, 0 }; static const Cpair cpanell = { 166, 233 }; static const Cpair cpanelr = { 5, 233 }; +static const Cpair cerr = { 124, 0 }; static const Cpair cprompt = { 33, 0 }; static const Cpair csearch = { 255, 0 }; static const Cpair cstatus = { 243, 0 }; diff --git a/sfm.c b/sfm.c @@ -120,7 +120,6 @@ static void clear_pane(Pane *); static void add_hi(Pane *, size_t); static void rm_hi(Pane *, size_t); static int check_dir(char *); -static mode_t chech_execf(mode_t); static int sort_name(const void *const, const void *const); static void get_dirp(char *); static char *get_ext(char *); @@ -402,14 +401,6 @@ check_dir(char *path) return 0; } -static mode_t -chech_execf(mode_t mode) -{ - if (S_ISREG(mode)) - return (((S_IXUSR | S_IXGRP | S_IXOTH) & mode)); - return 0; -} - static int sort_name(const void *const A, const void *const B) { @@ -645,13 +636,34 @@ get_dirsize(char *fullpath, off_t *fullsize) static void get_hicol(Cpair *col, mode_t mode) { - *col = cfile; - if (S_ISDIR(mode)) + switch (mode & S_IFMT) { + case S_IFREG: + *col = cfile; + if ((S_IXUSR | S_IXGRP | S_IXOTH) & mode) + *col = cexec; + break; + case S_IFDIR: *col = cdir; - else if (S_ISLNK(mode)) + break; + case S_IFLNK: + *col = clnk; + break; + case S_IFBLK: + *col = cblk; + break; + case S_IFCHR: + *col = cchr; + break; + case S_IFIFO: + *col = cifo; + break; + case S_IFSOCK: + *col = csock; + break; + default: *col = cother; - else if (chech_execf(mode) > 0) - *col = cexec; + break; + } } static void