handle resize events properly

This commit is contained in:
Gokcehan 2018-04-15 18:18:39 +03:00
parent ad4fc51805
commit d608eb4a56
5 changed files with 12 additions and 16 deletions

2
app.go
View File

@ -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 {

View File

@ -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

View File

@ -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()

9
nav.go
View File

@ -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

7
ui.go
View File

@ -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) {