2022-07-29 09:21:27 -04:00
|
|
|
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || aix
|
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris aix
|
2020-06-17 12:27:16 -04:00
|
|
|
|
|
|
|
package tea
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// listenForResize sends messages (or errors) when the terminal resizes.
|
|
|
|
// Argument output should be the file descriptor for the terminal; usually
|
|
|
|
// os.Stdout.
|
2022-10-14 22:50:01 -04:00
|
|
|
func (p *Program) listenForResize(done chan struct{}) {
|
2020-08-19 17:59:12 -04:00
|
|
|
sig := make(chan os.Signal, 1)
|
2020-06-17 12:27:16 -04:00
|
|
|
signal.Notify(sig, syscall.SIGWINCH)
|
2021-09-28 13:30:11 -04:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
signal.Stop(sig)
|
|
|
|
close(done)
|
|
|
|
}()
|
|
|
|
|
2020-06-17 12:27:16 -04:00
|
|
|
for {
|
2021-09-28 13:30:11 -04:00
|
|
|
select {
|
2022-10-14 22:50:01 -04:00
|
|
|
case <-p.ctx.Done():
|
2021-09-28 13:30:11 -04:00
|
|
|
return
|
|
|
|
case <-sig:
|
|
|
|
}
|
|
|
|
|
2022-10-14 22:50:01 -04:00
|
|
|
p.checkResize()
|
2020-06-17 12:27:16 -04:00
|
|
|
}
|
|
|
|
}
|