add 'drawbox' option to draw box around windows

This commit is contained in:
Gokcehan 2018-04-15 19:26:51 +03:00
parent d608eb4a56
commit 8eb9055622
6 changed files with 77 additions and 5 deletions

View File

@ -58,6 +58,9 @@ var (
"dirfirst",
"nodirfirst",
"dirfirst!",
"drawbox",
"nodrawbox",
"drawbox!",
"globsearch",
"noglobsearch",
"globsearch!",

1
doc.go
View File

@ -76,6 +76,7 @@ The following options can be used to customize the behavior of lf:
dircounts boolean (default off)
dirfirst boolean (default on)
drawbox boolean (default off)
globsearch boolean (default off)
hidden boolean (default off)
ignorecase boolean (default on)

View File

@ -80,6 +80,7 @@ The following options can be used to customize the behavior of lf:
dircounts boolean (default off)
dirfirst boolean (default on)
drawbox boolean (default off)
globsearch boolean (default off)
hidden boolean (default off)
ignorecase boolean (default on)

12
eval.go
View File

@ -26,6 +26,18 @@ func (e *setExpr) eval(app *app, args []string) {
case "dirfirst!":
gOpts.dirfirst = !gOpts.dirfirst
app.nav.sort()
case "drawbox":
gOpts.drawbox = true
app.ui.renew()
app.nav.height = app.ui.wins[0].h
case "nodrawbox":
gOpts.drawbox = false
app.ui.renew()
app.nav.height = app.ui.wins[0].h
case "drawbox!":
gOpts.drawbox = !gOpts.drawbox
app.ui.renew()
app.nav.height = app.ui.wins[0].h
case "globsearch":
gOpts.globsearch = true
case "noglobsearch":

View File

@ -5,6 +5,7 @@ import "time"
var gOpts struct {
dircounts bool
dirfirst bool
drawbox bool
globsearch bool
hidden bool
ignorecase bool
@ -31,6 +32,7 @@ var gOpts struct {
func init() {
gOpts.dircounts = false
gOpts.dirfirst = true
gOpts.drawbox = false
gOpts.globsearch = false
gOpts.hidden = false
gOpts.ignorecase = true

63
ui.go
View File

@ -276,10 +276,12 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool,
return
}
maxind := len(dir.fi) - 1
beg := max(dir.ind-dir.pos, 0)
end := min(beg+win.h, maxind+1)
end := min(beg+win.h, len(dir.fi))
if beg > end {
return
}
for i, f := range dir.fi[beg:end] {
fg, bg = colors.get(f)
@ -376,6 +378,10 @@ func getWidths(wtot int) []int {
}
widths[wlen-1] = wtot - wsum
if gOpts.drawbox {
widths[wlen-1]--
}
return widths
}
@ -389,7 +395,11 @@ func getWins() []*win {
wacc := 0
wlen := len(widths)
for i := 0; i < wlen; i++ {
wins = append(wins, newWin(widths[i], htot-2, wacc, 1))
if gOpts.drawbox {
wins = append(wins, newWin(widths[i], htot-4, wacc+1, 2))
} else {
wins = append(wins, newWin(widths[i], htot-2, wacc, 1))
}
wacc += widths[i]
}
@ -426,7 +436,11 @@ func (ui *ui) renew() {
wacc := 0
wlen := len(widths)
for i := 0; i < wlen; i++ {
ui.wins[i].renew(widths[i], htot-2, wacc, 1)
if gOpts.drawbox {
ui.wins[i].renew(widths[i], htot-4, wacc+1, 2)
} else {
ui.wins[i].renew(widths[i], htot-2, wacc, 1)
}
wacc += widths[i]
}
@ -529,6 +543,37 @@ func (ui *ui) drawStatLine(nav *nav) {
ui.msgWin.printRight(0, fg, bg, ruler)
}
func (ui *ui) drawBox(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault
w, h := termbox.Size()
for i := 1; i < w-1; i++ {
termbox.SetCell(i, 1, '─', fg, bg)
termbox.SetCell(i, h-2, '─', fg, bg)
}
for i := 2; i < h-2; i++ {
termbox.SetCell(0, i, '│', fg, bg)
termbox.SetCell(w-1, i, '│', fg, bg)
}
termbox.SetCell(0, 1, '┌', fg, bg)
termbox.SetCell(w-1, 1, '┐', fg, bg)
termbox.SetCell(0, h-2, '└', fg, bg)
termbox.SetCell(w-1, h-2, '┘', fg, bg)
wacc := 0
for wind := 0; wind < len(ui.wins)-1; wind++ {
wacc += ui.wins[wind].w
termbox.SetCell(wacc, 1, '┬', fg, bg)
for i := 2; i < h-2; i++ {
termbox.SetCell(wacc, i, '│', fg, bg)
}
termbox.SetCell(wacc, h-2, '┴', fg, bg)
}
}
func (ui *ui) draw(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault
@ -579,6 +624,10 @@ func (ui *ui) draw(nav *nav) {
}
}
if gOpts.drawbox {
ui.drawBox(nav)
}
if ui.menuBuf != nil {
lines := strings.Split(ui.menuBuf.String(), "\n")
@ -587,6 +636,10 @@ func (ui *ui) draw(nav *nav) {
ui.menuWin.h = len(lines) - 1
ui.menuWin.y = ui.wins[0].h - ui.menuWin.h
if gOpts.drawbox {
ui.menuWin.y += 2
}
ui.menuWin.printLine(0, 0, termbox.AttrBold, termbox.AttrBold, lines[0])
for i, line := range lines[1:] {
ui.menuWin.printLine(0, i+1, fg, bg, "")