Can't redirect output of non-interactive application #663
-
I use bubbletea for the sole purpose of generating and printing a table in my application. So no interactive features there (until now!). I expected, that I could perform a benchmark-measurement with hyperfine, however it seems like execution is blocked in this case, because hyperfine redirects stdout and stderr. Sure enough, if I redirect the output of my program to Is this something I can solve by writing my application in a different way? Is this a bug with bubbletea? |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments
-
@tim-hilt This doesn’t exactly answer your question, but Bubble Tea is a bit overkill for rendering a static table. What we should really do here is move the rendering portion to Lip Gloss, the style and layout library. |
Beta Was this translation helpful? Give feedback.
-
It’s overkill at the moment, but I might expand on bubbletea in the future. So you don’t have an idea of why that happens? |
Beta Was this translation helpful? Give feedback.
-
Hey @tim-hilt we implemented a This is a working example, but it works with hyperfine x Bubble Tea https://gist.github.com/bashbunni/f79665e45e3ace35b344cbd6bd2442dd of course it's not perfect, but the functionality you're looking for is working here. Just did the minimal edits required from the example above |
Beta Was this translation helpful? Give feedback.
-
Hey @bashbunni and thanks for your response. I think what I’m looking for got lost in translation. I have a bubbletea application that has no interactive elements. It‘s only there to print a table. I would want to time how long it takes to run the command to completion. You can see how I start the bubbletea process here: https://github.com/tim-hilt/tempo/blob/main/cli/tablecomponent/tablecomponent.go#L42 |
Beta Was this translation helpful? Give feedback.
-
Hey @tim-hilt, haha no problem. I'm not really understanding what you're trying to do. You've got a table being output... Are you trying to count how long it takes for the bubble tea program to start up or the duration of some other terminal command that gets triggered by some keypress after the table prints? |
Beta Was this translation helpful? Give feedback.
-
@bashbunni I implemented a minimal reproducable example. To run it enter the following: git clone [email protected]:tim-hilt/bubbletea-redirection-showcasing.git && cd bubbletea-redirection-showcasing && go mod download && go run main.go you should see the table printed to the screen. The command exits afterwards. Now try again with go run main.go > /dev/null you should see the command blocking forever, which is not what I'd expect. I'd expect the program to run without output and exit afterwards. |
Beta Was this translation helpful? Give feedback.
-
Don't use |
Beta Was this translation helpful? Give feedback.
-
Ok, then try the following: go build && ./bubbletea-redirection-showcasing > /dev/null it blocks for me. |
Beta Was this translation helpful? Give feedback.
-
Hey @tim-hilt, I think what's happening here is your Normally, there's always one message for Changing the |
Beta Was this translation helpful? Give feedback.
-
@mcastorina We typically do a final render before quitting. It would also do a render before executing the commands you provide. That's why in this case it would be rendering twice total |
Beta Was this translation helpful? Give feedback.
Hey @tim-hilt, I think what's happening here is your
Update
method is used to signal bubbletea to quit. You'll notice if you hit a key the program will exit.Normally, there's always one message for
Update
on initialization to provide information on the screen size, but since we redirect I think that event isn't happening.Changing the
Init()
method to returntea.Quit
seems to work, though idk why it's still able to display the table when not redirecting. It seemsView()
is called at least once before exitting. By my crude testing, it's called twice with this solution.