diff --git a/app.go b/app.go index e4982e6..37cff0b 100644 --- a/app.go +++ b/app.go @@ -191,7 +191,7 @@ func (app *app) runShell(s string, args []string, prefix string) { app.ui.pause() defer app.ui.resume() - defer app.nav.renew(app.ui.wins[0].h) + defer app.nav.renew() case "%": stdin, err := cmd.StdinPipe() if err != nil { diff --git a/colors.go b/colors.go index a1db69f..14dfbb7 100644 --- a/colors.go +++ b/colors.go @@ -10,6 +10,8 @@ import ( "github.com/nsf/termbox-go" ) +const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse + type colorEntry struct { fg termbox.Attribute bg termbox.Attribute diff --git a/eval.go b/eval.go index 3536ad2..70ca44d 100644 --- a/eval.go +++ b/eval.go @@ -84,10 +84,6 @@ func (e *setExpr) eval(app *app, args []string) { app.ui.print("scrolloff: value should be a non-negative number") return } - max := app.ui.wins[0].h / 2 - if n > max { - n = max - } gOpts.scrolloff = n case "tabstop": n, err := strconv.Atoi(e.val) @@ -327,7 +323,7 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.printf("put: %s", err) return } - app.nav.renew(app.nav.height) + app.nav.renew() if err := sendRemote("send sync"); err != nil { app.ui.printf("put: %s", err) } @@ -343,7 +339,7 @@ func (e *callExpr) eval(app *app, args []string) { case "redraw": app.ui.sync() app.ui.renew() - app.ui.loadFile(app.nav) + app.nav.height = app.ui.wins[0].h case "reload": app.ui.sync() app.ui.renew() diff --git a/nav.go b/nav.go index 4842ba2..650da57 100644 --- a/nav.go +++ b/nav.go @@ -208,7 +208,7 @@ func (dir *dir) find(name string, height int) { } } - edge := min(gOpts.scrolloff, len(dir.fi)-dir.ind-1) + edge := min(min(height/2, gOpts.scrolloff), len(dir.fi)-dir.ind-1) dir.pos = min(dir.ind, height-edge-1) } @@ -271,13 +271,12 @@ func (nav *nav) getDirs(wd string) { nav.dirs = dirs } -func (nav *nav) renew(height int) { +func (nav *nav) renew() { nav.dirCache = make(map[string]*dir) for _, d := range nav.dirs { nav.dirCache[d.path] = d } - nav.height = height for _, d := range nav.dirs { go func(d *dir) { s, err := os.Stat(d.path) @@ -422,7 +421,7 @@ func (nav *nav) up(dist int) { dir.ind = max(0, dir.ind) dir.pos -= dist - edge := min(gOpts.scrolloff, dir.ind) + edge := min(min(nav.height/2, gOpts.scrolloff), dir.ind) dir.pos = max(dir.pos, edge) } @@ -439,7 +438,7 @@ func (nav *nav) down(dist int) { dir.ind = min(maxind, dir.ind) dir.pos += dist - edge := min(gOpts.scrolloff, maxind-dir.ind) + edge := min(min(nav.height/2, gOpts.scrolloff), maxind-dir.ind) // use a smaller value when the height is even and scrolloff is maxed // in order to stay at the same row as much as possible while up/down diff --git a/ui.go b/ui.go index 5fb2de6..ce94421 100644 --- a/ui.go +++ b/ui.go @@ -18,10 +18,7 @@ import ( "github.com/nsf/termbox-go" ) -const ( - gEscapeCode = 27 - gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse -) +const gEscapeCode = 27 var gAnsiCodes = map[int]termbox.Attribute{ 0: termbox.ColorDefault, @@ -433,7 +430,9 @@ func (ui *ui) renew() { wacc += widths[i] } + ui.promptWin.renew(wtot, 1, 0, 0) ui.msgWin.renew(wtot, 1, 0, htot-1) + ui.menuWin.renew(wtot, 1, 0, htot-2) } func (ui *ui) print(msg string) {