Add hidecursorinactive option to indicate status when terminal loses focus (#965)
* Enable focus events through configuration by using focus (option) and on-ui-enter/on-ui-exit events. * Revert doc This reverts commit77f113639f. * Revert rune evt This reverts commit77f113639f. * hidecursorinactive with tcell * cleanup * cleanup
This commit is contained in:
1 parent
2a4adb323f
commit
075caac3a9
8 files changed
+818
-997
No files matched your search
@@ -36,6 +36,7 @@ func run() {
|
||||
if gOpts.mouse {
|
||||
screen.EnableMouse()
|
||||
}
|
||||
screen.EnableFocus()
|
||||
|
||||
if gLogPath != "" {
|
||||
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
|
||||
@@ -120,6 +120,9 @@ var (
|
||||
"cursoractivefmt",
|
||||
"cursorparentfmt",
|
||||
"cursorpreviewfmt",
|
||||
"hidecursorinactive",
|
||||
"nohidecursorinactive",
|
||||
"hidecursorinactive!",
|
||||
"dircache",
|
||||
"nodircache",
|
||||
"dircache!",
|
||||
|
||||
@@ -136,69 +136,70 @@ The following command line commands are provided by lf:
|
||||
|
||||
The following options can be used to customize the behavior of lf:
|
||||
|
||||
anchorfind bool (default true)
|
||||
autoquit bool (default false)
|
||||
borderfmt string (default "\033[0m")
|
||||
cleaner string (default '')
|
||||
cursoractivefmt string (default "\033[7m")
|
||||
cursorparentfmt string (default "\033[7m")
|
||||
cursorpreviewfmt string (default "\033[4m")
|
||||
dircache bool (default true)
|
||||
dircounts bool (default false)
|
||||
dirfirst bool (default true)
|
||||
dironly bool (default false)
|
||||
dirpreviews bool (default false)
|
||||
drawbox bool (default false)
|
||||
dupfilefmt string (default '%f.~%n~')
|
||||
errorfmt string (default "\033[7;31;47m")
|
||||
filesep string (default "\n")
|
||||
findlen int (default 1)
|
||||
globsearch bool (default false)
|
||||
hidden bool (default false)
|
||||
hiddenfiles []string (default '.*')
|
||||
history bool (default true)
|
||||
icons bool (default false)
|
||||
ifs string (default '')
|
||||
ignorecase bool (default true)
|
||||
ignoredia bool (default true)
|
||||
incfilter bool (default false)
|
||||
incsearch bool (default false)
|
||||
info []string (default '')
|
||||
infotimefmtnew string (default 'Jan _2 15:04')
|
||||
infotimefmtold string (default 'Jan _2 2006')
|
||||
mouse bool (default false)
|
||||
number bool (default false)
|
||||
numberfmt string (default "\033[33m")
|
||||
period int (default 0)
|
||||
preserve []string (default "mode")
|
||||
preview bool (default true)
|
||||
previewer string (default '')
|
||||
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m")
|
||||
ratios []int (default '1:2:3')
|
||||
relativenumber bool (default false)
|
||||
reverse bool (default false)
|
||||
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)
|
||||
selmode string (default 'all')
|
||||
shell string (default 'sh' for Unix and 'cmd' for Windows)
|
||||
shellflag string (default '-c' for Unix and '/c' for Windows)
|
||||
shellopts []string (default '')
|
||||
sixel bool (default false)
|
||||
smartcase bool (default true)
|
||||
smartdia bool (default false)
|
||||
sortby string (default 'natural')
|
||||
statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l")
|
||||
tabstop int (default 8)
|
||||
tagfmt string (default "\033[31m")
|
||||
tempmarks string (default '')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
truncatechar string (default '~')
|
||||
truncatepct int (default 100)
|
||||
waitmsg string (default 'Press any key to continue')
|
||||
wrapscan bool (default true)
|
||||
wrapscroll bool (default false)
|
||||
user_{option} string (default none)
|
||||
anchorfind bool (default true)
|
||||
autoquit bool (default false)
|
||||
borderfmt string (default "\033[0m")
|
||||
cleaner string (default '')
|
||||
cursoractivefmt string (default "\033[7m")
|
||||
cursorparentfmt string (default "\033[7m")
|
||||
cursorpreviewfmt string (default "\033[4m")
|
||||
dircache bool (default true)
|
||||
dircounts bool (default false)
|
||||
dirfirst bool (default true)
|
||||
dironly bool (default false)
|
||||
dirpreviews bool (default false)
|
||||
drawbox bool (default false)
|
||||
dupfilefmt string (default '%f.~%n~')
|
||||
errorfmt string (default "\033[7;31;47m")
|
||||
filesep string (default "\n")
|
||||
findlen int (default 1)
|
||||
globsearch bool (default false)
|
||||
hidden bool (default false)
|
||||
hiddenfiles []string (default '.*')
|
||||
hidecursorinactive bool (default false)
|
||||
history bool (default true)
|
||||
icons bool (default false)
|
||||
ifs string (default '')
|
||||
ignorecase bool (default true)
|
||||
ignoredia bool (default true)
|
||||
incfilter bool (default false)
|
||||
incsearch bool (default false)
|
||||
info []string (default '')
|
||||
infotimefmtnew string (default 'Jan _2 15:04')
|
||||
infotimefmtold string (default 'Jan _2 2006')
|
||||
mouse bool (default false)
|
||||
number bool (default false)
|
||||
numberfmt string (default "\033[33m")
|
||||
period int (default 0)
|
||||
preserve []string (default "mode")
|
||||
preview bool (default true)
|
||||
previewer string (default '')
|
||||
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m")
|
||||
ratios []int (default '1:2:3')
|
||||
relativenumber bool (default false)
|
||||
reverse bool (default false)
|
||||
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)
|
||||
selmode string (default 'all')
|
||||
shell string (default 'sh' for Unix and 'cmd' for Windows)
|
||||
shellflag string (default '-c' for Unix and '/c' for Windows)
|
||||
shellopts []string (default '')
|
||||
sixel bool (default false)
|
||||
smartcase bool (default true)
|
||||
smartdia bool (default false)
|
||||
sortby string (default 'natural')
|
||||
statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l")
|
||||
tabstop int (default 8)
|
||||
tagfmt string (default "\033[31m")
|
||||
tempmarks string (default '')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
truncatechar string (default '~')
|
||||
truncatepct int (default 100)
|
||||
waitmsg string (default 'Press any key to continue')
|
||||
wrapscan bool (default true)
|
||||
wrapscroll bool (default false)
|
||||
user_{option} string (default none)
|
||||
|
||||
The following environment variables are exported for shell commands:
|
||||
|
||||
@@ -755,6 +756,10 @@ Patterns can be given as relative or absolute paths.
|
||||
Globbing supports the usual special characters, `*` to match any sequence, `?` to match any character, and `[...]` or `[^...]` to match character sets or ranges.
|
||||
In addition, if a pattern starts with `!`, then its matches are excluded from hidden files. To add multiple patterns, use `:` as a separator. Example: `.*:lost+found:*.bak`
|
||||
|
||||
## hidecursorinactive (bool) (default false)
|
||||
|
||||
Hide the cursor when the terminal or tmux pane loses focus.
|
||||
|
||||
## history (bool) (default true)
|
||||
|
||||
Save command history.
|
||||
|
||||
@@ -68,6 +68,27 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.cursorparentfmt = e.val
|
||||
case "cursorpreviewfmt":
|
||||
gOpts.cursorpreviewfmt = e.val
|
||||
case "hidecursorinactive":
|
||||
if e.val == "" || e.val == "true" {
|
||||
gOpts.hidecursorinactive = true
|
||||
} else if e.val == "false" {
|
||||
gOpts.hidecursorinactive = false
|
||||
} else {
|
||||
app.ui.echoerr("hidecursorinactive: value should be empty, 'true', or 'false'")
|
||||
return
|
||||
}
|
||||
case "nohidecursorinactive":
|
||||
if e.val != "" {
|
||||
app.ui.echoerrf("nohidecursorinactive: unexpected value: %s", e.val)
|
||||
return
|
||||
}
|
||||
gOpts.hidecursorinactive = false
|
||||
case "hidecursorinactive!":
|
||||
if e.val != "" {
|
||||
app.ui.echoerrf("hidecursorinactive!: unexpected value: %s", e.val)
|
||||
return
|
||||
}
|
||||
gOpts.hidecursorinactive = !gOpts.hidecursorinactive
|
||||
case "dircache":
|
||||
if e.val == "" || e.val == "true" {
|
||||
gOpts.dircache = true
|
||||
|
||||
@@ -31,69 +31,70 @@ type sortType struct {
|
||||
}
|
||||
|
||||
var gOpts struct {
|
||||
anchorfind bool
|
||||
autoquit bool
|
||||
borderfmt string
|
||||
cursoractivefmt string
|
||||
cursorparentfmt string
|
||||
cursorpreviewfmt string
|
||||
dircache bool
|
||||
dircounts bool
|
||||
dironly bool
|
||||
dirpreviews bool
|
||||
drawbox bool
|
||||
dupfilefmt string
|
||||
globsearch bool
|
||||
icons bool
|
||||
ignorecase bool
|
||||
ignoredia bool
|
||||
incfilter bool
|
||||
incsearch bool
|
||||
mouse bool
|
||||
number bool
|
||||
preview bool
|
||||
sixel bool
|
||||
relativenumber bool
|
||||
smartcase bool
|
||||
smartdia bool
|
||||
waitmsg string
|
||||
wrapscan bool
|
||||
wrapscroll bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
errorfmt string
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
cleaner string
|
||||
promptfmt string
|
||||
selmode string
|
||||
shell string
|
||||
shellflag string
|
||||
statfmt string
|
||||
timefmt string
|
||||
infotimefmtnew string
|
||||
infotimefmtold string
|
||||
truncatechar string
|
||||
truncatepct int
|
||||
ratios []int
|
||||
hiddenfiles []string
|
||||
history bool
|
||||
info []string
|
||||
ruler []string
|
||||
rulerfmt string
|
||||
preserve []string
|
||||
shellopts []string
|
||||
keys map[string]expr
|
||||
cmdkeys map[string]expr
|
||||
cmds map[string]expr
|
||||
user map[string]string
|
||||
sortType sortType
|
||||
tempmarks string
|
||||
numberfmt string
|
||||
tagfmt string
|
||||
anchorfind bool
|
||||
autoquit bool
|
||||
borderfmt string
|
||||
cursoractivefmt string
|
||||
cursorparentfmt string
|
||||
cursorpreviewfmt string
|
||||
hidecursorinactive bool
|
||||
dircache bool
|
||||
dircounts bool
|
||||
dironly bool
|
||||
dirpreviews bool
|
||||
drawbox bool
|
||||
dupfilefmt string
|
||||
globsearch bool
|
||||
icons bool
|
||||
ignorecase bool
|
||||
ignoredia bool
|
||||
incfilter bool
|
||||
incsearch bool
|
||||
mouse bool
|
||||
number bool
|
||||
preview bool
|
||||
sixel bool
|
||||
relativenumber bool
|
||||
smartcase bool
|
||||
smartdia bool
|
||||
waitmsg string
|
||||
wrapscan bool
|
||||
wrapscroll bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
errorfmt string
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
cleaner string
|
||||
promptfmt string
|
||||
selmode string
|
||||
shell string
|
||||
shellflag string
|
||||
statfmt string
|
||||
timefmt string
|
||||
infotimefmtnew string
|
||||
infotimefmtold string
|
||||
truncatechar string
|
||||
truncatepct int
|
||||
ratios []int
|
||||
hiddenfiles []string
|
||||
history bool
|
||||
info []string
|
||||
ruler []string
|
||||
rulerfmt string
|
||||
preserve []string
|
||||
shellopts []string
|
||||
keys map[string]expr
|
||||
cmdkeys map[string]expr
|
||||
cmds map[string]expr
|
||||
user map[string]string
|
||||
sortType sortType
|
||||
tempmarks string
|
||||
numberfmt string
|
||||
tagfmt string
|
||||
}
|
||||
|
||||
var gLocalOpts struct {
|
||||
@@ -194,6 +195,7 @@ func init() {
|
||||
gOpts.cursoractivefmt = "\033[7m"
|
||||
gOpts.cursorparentfmt = "\033[7m"
|
||||
gOpts.cursorpreviewfmt = "\033[4m"
|
||||
gOpts.hidecursorinactive = false
|
||||
gOpts.globsearch = false
|
||||
gOpts.icons = false
|
||||
gOpts.ignorecase = true
|
||||
|
||||
@@ -353,7 +353,7 @@ const SelectionColor = tcell.ColorPurple
|
||||
const YankColor = tcell.ColorOlive
|
||||
const CutColor = tcell.ColorMaroon
|
||||
|
||||
func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dirStyle *dirStyle, previewLoading bool) {
|
||||
func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle, previewLoading bool) {
|
||||
if win.w < 5 || dir == nil {
|
||||
return
|
||||
}
|
||||
@@ -361,12 +361,12 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
||||
messageStyle := tcell.StyleDefault.Reverse(true)
|
||||
|
||||
if dir.noPerm {
|
||||
win.print(screen, 2, 0, messageStyle, "permission denied")
|
||||
win.print(ui.screen, 2, 0, messageStyle, "permission denied")
|
||||
return
|
||||
}
|
||||
if (dir.loading && len(dir.files) == 0) || (dirStyle.role == Preview && dir.loading && gOpts.dirpreviews) {
|
||||
if dirStyle.role != Preview || previewLoading {
|
||||
win.print(screen, 2, 0, messageStyle, "loading...")
|
||||
win.print(ui.screen, 2, 0, messageStyle, "loading...")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -379,12 +379,12 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
||||
break
|
||||
}
|
||||
|
||||
st = win.print(screen, 2, i, st, l)
|
||||
st = win.print(ui.screen, 2, i, st, l)
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(dir.files) == 0 {
|
||||
win.print(screen, 2, 0, messageStyle, "empty")
|
||||
win.print(ui.screen, 2, 0, messageStyle, "empty")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -428,18 +428,18 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
||||
}
|
||||
}
|
||||
|
||||
win.print(screen, 0, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.numberfmt), ln))
|
||||
win.print(ui.screen, 0, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.numberfmt), ln))
|
||||
}
|
||||
|
||||
path := filepath.Join(dir.path, f.Name())
|
||||
|
||||
if _, ok := context.selections[path]; ok {
|
||||
win.print(screen, lnwidth, i, st.Background(SelectionColor), " ")
|
||||
win.print(ui.screen, lnwidth, i, st.Background(SelectionColor), " ")
|
||||
} else if cp, ok := context.saves[path]; ok {
|
||||
if cp {
|
||||
win.print(screen, lnwidth, i, st.Background(YankColor), " ")
|
||||
win.print(ui.screen, lnwidth, i, st.Background(YankColor), " ")
|
||||
} else {
|
||||
win.print(screen, lnwidth, i, st.Background(CutColor), " ")
|
||||
win.print(ui.screen, lnwidth, i, st.Background(CutColor), " ")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
||||
}
|
||||
|
||||
ce := ""
|
||||
if i == dir.pos {
|
||||
if i == dir.pos && (ui.focused || !gOpts.hidecursorinactive) {
|
||||
switch dirStyle.role {
|
||||
case Active:
|
||||
ce = gOpts.cursoractivefmt
|
||||
@@ -500,14 +500,14 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
||||
|
||||
s = append(s, ' ')
|
||||
styledFilename := fmt.Sprintf(cursorescapefmt, string(s))
|
||||
win.print(screen, lnwidth+1, i, st, styledFilename)
|
||||
win.print(ui.screen, lnwidth+1, i, st, styledFilename)
|
||||
|
||||
tag, ok := context.tags[path]
|
||||
if ok {
|
||||
if i == dir.pos {
|
||||
win.print(screen, lnwidth+1, i, st, fmt.Sprintf(cursorescapefmt, tag))
|
||||
win.print(ui.screen, lnwidth+1, i, st, fmt.Sprintf(cursorescapefmt, tag))
|
||||
} else {
|
||||
win.print(screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag))
|
||||
win.print(ui.screen, lnwidth+1, i, tcell.StyleDefault, fmt.Sprintf(optionToFmtstr(gOpts.tagfmt), tag))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -562,6 +562,7 @@ type ui struct {
|
||||
screen tcell.Screen
|
||||
sxScreen sixelScreen
|
||||
polling bool
|
||||
focused bool
|
||||
wins []*win
|
||||
promptWin *win
|
||||
msgWin *win
|
||||
@@ -592,6 +593,7 @@ func newUI(screen tcell.Screen) *ui {
|
||||
ui := &ui{
|
||||
screen: screen,
|
||||
polling: true,
|
||||
focused: true,
|
||||
wins: getWins(screen),
|
||||
promptWin: newWin(wtot, 1, 0, 0),
|
||||
msgWin: newWin(wtot, 1, 0, htot-1),
|
||||
@@ -1029,7 +1031,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
role = Active
|
||||
}
|
||||
if dir := ui.dirOfWin(nav, i); dir != nil {
|
||||
ui.wins[i].printDir(ui.screen, dir, &context,
|
||||
ui.wins[i].printDir(ui, dir, &context,
|
||||
&dirStyle{colors: ui.styles, icons: ui.icons, role: role},
|
||||
nav.previewLoading)
|
||||
}
|
||||
@@ -1060,7 +1062,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
preview := ui.wins[len(ui.wins)-1]
|
||||
|
||||
if curr.IsDir() {
|
||||
preview.printDir(ui.screen, ui.dirPrev, &context,
|
||||
preview.printDir(ui, ui.dirPrev, &context,
|
||||
&dirStyle{colors: ui.styles, icons: ui.icons, role: Preview},
|
||||
nav.previewLoading)
|
||||
} else if curr.Mode().IsRegular() {
|
||||
@@ -1445,6 +1447,9 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
|
||||
log.Printf("Got EventError: '%s' at %s", tev.Error(), tev.When())
|
||||
case *tcell.EventInterrupt:
|
||||
log.Printf("Got EventInterrupt: at %s", tev.When())
|
||||
case *tcell.EventFocus:
|
||||
ui.focused = tev.Focused
|
||||
return draw
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user