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:
8
tea.go
8
tea.go
@@ -141,8 +141,14 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
|
||||
msgs: make(chan Msg),
|
||||
}
|
||||
|
||||
// A context can be provided with a ProgramOption, but if none was provided
|
||||
// we'll use the default background context.
|
||||
if p.ctx == nil {
|
||||
p.ctx = context.Background()
|
||||
}
|
||||
|
||||
// Initialize context and teardown channel.
|
||||
p.ctx, p.cancel = context.WithCancel(context.Background())
|
||||
p.ctx, p.cancel = context.WithCancel(p.ctx)
|
||||
|
||||
// Apply all options to the program.
|
||||
for _, opt := range opts {
|
||||
|
||||
Reference in New Issue
Block a user