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 commit 77f113639f.

* Revert rune evt

This reverts commit 77f113639f.

* hidecursorinactive with tcell

* cleanup

* cleanup
This commit is contained in:
Christian Zangl authored and GitHub committed 2023-12-26 15:37:11 +01:00
1 parent 2a4adb323f
commit 075caac3a9
8 files changed
+818 -997

No files matched your search

+20 -15
View File
@@ -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
}