From 4f83c621fb033a4a35838529733cf03add8e514e Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 30 Oct 2022 06:08:36 +0100 Subject: [PATCH] chore: apply ProgramOptions before checking context We don't need to set the background context if an outside context was supplied. --- tea.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tea.go b/tea.go index 6736d6a..4de805e 100644 --- a/tea.go +++ b/tea.go @@ -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()