-
Notifications
You must be signed in to change notification settings - Fork 319
Closed
Description
Describe the bug
When I tried the v2 version of BubbleTea and Bubbles, I noticed that the Progress component, and when drawing something wider than 1, it would be like in the video below, but this behaved fine on macOS. And it is also normal under v1 (0.21.0) version.
Setup
Please complete the following information along with version numbers, if applicable.
- OS: Windows 11
- Shell: pwsh
- Terminal Emulator: Terminal
- Terminal Multiplexer: None
- Locale: both en_US.UTF-8 and zh_CN.UTF-8 are tested
- Font: Cascadia Mono
To Reproduce
go run ./v1
go run ./v2
Source Code
v1/main.go
is a copy of https://github.com/charmbracelet/bubbletea/blob/main/examples/progress-animated/main.go
v2/main.go
:
package main
// A simple example that shows how to render an animated progress bar. In this
// example we bump the progress by 25% every two seconds, animating our
// progress bar to its new target state.
//
// It's also possible to render a progress bar in a more static fashion without
// transitions. For details on that approach see the progress-static example.
import (
"fmt"
"os"
"strings"
"time"
"github.com/charmbracelet/bubbles/v2/progress"
tea "github.com/charmbracelet/bubbletea/v2"
"github.com/charmbracelet/lipgloss/v2"
)
const (
padding = 2
maxWidth = 80
)
var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")).Render
func main() {
m := model{
progress: progress.New(progress.WithDefaultGradient()),
}
if _, err := tea.NewProgram(m).Run(); err != nil {
fmt.Println("Oh no!", err)
os.Exit(1)
}
}
type tickMsg time.Time
type model struct {
progress progress.Model
}
func (m model) Init() tea.Cmd {
return tickCmd()
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
return m, tea.Quit
case tea.WindowSizeMsg:
m.progress.SetWidth(msg.Width - padding*2 - 4)
if m.progress.Width() > maxWidth {
m.progress.SetWidth(maxWidth)
}
return m, nil
case tickMsg:
if m.progress.Percent() == 1.0 {
return m, tea.Quit
}
// Note that you can also use progress.Model.SetPercent to set the
// percentage value explicitly, too.
cmd := m.progress.IncrPercent(0.25)
return m, tea.Batch(tickCmd(), cmd)
// FrameMsg is sent when the progress bar wants to animate itself
case progress.FrameMsg:
var cmd tea.Cmd
m.progress, cmd = m.progress.Update(msg)
return m, cmd
default:
return m, nil
}
}
func (m model) View() string {
pad := strings.Repeat(" ", padding)
return "\n" +
pad + m.progress.View() + "\n\n" +
pad + helpStyle("Press any key to quit")
}
func tickCmd() tea.Cmd {
return tea.Tick(time.Second*1, func(t time.Time) tea.Msg {
return tickMsg(t)
})
}
Expected behavior
The component will be rendered properly.
Additional context
None
Metadata
Metadata
Assignees
Labels
No labels