Files
bubbletea/signals_unix.go
Tobias Klauser 295f7bd246 Use golang.org/x/term
The golang.org/x/crypto/ssh/terminal package is deprecated and merely a
wrapper around golang.org/x/term. Use the latter directly and avoid the
dependency on the former altogether.
2021-04-29 15:05:50 +02:00

28 lines
579 B
Go

// +build darwin dragonfly freebsd linux netbsd openbsd solaris
package tea
import (
"os"
"os/signal"
"syscall"
"golang.org/x/term"
)
// 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) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGWINCH)
for {
<-sig
w, h, err := term.GetSize(int(output.Fd()))
if err != nil {
errs <- err
}
msgs <- WindowSizeMsg{w, h}
}
}