Skip to content

Commit

Permalink
docs(examples): update for new Bubbles v2 API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Oct 31, 2024
1 parent 861c0f0 commit e32245e
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/autocomplete/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func initialModel() model {
ti.Cursor.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))
ti.Focus()
ti.CharLimit = 50
ti.Width = 20
ti.SetWidth(20)
ti.ShowSuggestions = true

h := help.New()
Expand Down
4 changes: 2 additions & 2 deletions examples/chat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func initialModel() model {

ta.ShowLineNumbers = false

vp := viewport.New(30, 5)
vp := viewport.New(viewport.WithWidth(30), viewport.WithHeight(5))
vp.SetContent(`Welcome to the chat room!
Type a message and press Enter to send.`)

Expand All @@ -68,7 +68,7 @@ func (m model) Init() (tea.Model, tea.Cmd) {
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.viewport.Width = msg.Width
m.viewport.SetWidth(msg.Width)
m.textarea.SetWidth(msg.Width)
return m, nil
case tea.KeyPressMsg:
Expand Down
6 changes: 3 additions & 3 deletions examples/credit-card-form/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ func initialModel() model {
inputs[ccn].Placeholder = "4505 **** **** 1234"
inputs[ccn].Focus()
inputs[ccn].CharLimit = 20
inputs[ccn].Width = 30
inputs[ccn].SetWidth(30)
inputs[ccn].Prompt = ""
inputs[ccn].Validate = ccnValidator

inputs[exp] = textinput.New()
inputs[exp].Placeholder = "MM/YY "
inputs[exp].CharLimit = 5
inputs[exp].Width = 5
inputs[exp].SetWidth(5)
inputs[exp].Prompt = ""
inputs[exp].Validate = expValidator

inputs[cvv] = textinput.New()
inputs[cvv].Placeholder = "XXX"
inputs[cvv].CharLimit = 3
inputs[cvv].Width = 5
inputs[cvv].SetWidth(5)
inputs[cvv].Prompt = ""
inputs[cvv].Validate = cvvValidator

Expand Down
9 changes: 7 additions & 2 deletions examples/glamour/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ type example struct {
}

func newExample() (*example, error) {
const width = 78
const (
width = 78
height = 20
)

vp := viewport.New(width, 20)
vp := viewport.New()
vp.SetWidth(width)
vp.SetHeight(height)
vp.Style = lipgloss.NewStyle().
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.Color("62")).
Expand Down
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module examples
go 1.23.1

require (
github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1.0.20241029195424-db64e3cd782c
github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1.0.20241031195835-cc9a7270283d
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1.0.20241024164833-a31857d07198
github.com/charmbracelet/colorprofile v0.1.6
github.com/charmbracelet/glamour v0.8.0
Expand Down
4 changes: 2 additions & 2 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1.0.20241029195424-db64e3cd782c h1:GQXDDexYp4Y0tPLMPT2UCdOvEt1eX125BlU2KaJ+AtA=
github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1.0.20241029195424-db64e3cd782c/go.mod h1:m1OsgLhZIiKx3O0R51XwnXwwm9vP/LFa8IBUMQiiZmw=
github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1.0.20241031195835-cc9a7270283d h1:iXR9lgmZhwy9yrrCmmDv++akjSbZJs4Owzlbfoc9OrQ=
github.com/charmbracelet/bubbles/v2 v2.0.0-alpha.1.0.20241031195835-cc9a7270283d/go.mod h1:m1OsgLhZIiKx3O0R51XwnXwwm9vP/LFa8IBUMQiiZmw=
github.com/charmbracelet/colorprofile v0.1.6 h1:nMMqCns0c0DfCwNGdagBh6SxutFqkltSxxKk5S9kt+Y=
github.com/charmbracelet/colorprofile v0.1.6/go.mod h1:3EMXDxwRDJl0c17eJ1jX99MhtlP9OxE/9Qw0C5lvyUg=
github.com/charmbracelet/glamour v0.8.0 h1:tPrjL3aRcQbn++7t18wOpgLyl8wrOHUEDS7IZ68QtZs=
Expand Down
10 changes: 5 additions & 5 deletions examples/pager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// we can initialize the viewport. The initial dimensions come in
// quickly, though asynchronously, which is why we wait for them
// here.
m.viewport = viewport.New(msg.Width, msg.Height-verticalMarginHeight)
m.viewport = viewport.New(viewport.WithWidth(msg.Width), viewport.WithHeight(msg.Height-verticalMarginHeight))
m.viewport.YPosition = headerHeight
m.viewport.SetContent(m.content)
m.ready = true
} else {
m.viewport.Width = msg.Width
m.viewport.Height = msg.Height - verticalMarginHeight
m.viewport.SetWidth(msg.Width)
m.viewport.SetHeight(msg.Height - verticalMarginHeight)
}
}

Expand All @@ -86,13 +86,13 @@ func (m model) View() string {

func (m model) headerView() string {
title := titleStyle.Render("Mr. Pager")
line := strings.Repeat("─", max(0, m.viewport.Width-lipgloss.Width(title)))
line := strings.Repeat("─", max(0, m.viewport.Width()-lipgloss.Width(title)))
return lipgloss.JoinHorizontal(lipgloss.Center, title, line)
}

func (m model) footerView() string {
info := infoStyle.Render(fmt.Sprintf("%3.f%%", m.viewport.ScrollPercent()*100))
line := strings.Repeat("─", max(0, m.viewport.Width-lipgloss.Width(info)))
line := strings.Repeat("─", max(0, m.viewport.Width()-lipgloss.Width(info)))
return lipgloss.JoinHorizontal(lipgloss.Center, line, info)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/pipe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newModel(initialValue string) (m model) {
i := textinput.New()
i.Prompt = ""
i.Cursor.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))
i.Width = 48
i.SetWidth(48)
i.SetValue(initialValue)
i.CursorEnd()
i.Focus()
Expand Down
6 changes: 3 additions & 3 deletions examples/progress-animated/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit

case tea.WindowSizeMsg:
m.progress.Width = msg.Width - padding*2 - 4
if m.progress.Width > maxWidth {
m.progress.Width = maxWidth
m.progress.SetWidth(msg.Width - padding*2 - 4)
if m.progress.Width() > maxWidth {
m.progress.SetWidth(maxWidth)
}
return m, nil

Expand Down
6 changes: 3 additions & 3 deletions examples/progress-download/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit

case tea.WindowSizeMsg:
m.progress.Width = msg.Width - padding*2 - 4
if m.progress.Width > maxWidth {
m.progress.Width = maxWidth
m.progress.SetWidth(msg.Width - padding*2 - 4)
if m.progress.Width() > maxWidth {
m.progress.SetWidth(maxWidth)
}
return m, nil

Expand Down
6 changes: 3 additions & 3 deletions examples/progress-static/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit

case tea.WindowSizeMsg:
m.progress.Width = msg.Width - padding*2 - 4
if m.progress.Width > maxWidth {
m.progress.Width = maxWidth
m.progress.SetWidth(msg.Width - padding*2 - 4)
if m.progress.Width() > maxWidth {
m.progress.SetWidth(maxWidth)
}
return m, nil

Expand Down
2 changes: 1 addition & 1 deletion examples/query-term/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newModel() model {
ti := textinput.New()
ti.Focus()
ti.CharLimit = 156
ti.Width = 20
ti.SetWidth(20)
return model{input: ti}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/set-terminal-color/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func main() {
ti.Placeholder = "#ff00ff"
ti.Focus()
ti.CharLimit = 156
ti.Width = 20
ti.SetWidth(20)
p := tea.NewProgram(model{
ti: ti,
})
Expand Down
2 changes: 1 addition & 1 deletion examples/stopwatch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

func main() {
m := model{
stopwatch: stopwatch.NewWithInterval(time.Millisecond),
stopwatch: stopwatch.New(stopwatch.WithInterval(time.Millisecond)),
keymap: keymap{
start: key.NewBinding(
key.WithKeys("s"),
Expand Down
2 changes: 1 addition & 1 deletion examples/textinput/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func initialModel() model {
ti.Placeholder = "Pikachu"
ti.Focus()
ti.CharLimit = 156
ti.Width = 20
ti.SetWidth(20)

return model{
textInput: ti,
Expand Down
2 changes: 1 addition & 1 deletion examples/timer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (m model) View() string {

func main() {
m := model{
timer: timer.NewWithInterval(timeout, time.Millisecond),
timer: timer.New(timeout, timer.WithInterval(time.Millisecond)),
keymap: keymap{
start: key.NewBinding(
key.WithKeys("s"),
Expand Down

0 comments on commit e32245e

Please sign in to comment.