Skip to content

Commit

Permalink
Add cursorparentfmt option to change look of cursors in parent dirs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ilyagr committed Feb 12, 2023
1 parent 530ab2c commit 52f1593
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 23 deletions.
1 change: 1 addition & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var (
"noautoquit",
"autoquit!",
"cursorfmt",
"cursorparentfmt",
"cursorpreviewfmt",
"dircache",
"nodircache",
Expand Down
10 changes: 7 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ The following options can be used to customize the behavior of lf:
autoquit bool (default off)
cleaner string (default '')
cursorfmt string (default "\033[7m")
cursorparentfmt string (default "\033[7m")
cursorpreviewfmt string (default "\033[4m")
dircache bool (default on)
dircounts bool (default off)
Expand Down Expand Up @@ -609,14 +610,17 @@ Five arguments are passed to the file, (1) current file name, (2) width, (3) hei
Preview clearing is disabled when the value of this option is left empty.
cursorfmt string (default "\033[7m")
cursorparentfmt string (default "\033[7m")
cursorpreviewfmt string (default "\033[4m")
Format strings for highlighting the cursor.
`cursorpreviewfmt` applies in panes that preview directories, and `cursorfmt` applies in all other panes.
`cursorfmt` 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.
For example, "\033[4m%s\033[0m" has the same effect as "\033[4m".
Expand Down
19 changes: 12 additions & 7 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.autoquit = false
case "cursorfmt":
gOpts.cursorfmt = e.val
case "cursorparentfmt":
gOpts.cursorparentfmt = e.val
case "cursorpreviewfmt":
gOpts.cursorpreviewfmt = e.val
case "autoquit!":
Expand Down
8 changes: 5 additions & 3 deletions lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ The following options can be used to customize the behavior of lf:
autoquit bool (default off)
cleaner string (default '')
cursorfmt string (default "\e033[7m")
cursorparentfmt string (default "\e033[7m")
cursorpreviewfmt string (default "\e033[4m")
dircache bool (default on)
dircounts bool (default off)
Expand Down Expand Up @@ -751,14 +752,15 @@ Set the path of a cleaner file. The file should be executable. This file is call
.PP
.EX
cursorfmt string (default "\e033[7m")
cursorparentfmt string (default "\e033[7m")
cursorpreviewfmt string (default "\e033[4m")
.EE
.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. `cursorfmt` 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
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
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
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
Expand Down
2 changes: 2 additions & 0 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var gOpts struct {
anchorfind bool
autoquit bool
cursorfmt string
cursorparentfmt string
cursorpreviewfmt string
dircache bool
dircounts bool
Expand Down Expand Up @@ -92,6 +93,7 @@ func init() {
gOpts.dirpreviews = false
gOpts.drawbox = false
gOpts.cursorfmt = "\033[7m"
gOpts.cursorparentfmt = "\033[7m"
gOpts.cursorpreviewfmt = "\033[4m"
gOpts.globsearch = false
gOpts.icons = false
Expand Down
37 changes: 27 additions & 10 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,18 @@ type dirContext struct {
tags map[string]string
}

type dirRole int

const (
Active dirRole = iota
Parent
Preview
)

type dirStyle struct {
colors styleMap
icons iconMap
previewing bool
colors styleMap
icons iconMap
role dirRole
}

// These colors are not currently customizeable
Expand All @@ -353,12 +361,12 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
win.print(screen, 2, 0, messageStyle, "permission denied")
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...")
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.
st := tcell.StyleDefault
for i, l := range dir.lines {
Expand Down Expand Up @@ -475,10 +483,13 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir

ce := ""
if i == dir.pos {
if dirStyle.previewing {
ce = gOpts.cursorpreviewfmt
} else {
switch dirStyle.role {
case Active:
ce = gOpts.cursorfmt
case Parent:
ce = gOpts.cursorparentfmt
case Preview:
ce = gOpts.cursorpreviewfmt
}
}
cursorescapefmt := optionToFmtstr(ce)
Expand Down Expand Up @@ -920,9 +931,15 @@ func (ui *ui) draw(nav *nav) {
wins--
}
for i := 0; i < wins; i++ {
var role dirRole
if i < wins-1 {
role = Parent
} else {
role = Active
}
if dir := ui.dirOfWin(nav, i); dir != nil {
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})
}
}

Expand Down Expand Up @@ -958,7 +975,7 @@ func (ui *ui) draw(nav *nav) {

if curr.IsDir() {
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() {
preview.printReg(ui.screen, ui.regPrev)
}
Expand Down

0 comments on commit 52f1593

Please sign in to comment.