From debaf312f7b9374a7702a8f71ebadd856abf6b8c Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 17 Jun 2020 12:27:16 -0400 Subject: [PATCH] Disable resize listening on windows since it's not supported --- signals_unix.go | 27 +++++++++++++++++++++++++++ signals_windows.go | 9 +++++++++ tea.go | 15 +-------------- 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 signals_unix.go create mode 100644 signals_windows.go diff --git a/signals_unix.go b/signals_unix.go new file mode 100644 index 0000000..5d98b7e --- /dev/null +++ b/signals_unix.go @@ -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} + } +} diff --git a/signals_windows.go b/signals_windows.go new file mode 100644 index 0000000..0f4f3c0 --- /dev/null +++ b/signals_windows.go @@ -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) {} diff --git a/tea.go b/tea.go index 8634b90..0d9e258 100644 --- a/tea.go +++ b/tea.go @@ -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() {