Skip to content

Commit

Permalink
No-op changes to ui.go
Browse files Browse the repository at this point in the history
Reduce number of arguments to printDir and list non-configurable colors
  • Loading branch information
ilyagr committed Sep 3, 2022
1 parent 6e24001 commit fa3e7d7
Showing 1 changed file with 62 additions and 40 deletions.
102 changes: 62 additions & 40 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,26 @@ 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, activeCursor bool) {
type dirContext struct {
selections map[string]int
saves map[string]bool
tags map[string]string
}

type dirStyle struct {
colors styleMap
icons iconMap
activeCursor 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
}
Expand Down Expand Up @@ -366,7 +385,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 @@ -386,24 +405,24 @@ 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 !activeCursor {
if !dirStyle.activeCursor {
st = st.Foreground(tcell.ColorGrey)
}
}
Expand All @@ -415,7 +434,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 @@ -453,7 +472,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 @@ -464,33 +483,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
menuSelected int
cmdPrefix string
cmdAccLeft []rune
cmdAccRight []rune
cmdYankBuf []rune
cmdTmp []rune
keyAcc []rune
keyCount []rune
styles styleMap
icons iconMap
}

func getWidths(wtot int) []int {
rsum := 0
for _, r := range gOpts.ratios {
Expand Down Expand Up @@ -535,6 +527,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
menuSelected int
cmdPrefix string
cmdAccLeft []rune
cmdAccRight []rune
cmdYankBuf []rune
cmdTmp []rune
keyAcc []rune
keyCount []rune
styles styleMap
icons iconMap
}

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

Expand Down Expand Up @@ -838,6 +857,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 @@ -858,7 +878,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, true)
ui.wins[woff+i].printDir(ui.screen, nav.dirs[doff+i], &context,
&dirStyle{colors: ui.styles, icons: ui.icons, activeCursor: true})
}

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

0 comments on commit fa3e7d7

Please sign in to comment.