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", "dirfirst",
"nodirfirst", "nodirfirst",
"dirfirst!", "dirfirst!",
"drawbox",
"nodrawbox",
"drawbox!",
"globsearch", "globsearch",
"noglobsearch", "noglobsearch",
"globsearch!", "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) dircounts boolean (default off)
dirfirst boolean (default on) dirfirst boolean (default on)
drawbox boolean (default off)
globsearch boolean (default off) globsearch boolean (default off)
hidden boolean (default off) hidden boolean (default off)
ignorecase boolean (default on) 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) dircounts boolean (default off)
dirfirst boolean (default on) dirfirst boolean (default on)
drawbox boolean (default off)
globsearch boolean (default off) globsearch boolean (default off)
hidden boolean (default off) hidden boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)

12
eval.go
View File

@ -26,6 +26,18 @@ func (e *setExpr) eval(app *app, args []string) {
case "dirfirst!": case "dirfirst!":
gOpts.dirfirst = !gOpts.dirfirst gOpts.dirfirst = !gOpts.dirfirst
app.nav.sort() 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": case "globsearch":
gOpts.globsearch = true gOpts.globsearch = true
case "noglobsearch": case "noglobsearch":

View File

@ -5,6 +5,7 @@ import "time"
var gOpts struct { var gOpts struct {
dircounts bool dircounts bool
dirfirst bool dirfirst bool
drawbox bool
globsearch bool globsearch bool
hidden bool hidden bool
ignorecase bool ignorecase bool
@ -31,6 +32,7 @@ var gOpts struct {
func init() { func init() {
gOpts.dircounts = false gOpts.dircounts = false
gOpts.dirfirst = true gOpts.dirfirst = true
gOpts.drawbox = false
gOpts.globsearch = false gOpts.globsearch = false
gOpts.hidden = false gOpts.hidden = false
gOpts.ignorecase = true 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 return
} }
maxind := len(dir.fi) - 1
beg := max(dir.ind-dir.pos, 0) 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] { for i, f := range dir.fi[beg:end] {
fg, bg = colors.get(f) fg, bg = colors.get(f)
@ -376,6 +378,10 @@ func getWidths(wtot int) []int {
} }
widths[wlen-1] = wtot - wsum widths[wlen-1] = wtot - wsum
if gOpts.drawbox {
widths[wlen-1]--
}
return widths return widths
} }
@ -389,7 +395,11 @@ func getWins() []*win {
wacc := 0 wacc := 0
wlen := len(widths) wlen := len(widths)
for i := 0; i < wlen; i++ { 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] wacc += widths[i]
} }
@ -426,7 +436,11 @@ func (ui *ui) renew() {
wacc := 0 wacc := 0
wlen := len(widths) wlen := len(widths)
for i := 0; i < wlen; i++ { 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] wacc += widths[i]
} }
@ -529,6 +543,37 @@ func (ui *ui) drawStatLine(nav *nav) {
ui.msgWin.printRight(0, fg, bg, ruler) 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) { func (ui *ui) draw(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault 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 { if ui.menuBuf != nil {
lines := strings.Split(ui.menuBuf.String(), "\n") 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.h = len(lines) - 1
ui.menuWin.y = ui.wins[0].h - ui.menuWin.h 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]) ui.menuWin.printLine(0, 0, termbox.AttrBold, termbox.AttrBold, lines[0])
for i, line := range lines[1:] { for i, line := range lines[1:] {
ui.menuWin.printLine(0, i+1, fg, bg, "") ui.menuWin.printLine(0, i+1, fg, bg, "")