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 Oct 15, 2022
1 parent 1401c32 commit ecb2c02
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 45 deletions.
Empty file added qq
Empty file.
112 changes: 67 additions & 45 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,26 +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, previewing 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 previewing {
messageStyle = messageStyle.Foreground(tcell.ColorGrey)
if dirStyle.previewing {
messageStyle = messageStyle.Foreground(DimCursorColor)
}

if dir.noPerm {
win.print(screen, 2, 0, messageStyle, "permission denied")
return
}
if (dir.loading && len(dir.files) == 0) || (previewing && dir.loading && gOpts.dirpreviews) {
if (dir.loading && len(dir.files) == 0) || (dirStyle.previewing && dir.loading && gOpts.dirpreviews) {
win.print(screen, 2, 0, messageStyle, "loading...")
return
}

if previewing && 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 Down Expand Up @@ -382,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 @@ -402,25 +421,25 @@ 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 previewing {
st = st.Foreground(tcell.ColorGrey)
if dirStyle.previewing {
st = st.Foreground(DimCursorColor)
}
}

Expand All @@ -431,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 @@ -469,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 @@ -480,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 @@ -551,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 @@ -861,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 @@ -881,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 @@ -915,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

0 comments on commit ecb2c02

Please sign in to comment.