Skip to content

Commit

Permalink
fix panic on resize (regression)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed May 16, 2021
1 parent f0385f8 commit 5c5a66e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions tscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewTerminfoScreenFromTty(tty Tty) (Screen, error) {
}
t.prepareKeys()
t.buildAcsMap()
t.sigwinch = make(chan os.Signal, 10)
t.resizeQ = make(chan bool, 1)
t.fallback = make(map[rune]string)
for k, v := range RuneFallbacks {
t.fallback[k] = v
Expand Down Expand Up @@ -96,7 +96,7 @@ type tScreen struct {
curstyle Style
style Style
evch chan Event
sigwinch chan os.Signal
resizeQ chan bool
quit chan struct{}
keyexist map[Key]bool
keycodes map[string]*tKeyCode
Expand Down Expand Up @@ -937,7 +937,6 @@ func (t *tScreen) HasPendingEvent() bool {
return len(t.evch) > 0
}


// vtACSNames is a map of bytes defined by terminfo that are used in
// the terminals Alternate Character Set to represent other glyphs.
// For example, the upper left corner of the box drawing set can be
Expand Down Expand Up @@ -1451,7 +1450,7 @@ func (t *tScreen) mainLoop(stopQ chan struct{}) {
return
case <-t.quit:
return
case <-t.sigwinch:
case <-t.resizeQ:
t.Lock()
t.cx = -1
t.cy = -1
Expand Down Expand Up @@ -1607,6 +1606,12 @@ func (t *tScreen) engage() error {
if t.tty == nil {
return ErrNoScreen
}
t.tty.NotifyResize(func() {
select {
case t.resizeQ <- true:
default:
}
})
if t.running {
return errors.New("already engaged")
}
Expand Down Expand Up @@ -1652,6 +1657,7 @@ func (t *tScreen) disengage() {
_ = t.tty.Drain()
t.Unlock()

t.tty.NotifyResize(nil)
// wait for everything to shut down
t.wg.Wait()

Expand Down
4 changes: 3 additions & 1 deletion tty_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func (tty *devTty) Start() error {
tty.l.Lock()
cb := tty.cb
tty.l.Unlock()
cb()
if cb != nil {
cb()
}
case <-stopQ:
return
}
Expand Down

0 comments on commit 5c5a66e

Please sign in to comment.