2020-06-17 12:27:16 -04:00
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
|
|
|
|
|
|
|
package tea
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2021-04-29 08:24:25 -04:00
|
|
|
"golang.org/x/term"
|
2020-06-17 12:27:16 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// listenForResize sends messages (or errors) when the terminal resizes.
|
|
|
|
// Argument output should be the file descriptor for the terminal; usually
|
|
|
|
// os.Stdout.
|
|
|
|
func listenForResize(output *os.File, msgs chan Msg, errs chan error) {
|
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)
|
|
|
|
for {
|
|
|
|
<-sig
|
2021-04-29 08:24:25 -04:00
|
|
|
w, h, err := term.GetSize(int(output.Fd()))
|
2020-06-17 12:27:16 -04:00
|
|
|
if err != nil {
|
|
|
|
errs <- err
|
|
|
|
}
|
|
|
|
msgs <- WindowSizeMsg{w, h}
|
|
|
|
}
|
|
|
|
}
|