Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For directories in preview column, dim cursor #924

Merged
merged 2 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added qq
Empty file.
120 changes: 73 additions & 47 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,24 +324,45 @@ 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, previewAllowed bool) {
type dirContext struct {
selections map[string]int
saves map[string]bool
tags map[string]string
}

type dirStyle struct {
colors styleMap
icons iconMap
previewing bool
}

// These colors are not currently customizeable
const LineNumberColor = tcell.ColorOlive
const SelectionColor = tcell.ColorPurple
const YankColor = tcell.ColorOlive
const CutColor = tcell.ColorMaroon
const DimCursorColor = tcell.ColorGrey

func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dirStyle *dirStyle) {
if win.w < 5 || dir == nil {
return
}

messageStyle := tcell.StyleDefault.Reverse(true)
if dirStyle.previewing {
messageStyle = messageStyle.Foreground(DimCursorColor)
}

if dir.noPerm {
win.print(screen, 2, 0, tcell.StyleDefault.Reverse(true), "permission denied")
win.print(screen, 2, 0, messageStyle, "permission denied")
return
}

if (dir.loading && len(dir.files) == 0) || (previewAllowed && dir.loading && gOpts.dirpreviews) {
win.print(screen, 2, 0, tcell.StyleDefault.Reverse(true), "loading...")
if (dir.loading && len(dir.files) == 0) || (dirStyle.previewing && dir.loading && gOpts.dirpreviews) {
win.print(screen, 2, 0, messageStyle, "loading...")
return
}

if previewAllowed && gOpts.dirpreviews && len(gOpts.previewer) > 0 {

if dirStyle.previewing && 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 All @@ -353,9 +374,8 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in
}
return
}

if len(dir.files) == 0 {
win.print(screen, 2, 0, tcell.StyleDefault.Reverse(true), "empty")
win.print(screen, 2, 0, messageStyle, "empty")
return
}

Expand All @@ -381,7 +401,7 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in
}

for i, f := range dir.files[beg:end] {
st := colors.get(f)
st := dirStyle.colors.get(f)

if lnwidth > 0 {
var ln string
Expand All @@ -401,23 +421,26 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in
}
}

win.print(screen, 0, i, tcell.StyleDefault.Foreground(tcell.ColorOlive), ln)
win.print(screen, 0, i, tcell.StyleDefault.Foreground(LineNumberColor), ln)
}

path := filepath.Join(dir.path, f.Name())

if _, ok := selections[path]; ok {
win.print(screen, lnwidth, i, st.Background(tcell.ColorPurple), " ")
} else if cp, ok := saves[path]; ok {
if _, ok := context.selections[path]; ok {
win.print(screen, lnwidth, i, st.Background(SelectionColor), " ")
} else if cp, ok := context.saves[path]; ok {
if cp {
win.print(screen, lnwidth, i, st.Background(tcell.ColorOlive), " ")
win.print(screen, lnwidth, i, st.Background(YankColor), " ")
} else {
win.print(screen, lnwidth, i, st.Background(tcell.ColorMaroon), " ")
win.print(screen, lnwidth, i, st.Background(CutColor), " ")
}
}

if i == dir.pos {
st = st.Reverse(true)
if dirStyle.previewing {
st = st.Foreground(DimCursorColor)
}
}

var s []rune
Expand All @@ -427,7 +450,7 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in
var iwidth int

if gOpts.icons {
s = append(s, []rune(icons.get(f))...)
s = append(s, []rune(dirStyle.icons.get(f))...)
s = append(s, ' ')
iwidth = 2
}
Expand Down Expand Up @@ -465,7 +488,7 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in

win.print(screen, lnwidth+1, i, st, string(s))

tag, ok := tags[path]
tag, ok := context.tags[path]
if ok {
if i == dir.pos {
win.print(screen, lnwidth+1, i, st.Reverse(true), tag)
Expand All @@ -476,33 +499,6 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, selections map[string]in
}
}

type ui struct {
screen tcell.Screen
polling bool
wins []*win
promptWin *win
msgWin *win
menuWin *win
msg string
regPrev *reg
dirPrev *dir
exprChan chan expr
keyChan chan string
tevChan chan tcell.Event
evChan chan tcell.Event
menuBuf *bytes.Buffer
cmdPrefix string
cmdAccLeft []rune
cmdAccRight []rune
cmdYankBuf []rune
cmdTmp []rune
keyAcc []rune
keyCount []rune
styles styleMap
icons iconMap
currentFile string
}

func getWidths(wtot int) []int {
rsum := 0
for _, r := range gOpts.ratios {
Expand Down Expand Up @@ -547,6 +543,33 @@ func getWins(screen tcell.Screen) []*win {
return wins
}

type ui struct {
screen tcell.Screen
polling bool
wins []*win
promptWin *win
msgWin *win
menuWin *win
msg string
regPrev *reg
dirPrev *dir
exprChan chan expr
keyChan chan string
tevChan chan tcell.Event
evChan chan tcell.Event
menuBuf *bytes.Buffer
cmdPrefix string
cmdAccLeft []rune
cmdAccRight []rune
cmdYankBuf []rune
cmdTmp []rune
keyAcc []rune
keyCount []rune
styles styleMap
icons iconMap
currentFile string
}

func newUI(screen tcell.Screen) *ui {
wtot, htot := screen.Size()

Expand Down Expand Up @@ -857,6 +880,7 @@ func (ui *ui) drawBox() {

func (ui *ui) draw(nav *nav) {
st := tcell.StyleDefault
context := dirContext{selections: nav.selections, saves: nav.saves, tags: nav.tags}

wtot, htot := ui.screen.Size()
for i := 0; i < wtot; i++ {
Expand All @@ -877,7 +901,8 @@ 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, false)
ui.wins[woff+i].printDir(ui.screen, nav.dirs[doff+i], &context,
&dirStyle{colors: ui.styles, icons: ui.icons, previewing: false})
}

switch ui.cmdPrefix {
Expand Down Expand Up @@ -911,7 +936,8 @@ 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, true)
preview.printDir(ui.screen, ui.dirPrev, &context,
&dirStyle{colors: ui.styles, icons: ui.icons, previewing: true})
} else if curr.Mode().IsRegular() {
preview.printReg(ui.screen, ui.regPrev)
}
Expand Down