signals_unix.go

 1//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || aix || zos
 2// +build darwin dragonfly freebsd linux netbsd openbsd solaris aix zos
 3
 4package tea
 5
 6import (
 7	"os"
 8	"os/signal"
 9	"syscall"
10)
11
12// listenForResize sends messages (or errors) when the terminal resizes.
13// Argument output should be the file descriptor for the terminal; usually
14// os.Stdout.
15func (p *Program) listenForResize(done chan struct{}) {
16	sig := make(chan os.Signal, 1)
17	signal.Notify(sig, syscall.SIGWINCH)
18
19	defer func() {
20		signal.Stop(sig)
21		close(done)
22	}()
23
24	for {
25		select {
26		case <-p.ctx.Done():
27			return
28		case <-sig:
29		}
30
31		p.checkResize()
32	}
33}