fix(output): reuse termenv output (#715)

If the passed io.Writer is a termenv.Output, use it instead of creating
a new termenv.Output.
This commit is contained in:
Ayman Bagabas 2023-04-26 13:04:14 -07:00 committed by GitHub
parent c56884c0e2
commit 29254a08f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -28,7 +28,11 @@ func WithContext(ctx context.Context) ProgramOption {
// won't need to use this. // won't need to use this.
func WithOutput(output io.Writer) ProgramOption { func WithOutput(output io.Writer) ProgramOption {
return func(p *Program) { 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))
}
} }
} }