From 29254a08f1458a1ba43db4d2b902982f10758c71 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 26 Apr 2023 13:04:14 -0700 Subject: [PATCH] fix(output): reuse termenv output (#715) If the passed io.Writer is a termenv.Output, use it instead of creating a new termenv.Output. --- options.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/options.go b/options.go index 17d05ba..a060722 100644 --- a/options.go +++ b/options.go @@ -28,7 +28,11 @@ func WithContext(ctx context.Context) ProgramOption { // won't need to use this. func WithOutput(output io.Writer) ProgramOption { return func(p *Program) { - p.output = termenv.NewOutput(output, termenv.WithColorCache(true)) + if o, ok := output.(*termenv.Output); ok { + p.output = o + } else { + p.output = termenv.NewOutput(output, termenv.WithColorCache(true)) + } } }