Option to change look of cursors in parent dirs, rename an option. (#1106)

* Add `cursorparentfmt` option for cursors in parent dirs

The option defaults to the same value as `cursorfmt`, so the default look of `lf` is unchanged. However, I find it useful to make it different, since I seem to have so much trouble figuring out which of my cursors is the active one. :)

For example, here's what it looks like if one has `set cursorparentfmt "\033[7;90m"` in their `lfrc`:

https://user-images.githubusercontent.com/4123047/218299130-09ac411f-307a-489e-a4f0-4691710f8549.png

* Remove `cursorfmt` option to `cursoractivefmt`

This seems appropriate after introducing `cursorparentfmt`
This commit is contained in:
Ilya Grigoriev authored and GitHub committed 2023-02-25 20:38:41 +03:00
1 parent c0c85f206f
commit 6afefa5d09
7 files changed
+63 -32

No files matched your search

+2 -1
View File
@@ -113,7 +113,8 @@ var (
"autoquit", "autoquit",
"noautoquit", "noautoquit",
"autoquit!", "autoquit!",
"cursorfmt", "cursoractivefmt",
"cursorparentfmt",
"cursorpreviewfmt", "cursorpreviewfmt",
"dircache", "dircache",
"nodircache", "nodircache",
+9 -5
View File
@@ -114,7 +114,8 @@ The following options can be used to customize the behavior of lf:
anchorfind bool (default on) anchorfind bool (default on)
autoquit bool (default off) autoquit bool (default off)
cleaner string (default '') cleaner string (default '')
cursorfmt string (default "\033[7m") cursoractivefmt string (default "\033[7m")
cursorparentfmt string (default "\033[7m")
cursorpreviewfmt string (default "\033[4m") cursorpreviewfmt string (default "\033[4m")
dircache bool (default on) dircache bool (default on)
dircounts bool (default off) dircounts bool (default off)
@@ -608,15 +609,18 @@ This file is called if previewing is enabled, the previewer is set, and the prev
Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively. Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively.
Preview clearing is disabled when the value of this option is left empty. Preview clearing is disabled when the value of this option is left empty.
cursorfmt string (default "\033[7m") cursoractivefmt string (default "\033[7m")
cursorparentfmt string (default "\033[7m")
cursorpreviewfmt string (default "\033[4m") cursorpreviewfmt string (default "\033[4m")
Format strings for highlighting the cursor. Format strings for highlighting the cursor.
`cursorpreviewfmt` applies in panes that preview directories, and `cursorfmt` applies in all other panes. `cursoractivefmt` applies in the current directory pane,
`cursorparentfmt` applies in panes that show parents of the current directory,
and `cursorpreviewfmt` applies in panes that preview directories.
The default is to make the normal cursor inverted and the preview cursor underlined. The default is to make the active cursor and the parent directory cursor inverted. The preview cursor is underlined.
Some other possibilities to consider for the preview cursor: an empty string for no cursor, "\033[7;2m" for dimmed inverted text (visibility varies by terminal), "\033[7;90m" for inverted text with grey (aka "brightblack") background. Some other possibilities to consider for the preview or parent cursors: an empty string for no cursor, "\033[7;2m" for dimmed inverted text (visibility varies by terminal), "\033[7;90m" for inverted text with grey (aka "brightblack") background.
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. 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". For example, "\033[4m%s\033[0m" has the same effect as "\033[4m".
+14 -9
View File
@@ -117,7 +117,8 @@ The following options can be used to customize the behavior of lf:
anchorfind bool (default on) anchorfind bool (default on)
autoquit bool (default off) autoquit bool (default off)
cleaner string (default '') cleaner string (default '')
cursorfmt string (default "\033[7m") cursoractivefmt string (default "\033[7m")
cursorparentfmt string (default "\033[7m")
cursorpreviewfmt string (default "\033[4m") cursorpreviewfmt string (default "\033[4m")
dircache bool (default on) dircache bool (default on)
dircounts bool (default off) dircounts bool (default off)
@@ -634,18 +635,22 @@ file, (1) current file name, (2) width, (3) height, (4) horizontal position,
and (5) vertical position of preview pane respectively. Preview clearing is and (5) vertical position of preview pane respectively. Preview clearing is
disabled when the value of this option is left empty. disabled when the value of this option is left empty.
cursorfmt string (default "\033[7m") cursoractivefmt string (default "\033[7m")
cursorparentfmt string (default "\033[7m")
cursorpreviewfmt string (default "\033[4m") cursorpreviewfmt string (default "\033[4m")
Format strings for highlighting the cursor. 'cursorpreviewfmt' applies in panes Format strings for highlighting the cursor. 'cursoractivefmt' applies in the
that preview directories, and 'cursorfmt' applies in all other panes. current directory pane, 'cursorparentfmt' applies in panes that show parents
of the current directory, and 'cursorpreviewfmt' applies in panes that preview
directories.
The default is to make the normal cursor inverted and the preview cursor The default is to make the active cursor and the parent directory cursor
underlined. inverted. The preview cursor is underlined.
Some other possibilities to consider for the preview cursor: an empty string for Some other possibilities to consider for the preview or parent cursors: an empty
no cursor, "\033[7;2m" for dimmed inverted text (visibility varies by terminal), string for no cursor, "\033[7;2m" for dimmed inverted text (visibility varies
"\033[7;90m" for inverted text with grey (aka "brightblack") background. by terminal), "\033[7;90m" for inverted text with grey (aka "brightblack")
background.
If the format string contains the characters '%s', it is interpreted as a format 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 string for 'fmt.Sprintf'. Such a string should end with the terminal reset
+4 -2
View File
@@ -26,8 +26,10 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.autoquit = true gOpts.autoquit = true
case "noautoquit": case "noautoquit":
gOpts.autoquit = false gOpts.autoquit = false
case "cursorfmt": case "cursoractivefmt":
gOpts.cursorfmt = e.val gOpts.cursoractivefmt = e.val
case "cursorparentfmt":
gOpts.cursorparentfmt = e.val
case "cursorpreviewfmt": case "cursorpreviewfmt":
gOpts.cursorpreviewfmt = e.val gOpts.cursorpreviewfmt = e.val
case "autoquit!": case "autoquit!":
+7 -5
View File
@@ -133,7 +133,8 @@ The following options can be used to customize the behavior of lf:
anchorfind bool (default on) anchorfind bool (default on)
autoquit bool (default off) autoquit bool (default off)
cleaner string (default '') cleaner string (default '')
cursorfmt string (default "\e033[7m") cursoractivefmt string (default "\e033[7m")
cursorparentfmt string (default "\e033[7m")
cursorpreviewfmt string (default "\e033[4m") cursorpreviewfmt string (default "\e033[4m")
dircache bool (default on) dircache bool (default on)
dircounts bool (default off) dircounts bool (default off)
@@ -750,15 +751,16 @@ Automatically quit server when there are no clients left connected.
Set the path of a cleaner file. The file should be executable. This file is called if previewing is enabled, the previewer is set, and the previously selected file had its preview cache disabled. Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively. Preview clearing is disabled when the value of this option is left empty. Set the path of a cleaner file. The file should be executable. This file is called if previewing is enabled, the previewer is set, and the previously selected file had its preview cache disabled. Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively. Preview clearing is disabled when the value of this option is left empty.
.PP .PP
.EX .EX
cursorfmt string (default "\e033[7m") cursoractivefmt string (default "\e033[7m")
cursorparentfmt string (default "\e033[7m")
cursorpreviewfmt string (default "\e033[4m") cursorpreviewfmt string (default "\e033[4m")
.EE .EE
.PP .PP
Format strings for highlighting the cursor. `cursorpreviewfmt` applies in panes that preview directories, and `cursorfmt` applies in all other panes. Format strings for highlighting the cursor. `cursoractivefmt` applies in the current directory pane, `cursorparentfmt` applies in panes that show parents of the current directory, and `cursorpreviewfmt` applies in panes that preview directories.
.PP .PP
The default is to make the normal cursor inverted and the preview cursor underlined. The default is to make the active cursor and the parent directory cursor inverted. The preview cursor is underlined.
.PP .PP
Some other possibilities to consider for the preview cursor: an empty string for no cursor, "\e033[7;2m" for dimmed inverted text (visibility varies by terminal), "\e033[7;90m" for inverted text with grey (aka "brightblack") background. Some other possibilities to consider for the preview or parent cursors: an empty string for no cursor, "\e033[7;2m" for dimmed inverted text (visibility varies by terminal), "\e033[7;90m" for inverted text with grey (aka "brightblack") background.
.PP .PP
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, "\e033[4m%s\e033[0m" has the same effect as "\e033[4m". 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, "\e033[4m%s\e033[0m" has the same effect as "\e033[4m".
.PP .PP
+4 -2
View File
@@ -30,7 +30,8 @@ type sortType struct {
var gOpts struct { var gOpts struct {
anchorfind bool anchorfind bool
autoquit bool autoquit bool
cursorfmt string cursoractivefmt string
cursorparentfmt string
cursorpreviewfmt string cursorpreviewfmt string
dircache bool dircache bool
dircounts bool dircounts bool
@@ -91,7 +92,8 @@ func init() {
gOpts.dironly = false gOpts.dironly = false
gOpts.dirpreviews = false gOpts.dirpreviews = false
gOpts.drawbox = false gOpts.drawbox = false
gOpts.cursorfmt = "\033[7m" gOpts.cursoractivefmt = "\033[7m"
gOpts.cursorparentfmt = "\033[7m"
gOpts.cursorpreviewfmt = "\033[4m" gOpts.cursorpreviewfmt = "\033[4m"
gOpts.globsearch = false gOpts.globsearch = false
gOpts.icons = false gOpts.icons = false
+23 -8
View File
@@ -330,10 +330,18 @@ type dirContext struct {
tags map[string]string tags map[string]string
} }
type dirRole byte
const (
Active dirRole = iota
Parent
Preview
)
type dirStyle struct { type dirStyle struct {
colors styleMap colors styleMap
icons iconMap icons iconMap
previewing bool role dirRole
} }
// These colors are not currently customizeable // These colors are not currently customizeable
@@ -353,12 +361,12 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
win.print(screen, 2, 0, messageStyle, "permission denied") win.print(screen, 2, 0, messageStyle, "permission denied")
return return
} }
if (dir.loading && len(dir.files) == 0) || (dirStyle.previewing && dir.loading && gOpts.dirpreviews) { if (dir.loading && len(dir.files) == 0) || (dirStyle.role == Preview && dir.loading && gOpts.dirpreviews) {
win.print(screen, 2, 0, messageStyle, "loading...") win.print(screen, 2, 0, messageStyle, "loading...")
return return
} }
if dirStyle.previewing && gOpts.dirpreviews && len(gOpts.previewer) > 0 { if dirStyle.role == Preview && gOpts.dirpreviews && len(gOpts.previewer) > 0 {
// Print previewer result instead of default directory print operation. // Print previewer result instead of default directory print operation.
st := tcell.StyleDefault st := tcell.StyleDefault
for i, l := range dir.lines { for i, l := range dir.lines {
@@ -475,10 +483,13 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
ce := "" ce := ""
if i == dir.pos { if i == dir.pos {
if dirStyle.previewing { switch dirStyle.role {
case Active:
ce = gOpts.cursoractivefmt
case Parent:
ce = gOpts.cursorparentfmt
case Preview:
ce = gOpts.cursorpreviewfmt ce = gOpts.cursorpreviewfmt
} else {
ce = gOpts.cursorfmt
} }
} }
cursorescapefmt := optionToFmtstr(ce) cursorescapefmt := optionToFmtstr(ce)
@@ -920,9 +931,13 @@ func (ui *ui) draw(nav *nav) {
wins-- wins--
} }
for i := 0; i < wins; i++ { for i := 0; i < wins; i++ {
role := Parent
if i == wins-1 {
role = Active
}
if dir := ui.dirOfWin(nav, i); dir != nil { if dir := ui.dirOfWin(nav, i); dir != nil {
ui.wins[i].printDir(ui.screen, dir, &context, ui.wins[i].printDir(ui.screen, dir, &context,
&dirStyle{colors: ui.styles, icons: ui.icons, previewing: false}) &dirStyle{colors: ui.styles, icons: ui.icons, role: role})
} }
} }
@@ -958,7 +973,7 @@ func (ui *ui) draw(nav *nav) {
if curr.IsDir() { if curr.IsDir() {
preview.printDir(ui.screen, ui.dirPrev, &context, preview.printDir(ui.screen, ui.dirPrev, &context,
&dirStyle{colors: ui.styles, icons: ui.icons, previewing: true}) &dirStyle{colors: ui.styles, icons: ui.icons, role: Preview})
} else if curr.Mode().IsRegular() { } else if curr.Mode().IsRegular() {
preview.printReg(ui.screen, ui.regPrev) preview.printReg(ui.screen, ui.regPrev)
} }