Open
Description
Is your feature request related to a problem? Please describe.
Unix commands are designed to be chained in pipes, but since bubbletea currently takes over stdout
, this setup requires special configuration at the moment.
Describe the solution you'd like
stderr
tends to be connected to the terminal even when pipes are used, so we can take advantage of this by having bubbletea take over that instead:
diff --git a/tea.go b/tea.go
index 743a866..4aa0497 100644
--- a/tea.go
+++ b/tea.go
@@ -245,11 +245,11 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
// Initialize context and teardown channel.
p.ctx, p.cancel = context.WithCancel(p.ctx)
// if no output was set, set it to stdout
if p.output == nil {
- p.output = os.Stdout
+ p.output = os.Stderr
}
// if no environment was set, set it to os.Environ()
if p.environ == nil {
p.environ = os.Environ()
diff --git a/renderer.go b/renderer.go
index 233aa7c..ef28eb3 100644
--- a/renderer.go
+++ b/renderer.go
@@ -1,18 +1,19 @@
package lipgloss
import (
"io"
+ "os"
"sync"
"github.com/muesli/termenv"
)
// We're manually creating the struct here to avoid initializing the output and
// query the terminal multiple times.
var renderer = &Renderer{
- output: termenv.DefaultOutput(),
+ output: termenv.NewOutput(os.Stderr),
}
// Renderer is a lipgloss terminal renderer.
type Renderer struct {
output *termenv.Output
Describe alternatives you've considered
- This is an easier-to-implement alternative to Automatically open terminal when Stdout is not a terminal #860