mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
Based on @knz's work in #499, but slightly supersedes this change. A little more coupling in the resize handling, but a lot less code & logic repetition. Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net>
34 lines
651 B
Go
34 lines
651 B
Go
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || aix
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris aix
|
|
|
|
package tea
|
|
|
|
import (
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
// listenForResize sends messages (or errors) when the terminal resizes.
|
|
// Argument output should be the file descriptor for the terminal; usually
|
|
// os.Stdout.
|
|
func (p *Program) listenForResize(done chan struct{}) {
|
|
sig := make(chan os.Signal, 1)
|
|
signal.Notify(sig, syscall.SIGWINCH)
|
|
|
|
defer func() {
|
|
signal.Stop(sig)
|
|
close(done)
|
|
}()
|
|
|
|
for {
|
|
select {
|
|
case <-p.ctx.Done():
|
|
return
|
|
case <-sig:
|
|
}
|
|
|
|
p.checkResize()
|
|
}
|
|
}
|