Allow separate styles for cursor in normal and preview panes, simplify tagfmt and errorfmt (#1086)

* Allow separate styles for cursor in normal and preview panes

This defines new `cursorfmt` and `crusorpreviewfmt` options to style cursor in normal/preview panes. This allows using a different style for the normal and preview cursor. The documentation includes several possible values these options can be set to.

The default behavior is an underline, same as in
https://github.com/gokcehan/lf/pull/1072, since it should not cause severe
problems and be visible on all terminals. It can now be easily changed, as explained in the docs. I also added an example to `etc/lfrc.example`.

See linked issues and PRs for the more context.

Fixes https://github.com/gokcehan/lf/issues/1038

Follows up on:

https://github.com/gokcehan/lf/pull/1072
https://github.com/gokcehan/lf/pull/924
https://github.com/gokcehan/lf/commit/b47cf6d5a5

* Simplify configuration of several formatting options

This simplifies the configuration of `cursorfmt`, `cursorpreviewfmt`, `tagfmt`,
and `errorfmt` options.

In almost all usecases, the value of these options had to end with `%s\033[0m`
to print the contents of filename/tag/error and reset the terminal style. Now,
if `%s` is not part of the option's value, `%s\033[0m` is appended
automatically. This simplifies configuration.

I retained the same behavior as before when `%s` is part of the string for
backwards compatibility. I think it should be considered deprecated, but it
also causes no harm.
This commit is contained in:
Ilya Grigoriev authored and GitHub committed 2023-02-11 20:11:07 +03:00
1 parent 4a443cae58
commit 530ab2c40a
8 files changed
+315 -221

No files matched your search

+23 -9
View File
@@ -432,10 +432,6 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
}
}
if i == dir.pos {
st = st.Reverse(true)
}
var s []rune
s = append(s, ' ')
@@ -477,16 +473,26 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
}
}
s = append(s, ' ')
ce := ""
if i == dir.pos {
if dirStyle.previewing {
ce = gOpts.cursorpreviewfmt
} else {
ce = gOpts.cursorfmt
}
}
cursorescapefmt := optionToFmtstr(ce)
win.print(screen, lnwidth+1, i, st, string(s))
s = append(s, ' ')
styledFilename := fmt.Sprintf(cursorescapefmt, string(s))
win.print(screen, lnwidth+1, i, st, styledFilename)
tag, ok := context.tags[path]
if ok {
if i == dir.pos {
win.print(screen, lnwidth+1, i, st, tag)
win.print(screen, lnwidth+1, i, st, fmt.Sprintf(cursorescapefmt, tag))
} else {
win.print(screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(gOpts.tagfmt, tag))
win.print(screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag))
}
}
}
@@ -652,8 +658,16 @@ func (ui *ui) echomsg(msg string) {
log.Print(msg)
}
func optionToFmtstr(optstr string) string {
if !strings.Contains(optstr, "%s") {
return optstr + "%s\033[0m"
} else {
return optstr
}
}
func (ui *ui) echoerr(msg string) {
ui.msg = fmt.Sprintf(gOpts.errorfmt, msg)
ui.msg = fmt.Sprintf(optionToFmtstr(gOpts.errorfmt), msg)
log.Printf("error: %s", msg)
}