Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to os.Stderr rather than os.Stdout #1280

Open
myaaaaaaaaa opened this issue Jan 6, 2025 · 0 comments
Open

Default to os.Stderr rather than os.Stdout #1280

myaaaaaaaaa opened this issue Jan 6, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@myaaaaaaaaa
Copy link

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

@myaaaaaaaaa myaaaaaaaaa added the enhancement New feature or request label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant