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

Allow unmanaged console output #179

Closed
rfc2119 opened this issue Dec 31, 2021 · 9 comments
Closed

Allow unmanaged console output #179

rfc2119 opened this issue Dec 31, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@rfc2119
Copy link

rfc2119 commented Dec 31, 2021

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 ?

@meowgorithm meowgorithm added the enhancement New feature or request label Jan 11, 2022
@meowgorithm
Copy link
Member

meowgorithm commented Jan 11, 2022

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.

@rfc2119
Copy link
Author

rfc2119 commented Jan 11, 2022

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

@Adjective-Object
Copy link
Contributor

Adjective-Object commented Feb 27, 2022

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.

@meowgorithm
Copy link
Member

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!

@Adjective-Object
Copy link
Contributor

Adjective-Object commented Feb 28, 2022 via email

@Adjective-Object
Copy link
Contributor

Adjective-Object commented Feb 28, 2022

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

@meowgorithm
Copy link
Member

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.

@meowgorithm
Copy link
Member

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..

@meowgorithm meowgorithm changed the title Allow unmanaged console output beside bubbletea's Allow unmanaged console output Mar 26, 2022
@meowgorithm
Copy link
Member

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

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

3 participants