diff --git a/CHANGELOG.md b/CHANGELOG.md index 98c7e911a..3942b6470 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - A new option `borderstyle` is added to control whether `drawbox` draws an outline, separators, or both (#2445). This also replaces the existing `roundbox` option. - The `loading...` message delay of 100 milliseconds for file previews is now applied to directories as well (#2410). - `lf` will now automatically change to the parent directory if the current directory no longer exists and the `watch` option is enabled (#2424). +- A new option `hiddenfmt` is added to colour hidden files and directories (#2492). ### Fixed diff --git a/colors.go b/colors.go index cb4cf3bc9..3e22a626c 100644 --- a/colors.go +++ b/colors.go @@ -221,6 +221,7 @@ func (sm styleMap) parseBSD(env string) { } } + func (sm styleMap) get(f *file) tcell.Style { if val, ok := sm.styles[f.path]; ok { return val diff --git a/doc.md b/doc.md index 72f30b052..489fbfcb2 100644 --- a/doc.md +++ b/doc.md @@ -274,6 +274,7 @@ The following options can be used to customize the behavior of lf: filtermethod string (default 'text') findlen int (default 1) hidden bool (default false) + hiddenfmt string (default '') hiddenfiles []string (default '.*' for Unix and '' for Windows) history bool (default true) icons bool (default false) @@ -955,6 +956,14 @@ Show hidden files. On Unix systems, hidden files are determined by the value of `hiddenfiles`. On Windows, files with hidden attributes are also considered hidden files. +## hiddenfmt (string) (default ``) + +Format string for colouring hidden files and directories. +When set to a non-empty value, it overrides the normal colour for entries considered hidden (see `hiddenfiles`). +Hidden detection on Windows also respects the filesystem hidden attribute. +Leave empty to disable and fall back to the regular colour lookup. +Example: `set hiddenfmt "\033[3;38;2;146;131;116m"`. + ## hiddenfiles ([]string) (default `.*` for Unix and `` for Windows) List of hidden file glob patterns. diff --git a/doc.txt b/doc.txt index 48fc1b484..43df165ab 100644 --- a/doc.txt +++ b/doc.txt @@ -1031,6 +1031,15 @@ Show hidden files. On Unix systems, hidden files are determined by the value of hiddenfiles. On Windows, files with hidden attributes are also considered hidden files. +hiddendirfmt (string) (default ``), hiddenfilefmt (string) (default ``) + +Format strings for colouring hidden directories and files. When set to +a non-empty value, they override the normal di and fi colours for +entries considered hidden (see hiddenfiles). Hidden detection on +Windows also respects the filesystem hidden attribute. Leave empty to +disable and fall back to the regular colour lookup. Example: set +hiddendirfmt "\033[3;38;2;146;131;116m". + hiddenfiles ([]string) (default .* for Unix and `` for Windows) List of hidden file glob patterns. Patterns can be given as relative or diff --git a/eval.go b/eval.go index 51b0e84b5..a3a7b8346 100644 --- a/eval.go +++ b/eval.go @@ -250,6 +250,8 @@ func (e *setExpr) eval(app *app, _ []string) { return } gOpts.findlen = n + case "hiddenfmt": + gOpts.hiddenfmt = e.val case "hiddenfiles": toks := strings.Split(e.val, ":") for _, s := range toks { diff --git a/lf.1 b/lf.1 index 9e84bb9d9..82baec77f 100644 --- a/lf.1 +++ b/lf.1 @@ -298,6 +298,8 @@ filesep string (default \(dq\(rsn\(dq) filtermethod string (default \(aqtext\(aq) findlen int (default 1) hidden bool (default false) +hiddendirfmt string (default \(aq\(aq) +hiddenfilefmt string (default \(aq\(aq) hiddenfiles []string (default \(aq.*\(aq for Unix and \(aq\(aq for Windows) history bool (default true) icons bool (default false) @@ -922,6 +924,15 @@ On Unix systems, hidden files are determined by the value of \f[CR]hiddenfiles\f[R]. On Windows, files with hidden attributes are also considered hidden files. +.SS hiddendirfmt (string) (default \(ga\(ga), hiddenfilefmt (string) (default \(ga\(ga) +Format strings for colouring hidden directories and files. +When set to a non-empty value, they override the normal \f[CR]di\f[R] +and \f[CR]fi\f[R] colours for entries considered hidden (see +\f[CR]hiddenfiles\f[R]). +Hidden detection on Windows also respects the filesystem hidden +attribute. +Leave empty to disable and fall back to the regular colour lookup. +Example: \f[CR]set hiddendirfmt \(dq\(rs033[3;38;2;146;131;116m\(dq\f[R]. .SS hiddenfiles ([]string) (default \f[CR].*\f[R] for Unix and \(ga\(ga for Windows) List of hidden file glob patterns. Patterns can be given as relative or absolute paths. diff --git a/opts.go b/opts.go index 3140253b3..70c1e0e8a 100644 --- a/opts.go +++ b/opts.go @@ -102,6 +102,7 @@ var gOpts struct { filtermethod searchMethod findlen int hidden bool + hiddenfmt string hiddenfiles []string history bool icons bool @@ -245,6 +246,7 @@ func init() { gOpts.filtermethod = textSearch gOpts.findlen = 1 gOpts.hidden = false + gOpts.hiddenfmt = "" gOpts.hiddenfiles = gDefaultHiddenFiles gOpts.history = true gOpts.icons = false diff --git a/ui.go b/ui.go index 770d50017..3c5c096c2 100644 --- a/ui.go +++ b/ui.go @@ -313,7 +313,12 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty visualSelections := dir.visualSelections() for i, f := range dir.files[beg:end] { - st := dirStyle.colors.get(f) + var st tcell.Style + if gOpts.hiddenfmt != "" && isHidden(f, dir.path, gOpts.hiddenfiles) { + st = parseEscapeSequence(gOpts.hiddenfmt) + } else { + st = dirStyle.colors.get(f) + } if lnwidth > 0 { var ln string