mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
fix: detect terminal size after exec
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>
This commit is contained in:
@@ -4,18 +4,15 @@
|
||||
package tea
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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(ctx context.Context, output *os.File, msgs chan Msg, errs chan error, done chan struct{}) {
|
||||
func (p *Program) listenForResize(done chan struct{}) {
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, syscall.SIGWINCH)
|
||||
|
||||
@@ -26,20 +23,11 @@ func listenForResize(ctx context.Context, output *os.File, msgs chan Msg, errs c
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-p.ctx.Done():
|
||||
return
|
||||
case <-sig:
|
||||
}
|
||||
|
||||
w, h, err := term.GetSize(int(output.Fd()))
|
||||
if err != nil {
|
||||
errs <- err
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case msgs <- WindowSizeMsg{w, h}:
|
||||
}
|
||||
p.checkResize()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user