handle resize events properly
This commit is contained in:
parent
ad4fc51805
commit
d608eb4a56
2
app.go
2
app.go
@ -191,7 +191,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
|
|
||||||
app.ui.pause()
|
app.ui.pause()
|
||||||
defer app.ui.resume()
|
defer app.ui.resume()
|
||||||
defer app.nav.renew(app.ui.wins[0].h)
|
defer app.nav.renew()
|
||||||
case "%":
|
case "%":
|
||||||
stdin, err := cmd.StdinPipe()
|
stdin, err := cmd.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -10,6 +10,8 @@ import (
|
|||||||
"github.com/nsf/termbox-go"
|
"github.com/nsf/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
||||||
|
|
||||||
type colorEntry struct {
|
type colorEntry struct {
|
||||||
fg termbox.Attribute
|
fg termbox.Attribute
|
||||||
bg termbox.Attribute
|
bg termbox.Attribute
|
||||||
|
8
eval.go
8
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")
|
app.ui.print("scrolloff: value should be a non-negative number")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
max := app.ui.wins[0].h / 2
|
|
||||||
if n > max {
|
|
||||||
n = max
|
|
||||||
}
|
|
||||||
gOpts.scrolloff = n
|
gOpts.scrolloff = n
|
||||||
case "tabstop":
|
case "tabstop":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
@ -327,7 +323,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.printf("put: %s", err)
|
app.ui.printf("put: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.renew(app.nav.height)
|
app.nav.renew()
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("put: %s", err)
|
app.ui.printf("put: %s", err)
|
||||||
}
|
}
|
||||||
@ -343,7 +339,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
case "redraw":
|
case "redraw":
|
||||||
app.ui.sync()
|
app.ui.sync()
|
||||||
app.ui.renew()
|
app.ui.renew()
|
||||||
app.ui.loadFile(app.nav)
|
app.nav.height = app.ui.wins[0].h
|
||||||
case "reload":
|
case "reload":
|
||||||
app.ui.sync()
|
app.ui.sync()
|
||||||
app.ui.renew()
|
app.ui.renew()
|
||||||
|
9
nav.go
9
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)
|
dir.pos = min(dir.ind, height-edge-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,13 +271,12 @@ func (nav *nav) getDirs(wd string) {
|
|||||||
nav.dirs = dirs
|
nav.dirs = dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) renew(height int) {
|
func (nav *nav) renew() {
|
||||||
nav.dirCache = make(map[string]*dir)
|
nav.dirCache = make(map[string]*dir)
|
||||||
for _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
nav.dirCache[d.path] = d
|
nav.dirCache[d.path] = d
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.height = height
|
|
||||||
for _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
go func(d *dir) {
|
go func(d *dir) {
|
||||||
s, err := os.Stat(d.path)
|
s, err := os.Stat(d.path)
|
||||||
@ -422,7 +421,7 @@ func (nav *nav) up(dist int) {
|
|||||||
dir.ind = max(0, dir.ind)
|
dir.ind = max(0, dir.ind)
|
||||||
|
|
||||||
dir.pos -= dist
|
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)
|
dir.pos = max(dir.pos, edge)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,7 +438,7 @@ func (nav *nav) down(dist int) {
|
|||||||
dir.ind = min(maxind, dir.ind)
|
dir.ind = min(maxind, dir.ind)
|
||||||
|
|
||||||
dir.pos += dist
|
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
|
// 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
|
// in order to stay at the same row as much as possible while up/down
|
||||||
|
7
ui.go
7
ui.go
@ -18,10 +18,7 @@ import (
|
|||||||
"github.com/nsf/termbox-go"
|
"github.com/nsf/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const gEscapeCode = 27
|
||||||
gEscapeCode = 27
|
|
||||||
gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
|
||||||
)
|
|
||||||
|
|
||||||
var gAnsiCodes = map[int]termbox.Attribute{
|
var gAnsiCodes = map[int]termbox.Attribute{
|
||||||
0: termbox.ColorDefault,
|
0: termbox.ColorDefault,
|
||||||
@ -433,7 +430,9 @@ func (ui *ui) renew() {
|
|||||||
wacc += widths[i]
|
wacc += widths[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.promptWin.renew(wtot, 1, 0, 0)
|
||||||
ui.msgWin.renew(wtot, 1, 0, htot-1)
|
ui.msgWin.renew(wtot, 1, 0, htot-1)
|
||||||
|
ui.menuWin.renew(wtot, 1, 0, htot-2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) print(msg string) {
|
func (ui *ui) print(msg string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user