No results
1
Streaming
Virgil edited this page 2026-02-23 04:54:00 +00:00
Table of Contents
Streaming Text Output
The Stream type renders growing text as tokens arrive, with optional word-wrap. Thread-safe for a single producer goroutine.
Basic Usage
stream := cli.NewStream()
go func() {
for token := range tokens {
stream.Write(token)
}
stream.Done()
}()
stream.Wait()
Word Wrap
stream := cli.NewStream(cli.WithWordWrap(80))
Custom Output
var buf strings.Builder
stream := cli.NewStream(cli.WithStreamOutput(&buf))
// ... write tokens ...
stream.Done()
result := stream.Captured() // or buf.String()
Reading from io.Reader
stream := cli.NewStream(cli.WithWordWrap(120))
err := stream.WriteFrom(resp.Body)
stream.Done()
API
| Method | Description |
|---|---|
NewStream(opts...) |
Create stream with options |
Write(text) |
Append text (thread-safe) |
WriteFrom(r) |
Stream from io.Reader until EOF |
Done() |
Signal completion (adds trailing newline if needed) |
Wait() |
Block until Done is called |
Column() |
Current column position |
Captured() |
Get output as string (when using Builder) |