charmbracelet / bubbletea

A powerful little TUI framework 🏗

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow unmanaged console output

rfc2119 opened this issue · comments

Using bubbletea, I would like to have a progress bar similar to apt's:
apt-progress-bar

Progress bar is updated and the above text does not get cleared. I could not achieve this in bubbletea. The closest attempt I got resulted in an unexpected error (see this cast. the code is a modification of examples/spinners/main.go).

I have also tried using bubbletea.ScrollDown() but it instantly clears the screen. Any ideas ?

This is a good one definitely a feature we’d like to support, however to do so we’ll need to add some additional functionality to both to the renderer as well as probably a special Cmd for unmanaged output.

Anyway, this should be a fun one. We’ll keep this issue updated with progress.

Thanks for your input @meowgorithm ! If there's anything I can help with, please do not hesitate to ask. I will try to help as much as I can

commented

I have a working approach to this. Right now I have it set up as a separate renderer for the sake of simplicity, and because the "AltScreen" mode is incompatible with the "log mode" @rfc2119 proposed, so putting them on the same object would require handling incompatible setup options.

Changes to expose the renderer: #246
The renderer: https://github.com/Adjective-Object/tea_log_renderer/blob/main/tea_log_renderer.go

Happy to PR this in @meowgorithm. If you're ok with this approach, let me know if you'd prefer the to keep the Renderer internal and I can make this a feature flag on the standard renderer.

Thanks for the info (and the PR!), @Adjective-Object. I'm inclined to keep the rendering interface internal for now as it (somewhat intentionally) hasn't been given the attention necessary for a public API. However, at a glance, your implementation seems to make sense.

Would you be interested in submitting a PR against the standard renderer instead? I've been imagining the public interface as a Cmd or two, perhaps something like:

// A command for printing above the output, with a final newline
func Println(...string) Msg

// A command for printing above the output, probably also with a newline (somewhat like log.Print)
func Printf(string, vars ...string) Msg

I'd also probably leave word-wrapping as an exercise for the user, but open to your opinions here.

Let me know what you think!

commented
commented

Is there a convenient place for consumers to get access to the widthe of the terminal for word wrapping themselves? Otherwise it might actually make sense as an option when calling Println / Printf, for ergonomics

Is there a convenient place for consumers to get access to the widthe of the terminal for word wrapping themselves? Otherwise it might actually make sense as an option when calling Println / Printf, for ergonomics

Yep, via a WindowSizeMsg, which is sent to update once on initialization and for window resizes.

What do you think the behaviour of the Println() Cmd should be when in AltScreen mode?

I’d simply not print anything and note in the doc comment that Printf/Println won’t work when the altscreen is active..

Just a note that this is now in master (via #249) and will be available in the next release.