charmbracelet / charmbracelet/bubbletea
v2: Consider erroring or warning when trying to print on the scrollback buffer while AltScreen is enabled
- Dominant language
- Go
- Stars
- 44.9k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Take this snippet as an example:
```go
package main
import (
tea "github.com/charmbracelet/bubbletea/v2"
)
type model struct{}
func (m model) Init() tea.Cmd {
return nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "q":
return m, tea.Quit
default:
return m, tea.Printf("Key pressed: %s", msg.String())
}
}
return m, nil
}
func (m model) View() string {
return `Logging stuff. Press "q" to exit.`
}
func main() {
p := tea.NewProgram(model{}, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
panic(err)
}
}
```
Because we're using `tea.WithAltScreen()`, the `tea.Printf` instructions are no-op and are not been print at all. Because these are used for debugging, the user may believe that some other feature is not working while it's actually just the debugging logs not being print due to AltScreen.
Before releasing v2 for real, we may consider adding some errors or warning somehow if `tea.Printf` is used together with `tea.WithAltScreen()`. Even a `panic` can be considered, but perhaps that's a bit too drastic?
Below, I'll paste the code paths until a `return` is reached, preventing the print:
https://github.com/charmbracelet/bubbletea/blob/7858a14b45ccb0561a6421c739147c817fe5d029/tea.go#L739-L740
https://github.com/charmbracelet/bubbletea/blob/7858a14b45ccb0561a6421c739147c817fe5d029/cursed_renderer.go#L219
https://github.com/charmbracelet/x/blob/92fd130481998d7760473ae5b14c1a9bc90b9df3/cellbuf/screen.go#L1449-L1451
/cc @aymanbagabas
Contributor guide
Research direction
Start by tracing the tea.Printf path in tea.go through cursed_renderer.go and the linked cellbuf screen code. Review how AltScreen causes the print request to return, then determine and document the chosen warning or error behavior. Done means attempts to print with AltScreen enabled no longer fail silently, with coverage added where the relevant project tests belong.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100