Allow customization for cut/copy/select colors (#1540)

* Allow customization for cut/copy/select colors

* Add documentation
This commit is contained in:
Joe Lim authored and GitHub committed 2024-01-01 06:35:54 +11:00
1 parent 488294588e
commit f8399eb6e0
5 files changed
+39 -11

No files matched your search

+3
View File
@@ -117,9 +117,11 @@ var (
"noautoquit",
"autoquit!",
"borderfmt",
"copyfmt",
"cursoractivefmt",
"cursorparentfmt",
"cursorpreviewfmt",
"cutfmt",
"hidecursorinactive",
"nohidecursorinactive",
"hidecursorinactive!",
@@ -181,6 +183,7 @@ var (
"ruler",
"rulerfmt",
"preserve",
"selectfmt",
"sixel",
"nosixel",
"sixel!",
+15
View File
@@ -140,9 +140,11 @@ The following options can be used to customize the behavior of lf:
autoquit bool (default false)
borderfmt string (default "\033[0m")
cleaner string (default '')
copyfmt string (default "\033[7;33m")
cursoractivefmt string (default "\033[7m")
cursorparentfmt string (default "\033[7m")
cursorpreviewfmt string (default "\033[4m")
cutfmt string (default "\033[7;31m")
dircache bool (default true)
dircounts bool (default false)
dirfirst bool (default true)
@@ -181,6 +183,7 @@ The following options can be used to customize the behavior of lf:
ruler []string (default 'acc:progress:selection:filter:ind')
rulerfmt string (default " %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;34m %f \033[0m| %i/%t")
scrolloff int (default 0)
selectfmt string (default "\033[7;35m")
selmode string (default 'all')
shell string (default 'sh' for Unix and 'cmd' for Windows)
shellflag string (default '-c' for Unix and '/c' for Windows)
@@ -674,6 +677,10 @@ This file is called if previewing is enabled, the previewer is set, and the prev
The following arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, (5) vertical position of preview pane and (6) next file name to be previewed respectively.
Preview cleaning is disabled when the value of this option is left empty.
## copyfmt (string) (default `\033[7;33m`)
Format string of the indicator for files to be copied.
## cursoractivefmt (string) (default `\033[7m`), cursorparentfmt string (default `\033[7m`), cursorpreviewfmt string (default `\033[4m`)
Format strings for highlighting the cursor.
@@ -688,6 +695,10 @@ Some other possibilities to consider for the preview or parent cursors: an empty
If the format string contains the characters `%s`, it is interpreted as a format string for `fmt.Sprintf`. Such a string should end with the terminal reset sequence.
For example, `\033[4m%s\033[0m` has the same effect as `\033[4m`.
## cutfmt (string) (default `\033[7;31m`)
Format string of the indicator for files to be cut.
## dircache (bool) (default true)
Cache directory contents.
@@ -894,6 +905,10 @@ Additional expansions are provided for environment variables exported by lf, in
Expansions are also provided for user-defined options, in the form `%{lf_user_<name>}` (e.g. `%{lf_user_foo}`).
The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
## selectfmt (string) (default `\033[7;35m`)
Format string of the indicator for files that are selected.
## selmode (string) (default `all`)
Selection mode for commands.
+6
View File
@@ -62,12 +62,16 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.borderfmt = e.val
case "cleaner":
gOpts.cleaner = replaceTilde(e.val)
case "copyfmt":
gOpts.copyfmt = e.val
case "cursoractivefmt":
gOpts.cursoractivefmt = e.val
case "cursorparentfmt":
gOpts.cursorparentfmt = e.val
case "cursorpreviewfmt":
gOpts.cursorpreviewfmt = e.val
case "cutfmt":
gOpts.cutfmt = e.val
case "hidecursorinactive":
if e.val == "" || e.val == "true" {
gOpts.hidecursorinactive = true
@@ -740,6 +744,8 @@ func (e *setExpr) eval(app *app, args []string) {
return
}
gOpts.scrolloff = n
case "selectfmt":
gOpts.selectfmt = e.val
case "selmode":
switch e.val {
case "all", "dir":
+6
View File
@@ -46,9 +46,11 @@ var gOpts struct {
anchorfind bool
autoquit bool
borderfmt string
copyfmt string
cursoractivefmt string
cursorparentfmt string
cursorpreviewfmt string
cutfmt string
hidecursorinactive bool
dircache bool
dircounts bool
@@ -65,6 +67,7 @@ var gOpts struct {
mouse bool
number bool
preview bool
selectfmt string
sixel bool
relativenumber bool
smartcase bool
@@ -204,9 +207,11 @@ func init() {
gOpts.drawbox = false
gOpts.dupfilefmt = "%f.~%n~"
gOpts.borderfmt = "\033[0m"
gOpts.copyfmt = "\033[7;33m"
gOpts.cursoractivefmt = "\033[7m"
gOpts.cursorparentfmt = "\033[7m"
gOpts.cursorpreviewfmt = "\033[4m"
gOpts.cutfmt = "\033[7;31m"
gOpts.hidecursorinactive = false
gOpts.globsearch = false
gOpts.icons = false
@@ -217,6 +222,7 @@ func init() {
gOpts.mouse = false
gOpts.number = false
gOpts.preview = true
gOpts.selectfmt = "\033[7;35m"
gOpts.sixel = false
gOpts.relativenumber = false
gOpts.smartcase = true
+9 -11
View File
@@ -348,11 +348,6 @@ type dirStyle struct {
role dirRole
}
// These colors are not currently customizeable
const SelectionColor = tcell.ColorPurple
const YankColor = tcell.ColorOlive
const CutColor = tcell.ColorMaroon
func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle, previewLoading bool) {
if win.w < 5 || dir == nil {
return
@@ -434,12 +429,12 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
path := filepath.Join(dir.path, f.Name())
if _, ok := context.selections[path]; ok {
win.print(ui.screen, lnwidth, i, st.Background(SelectionColor), " ")
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.selectfmt), " ")
} else if cp, ok := context.saves[path]; ok {
if cp {
win.print(ui.screen, lnwidth, i, st.Background(YankColor), " ")
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.copyfmt), " ")
} else {
win.print(ui.screen, lnwidth, i, st.Background(CutColor), " ")
win.print(ui.screen, lnwidth, i, parseEscapeSequence(gOpts.cutfmt), " ")
}
}
@@ -861,16 +856,19 @@ func (ui *ui) drawRuler(nav *nav) {
}
}
if copy > 0 {
selection = append(selection, fmt.Sprintf("\033[33;7m %d \033[0m", copy))
copyStr := fmt.Sprintf(optionToFmtstr(gOpts.copyfmt), fmt.Sprintf(" %d ", copy))
selection = append(selection, copyStr)
}
if move > 0 {
selection = append(selection, fmt.Sprintf("\033[31;7m %d \033[0m", move))
moveStr := fmt.Sprintf(optionToFmtstr(gOpts.cutfmt), fmt.Sprintf(" %d ", move))
selection = append(selection, moveStr)
}
}
currSelections := nav.currSelections()
if len(currSelections) > 0 {
selection = append(selection, fmt.Sprintf("\033[35;7m %d \033[0m", len(currSelections)))
selectStr := fmt.Sprintf(optionToFmtstr(gOpts.selectfmt), fmt.Sprintf(" %d ", len(currSelections)))
selection = append(selection, selectStr)
}
progress := []string{}