mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
chore: apply ProgramOptions before checking context
We don't need to set the background context if an outside context was supplied.
This commit is contained in:
11
tea.go
11
tea.go
@@ -141,20 +141,19 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
|
|||||||
msgs: make(chan Msg),
|
msgs: make(chan Msg),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply all options to the program.
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(p)
|
||||||
|
}
|
||||||
|
|
||||||
// A context can be provided with a ProgramOption, but if none was provided
|
// A context can be provided with a ProgramOption, but if none was provided
|
||||||
// we'll use the default background context.
|
// we'll use the default background context.
|
||||||
if p.ctx == nil {
|
if p.ctx == nil {
|
||||||
p.ctx = context.Background()
|
p.ctx = context.Background()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize context and teardown channel.
|
// Initialize context and teardown channel.
|
||||||
p.ctx, p.cancel = context.WithCancel(p.ctx)
|
p.ctx, p.cancel = context.WithCancel(p.ctx)
|
||||||
|
|
||||||
// Apply all options to the program.
|
|
||||||
for _, opt := range opts {
|
|
||||||
opt(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
// if no output was set, set it to stdout
|
// if no output was set, set it to stdout
|
||||||
if p.output == nil {
|
if p.output == nil {
|
||||||
p.output = termenv.DefaultOutput()
|
p.output = termenv.DefaultOutput()
|
||||||
|
|||||||
Reference in New Issue
Block a user