Skip to content

Commit

Permalink
For directories in preview column, dim cursor
Browse files Browse the repository at this point in the history
When preview is on and consists of a directory listing, make the
cursor in there dimmer to emphasize it's not active. This makes it
visually obvious which cursor is active at all times, without
having to read the path. The active cursor is now always  the
rightmost bright one, regardless of whether the `preview` option
is on or off.

See screenshots in the pull request.

Before this, I noticed that I often open a file by accident because
I got confused which of the three cursors on the screen is the active
one.

In the future, I also hope this dimming could be used to show when an lf
window loses focus, based on @laktak's implementation of focus tracking
in gokcehan#861.
  • Loading branch information
ilyagr committed Aug 30, 2022
1 parent b0cb926 commit 27ff6e7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func fileInfo(f *file, d *dir) string {
return info
}

func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]int, saves map[string]bool, tags map[string]string, colors styleMap, icons iconMap) {
func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]int, saves map[string]bool, tags map[string]string, colors styleMap, icons iconMap, dim_cursor bool) {
if win.w < 5 || dir == nil {
return
}
Expand Down Expand Up @@ -403,6 +403,9 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in

if i == dir.pos {
st = st.Reverse(true)
if dim_cursor {
st = st.Foreground(tcell.ColorGrey)
}
}

var s []rune
Expand Down Expand Up @@ -855,7 +858,7 @@ func (ui *ui) draw(nav *nav) {

doff := len(nav.dirs) - length
for i := 0; i < length; i++ {
ui.wins[woff+i].printDir(ui.screen, nav.dirs[doff+i], nav.selections, nav.saves, nav.tags, ui.styles, ui.icons)
ui.wins[woff+i].printDir(ui.screen, nav.dirs[doff+i], nav.selections, nav.saves, nav.tags, ui.styles, ui.icons, false)
}

switch ui.cmdPrefix {
Expand Down Expand Up @@ -889,7 +892,7 @@ func (ui *ui) draw(nav *nav) {
preview := ui.wins[len(ui.wins)-1]

if curr.IsDir() {
preview.printDir(ui.screen, ui.dirPrev, nav.selections, nav.saves, nav.tags, ui.styles, ui.icons)
preview.printDir(ui.screen, ui.dirPrev, nav.selections, nav.saves, nav.tags, ui.styles, ui.icons, true)
} else if curr.Mode().IsRegular() {
preview.printReg(ui.screen, ui.regPrev)
}
Expand Down

0 comments on commit 27ff6e7

Please sign in to comment.