From 8eb9055622786ce9d803da3e2206991090674258 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sun, 15 Apr 2018 19:26:51 +0300 Subject: [PATCH] add 'drawbox' option to draw box around windows --- comp.go | 3 +++ doc.go | 1 + docstring.go | 1 + eval.go | 12 ++++++++++ opts.go | 2 ++ ui.go | 63 +++++++++++++++++++++++++++++++++++++++++++++++----- 6 files changed, 77 insertions(+), 5 deletions(-) diff --git a/comp.go b/comp.go index 66abaf2..c13ad76 100644 --- a/comp.go +++ b/comp.go @@ -58,6 +58,9 @@ var ( "dirfirst", "nodirfirst", "dirfirst!", + "drawbox", + "nodrawbox", + "drawbox!", "globsearch", "noglobsearch", "globsearch!", diff --git a/doc.go b/doc.go index 04c6e63..dc75943 100644 --- a/doc.go +++ b/doc.go @@ -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) diff --git a/docstring.go b/docstring.go index 7c12645..55666c2 100644 --- a/docstring.go +++ b/docstring.go @@ -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) diff --git a/eval.go b/eval.go index 70ca44d..790bda1 100644 --- a/eval.go +++ b/eval.go @@ -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": diff --git a/opts.go b/opts.go index b2892e9..d6cbbc2 100644 --- a/opts.go +++ b/opts.go @@ -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 diff --git a/ui.go b/ui.go index ce94421..18043cd 100644 --- a/ui.go +++ b/ui.go @@ -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, "")