mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
feat: tea.WithContext ProgramOption to supply a context
WithContext lets you specify a context in which to run the Program. This is useful if you want to cancel the execution from outside. When a Program gets cancelled it will exit with an error ErrProgramKilled.
This commit is contained in:
10
options.go
10
options.go
@@ -1,6 +1,7 @@
|
||||
package tea
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/muesli/termenv"
|
||||
@@ -14,6 +15,15 @@ import (
|
||||
// p := NewProgram(model, WithInput(someInput), WithOutput(someOutput))
|
||||
type ProgramOption func(*Program)
|
||||
|
||||
// WithContext lets you specify a context in which to run the Program. This is
|
||||
// useful if you want to cancel the execution from outside. When a Program gets
|
||||
// cancelled it will exit with an error ErrProgramKilled.
|
||||
func WithContext(ctx context.Context) ProgramOption {
|
||||
return func(p *Program) {
|
||||
p.ctx = ctx
|
||||
}
|
||||
}
|
||||
|
||||
// WithOutput sets the output which, by default, is stdout. In most cases you
|
||||
// won't need to use this.
|
||||
func WithOutput(output io.Writer) ProgramOption {
|
||||
|
||||
Reference in New Issue
Block a user