Skip to content

Commit

Permalink
Allow customization for cut/copy/select colors (#1540)
Browse files Browse the repository at this point in the history
* Allow customization for cut/copy/select colors

* Add documentation
  • Loading branch information
joelim-work authored Dec 31, 2023
1 parent 4882945 commit f8399eb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
3 changes: 3 additions & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ var (
"noautoquit",
"autoquit!",
"borderfmt",
"copyfmt",
"cursoractivefmt",
"cursorparentfmt",
"cursorpreviewfmt",
"cutfmt",
"hidecursorinactive",
"nohidecursorinactive",
"hidecursorinactive!",
Expand Down Expand Up @@ -181,6 +183,7 @@ var (
"ruler",
"rulerfmt",
"preserve",
"selectfmt",
"sixel",
"nosixel",
"sixel!",
Expand Down
15 changes: 15 additions & 0 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down
6 changes: 6 additions & 0 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,6 +67,7 @@ var gOpts struct {
mouse bool
number bool
preview bool
selectfmt string
sixel bool
relativenumber bool
smartcase bool
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 9 additions & 11 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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), " ")
}
}

Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit f8399eb

Please sign in to comment.