Disable resize listening on windows since it's not supported

This commit is contained in:
Christian Rocha 2020-06-17 12:27:16 -04:00
parent a152cce4b6
commit debaf312f7
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
3 changed files with 37 additions and 14 deletions

27
signals_unix.go Normal file
View File

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

9
signals_windows.go Normal file
View File

@ -0,0 +1,9 @@
// +build windows
package tea
import "os"
// listenForResize is not available on windows because windows does not
// implement syscall.SIGWINCH.
func listenForResize(output *os.File, msgs chan Msg, errs chan error) {}

15
tea.go
View File

@ -2,8 +2,6 @@ package tea
import (
"os"
"os/signal"
"syscall"
"github.com/muesli/termenv"
"golang.org/x/crypto/ssh/terminal"
@ -132,18 +130,7 @@ func (p *Program) Start() error {
}()
// Listen for window resizes
go func() {
sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGWINCH)
for {
<-sig
w, h, err := terminal.GetSize(int(output.Fd()))
if err != nil {
errs <- err
}
msgs <- WindowSizeMsg{w, h}
}
}()
go listenForResize(output, msgs, errs)
// Process commands
go func() {