Skip to content

Commit

Permalink
chore: apply ProgramOptions before checking context
Browse files Browse the repository at this point in the history
We don't need to set the background context if an outside context
was supplied.
  • Loading branch information
muesli committed Oct 30, 2022
1 parent 280bc6f commit d1c1b24
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,19 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
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
// 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(p.ctx)

// Apply all options to the program.
for _, opt := range opts {
opt(p)
}

// if no output was set, set it to stdout
if p.output == nil {
p.output = termenv.DefaultOutput()
Expand Down

0 comments on commit d1c1b24

Please sign in to comment.