From 11caeddb355be398e28f0bd1bff237669c641775 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sun, 2 Apr 2023 00:05:44 +1100 Subject: [PATCH] Support custom line number colors (#1177) * Support custom line number colors * Move eval case --- complete.go | 1 + doc.go | 5 +++++ docstring.go | 5 +++++ eval.go | 2 ++ lf.1 | 7 +++++++ opts.go | 2 ++ ui.go | 3 +-- 7 files changed, 23 insertions(+), 2 deletions(-) diff --git a/complete.go b/complete.go index 1dcd7736..70f70b72 100644 --- a/complete.go +++ b/complete.go @@ -194,6 +194,7 @@ var ( "history", "ifs", "info", + "numberfmt", "previewer", "cleaner", "promptfmt", diff --git a/doc.go b/doc.go index 155908f6..f5f80563 100644 --- a/doc.go +++ b/doc.go @@ -143,6 +143,7 @@ The following options can be used to customize the behavior of lf: infotimefmtold string (default 'Jan _2 2006') mouse bool (default false) number bool (default false) + numberfmt string (default "\033[33m") period int (default 0) preview bool (default true) previewer string (default '') @@ -761,6 +762,10 @@ Send mouse events as input. Show the position number for directory items at the left side of pane. When 'relativenumber' option is enabled, only the current line shows the absolute position and relative positions are shown for the rest. + numberfmt string (default "\033[33m") + +Format string of the position number for each line. + period int (default 0) Set the interval in seconds for periodic checks of directory updates. diff --git a/docstring.go b/docstring.go index 979f85d6..fde45403 100644 --- a/docstring.go +++ b/docstring.go @@ -146,6 +146,7 @@ The following options can be used to customize the behavior of lf: infotimefmtold string (default 'Jan _2 2006') mouse bool (default false) number bool (default false) + numberfmt string (default "\033[33m") period int (default 0) preview bool (default true) previewer string (default '') @@ -807,6 +808,10 @@ Show the position number for directory items at the left side of pane. When 'relativenumber' option is enabled, only the current line shows the absolute position and relative positions are shown for the rest. + numberfmt string (default "\033[33m") + +Format string of the position number for each line. + period int (default 0) Set the interval in seconds for periodic checks of directory updates. This works diff --git a/eval.go b/eval.go index bcc1807e..e628218a 100644 --- a/eval.go +++ b/eval.go @@ -543,6 +543,8 @@ func (e *setExpr) eval(app *app, args []string) { return } gOpts.number = !gOpts.number + case "numberfmt": + gOpts.numberfmt = e.val case "period": n, err := strconv.Atoi(e.val) if err != nil { diff --git a/lf.1 b/lf.1 index 30414c4f..3f5e5cbd 100644 --- a/lf.1 +++ b/lf.1 @@ -162,6 +162,7 @@ The following options can be used to customize the behavior of lf: infotimefmtold string (default 'Jan _2 2006') mouse bool (default false) number bool (default false) + numberfmt string (default "\e033[33m") period int (default 0) preview bool (default true) previewer string (default '') @@ -928,6 +929,12 @@ Send mouse events as input. .PP Show the position number for directory items at the left side of pane. When 'relativenumber' option is enabled, only the current line shows the absolute position and relative positions are shown for the rest. .PP +.EX + numberfmt string (default "\e033[33m") +.EE +.PP +Format string of the position number for each line. +.PP .EX period int (default 0) .EE diff --git a/opts.go b/opts.go index f8f3b940..56f91f5a 100644 --- a/opts.go +++ b/opts.go @@ -81,6 +81,7 @@ var gOpts struct { user map[string]string sortType sortType tempmarks string + numberfmt string tagfmt string } @@ -134,6 +135,7 @@ func init() { gOpts.shellopts = nil gOpts.sortType = sortType{naturalSort, dirfirstSort} gOpts.tempmarks = "'" + gOpts.numberfmt = "\033[33m" gOpts.tagfmt = "\033[31m" gOpts.keys = make(map[string]expr) diff --git a/ui.go b/ui.go index 3665fc6f..ab07842d 100644 --- a/ui.go +++ b/ui.go @@ -347,7 +347,6 @@ type dirStyle struct { } // These colors are not currently customizeable -const LineNumberColor = tcell.ColorOlive const SelectionColor = tcell.ColorPurple const YankColor = tcell.ColorOlive const CutColor = tcell.ColorMaroon @@ -427,7 +426,7 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir } } - win.print(screen, 0, i, tcell.StyleDefault.Foreground(LineNumberColor), ln) + win.print(screen, 0, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.numberfmt), ln)) } path := filepath.Join(dir.path, f.Name())