charmbracelet / bubbletea

A powerful little TUI framework 🏗
MIT License
27.47k stars 792 forks source link

Force newline after rendering the final View #304

Open erikgeiser opened 2 years ago

erikgeiser commented 2 years ago

If the final call to View() (after emitting tea.Quit) does not end with a newline it is immediately overwritten by the shell prompt or by any other output. This can be a bit surprising and it's hard to debug if you don't know what happens.

It can be avoided by appending a newline to the result of the final call to View() if this result is not empty.

meowgorithm commented 2 years ago

Making this change will slightly alter the final output of some programs, however it will remove a quirk which we've seen confuse new users.

The former behavior can basically be recreated via some additional logic in View(), which is where such rendering logic should be anyway.


Here are some illustrations of the current behavior:

Normal view. The help text resides on the final line.

[x] UI
[ ] More UI
Some help text

After quit. The developer is exploiting a quirk in which the final view doesn't contain a newline, so the help text prints over it on exit.

[x] UI
[ ] More UI
user@machine:~ $: _
praagyajoshi commented 1 year ago

As a new user, I just got bit by this behaviour! And I have to admit, it really stumped me for quite a few hours where I spent figuring out whether:

I eventually figured out an extra newline was needed and submitted an issue here: https://github.com/charmbracelet/bubbletea/issues/827.

I will definitely recommend updating the default behaviour (to print an extra newline) with an option to turn it off if needed.

virtuallyunknown commented 1 year ago

As a new user, I just got bit by this behaviour! And I have to admit, it really stumped me for quite a few hours where I spent figuring out whether:

As a new user, and new to go in general I also assumed this is a mistake on my end, so same story as you. Would be nice if there was a note about this folks.

CalebJohnHunt commented 8 months ago

Is there still interest in this? I've made a proof of concept, but I'm open to changing the implementation.