MCPcopy Create free account
hub / github.com/charmbracelet/bubbletea / readLoop

Method readLoop

tty.go:103–113  ·  view source on GitHub ↗

readLoop streams input events to the program until ctx is done or reading fails. It takes the per-run state it uses as arguments rather than reading it from p: the loop can outlive [Program.shutdown], see [Program.shutdownInput], and must not race with a later run replacing it.

(ctx context.Context, scanner *uv.TerminalReader, done chan struct{}, errs chan error)

Source from the content-addressed store, hash-verified

101// it from p: the loop can outlive [Program.shutdown], see
102// [Program.shutdownInput], and must not race with a later run replacing it.
103func (p *Program) readLoop(ctx context.Context, scanner *uv.TerminalReader, done chan struct{}, errs chan error) {
104 defer close(done)
105
106 if err := scanner.StreamEvents(ctx, p.msgs); err != nil {
107 select {
108 case <-ctx.Done():
109 return
110 case errs <- err:
111 }
112 }
113}
114
115const inputReadLoopTimeout = 500 * time.Millisecond
116

Callers 1

initInputReaderMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected