forked from Mirrors/bubbletea
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:
parent
c56884c0e2
commit
29254a08f1
|
@ -28,9 +28,13 @@ 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) {
|
||||||
|
if o, ok := output.(*termenv.Output); ok {
|
||||||
|
p.output = o
|
||||||
|
} else {
|
||||||
p.output = termenv.NewOutput(output, termenv.WithColorCache(true))
|
p.output = termenv.NewOutput(output, termenv.WithColorCache(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithInput sets the input which, by default, is stdin. In most cases you
|
// WithInput sets the input which, by default, is stdin. In most cases you
|
||||||
// won't need to use this.
|
// won't need to use this.
|
||||||
|
|
Loading…
Reference in New Issue