winch.go

 1package uv
 2
 3import (
 4	"context"
 5	"fmt"
 6
 7	"github.com/charmbracelet/x/term"
 8)
 9
10// WinChReceiver listens for window size changes using (SIGWINCH) and sends the
11// new size to the event channel.
12// This is a Unix-specific implementation and should be used on Unix-like
13// systems and won't work on Windows.
14type WinChReceiver struct{ term.File }
15
16// Start starts the receiver.
17func (l *WinChReceiver) Start() error {
18	if l.File == nil {
19		return fmt.Errorf("no file set")
20	}
21	_, _, err := term.GetSize(l.File.Fd())
22	return err
23}
24
25// ReceiveEvents listens for window size changes and sends the new size to the
26// event channel. It stops when the context is done or an error occurs.
27func (l *WinChReceiver) ReceiveEvents(ctx context.Context, evch chan<- Event) error {
28	return l.receiveEvents(ctx, l.File, evch)
29}