Struggling to resize components within TUI #544
-
I am struggling with resizing. I have read the documentation and looked at examples of how to handle tui-example.movAny help would be greatly appreciated. I have put together a little example of what I am currently experiencing: package main
import (
"log"
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var (
PrimaryColour = lipgloss.Color("#3a1577")
Banner = lipgloss.NewStyle().Background(PrimaryColour).Height(2)
)
type model struct {
width int
text string
}
func (m model) Init() tea.Cmd {
return nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds := make([]tea.Cmd, 0)
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c":
return m, tea.Quit
}
}
return m, tea.Batch(cmds...)
}
func (m model) View() string {
var b strings.Builder
b.WriteString(Banner.Copy().Width(m.width).Render(m.text))
return b.String()
}
func main() {
m := model{
text: "hello!",
}
if err := tea.NewProgram(m, tea.WithAltScreen()).Start(); err != nil {
log.Fatal(err)
}
} I am running this example on a Mac using iTerm2 with fish shell |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Any pointers @muesli @meowgorithm ? Thanks |
Beta Was this translation helpful? Give feedback.
-
This issue comes down to This is non-trivial to solve because we can't prevent iTerm from wrapping these characters: this is happening outside of tea's renderer in the terminal itself. One solution is to fill up the available height with empty lines, but that's a solution that only works in alt-screen. |
Beta Was this translation helpful? Give feedback.
This issue comes down to
lipgloss
filling the available width with spaces, so the background color gets applied. When you resize the terminal, it automatically word-wraps the previous content. It looks like iTerm probably doesn't realize it's wrapping empty cells, while Alacritty does.This is non-trivial to solve because we can't prevent iTerm from wrapping these characters: this is happening outside of tea's renderer in the terminal itself.
One solution is to fill up the available height with empty lines, but that's a solution that only works in alt-screen.