Skip to content
Myr

Update textinputs for next Bubbles release

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent 30e88cb · Browse files · 4 files+31 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+31 added−29 removed

  • other:+31 added−29 removed

4 files+31 added−29 removed

modified:examples/textinput/main.go+7 added-4 removed
5 unmodified lines
6import (7 "fmt"8 "log"910 "github.com/charmbracelet/bubbles/textinput"11 input "github.com/charmbracelet/bubbles/textinput"12 tea "github.com/charmbracelet/bubbletea"13)1415func main() {16 tea.LogToFile("debug.log", "input")17 p := tea.NewProgram(initialModel())1819 if err := p.Start(); err != nil {20 log.Fatal(err)
11 unmodified lines
32func initialModel() model {33 inputModel := input.NewModel()34 inputModel.Placeholder = "Pikachu"35 inputModel.Focus()34 inputModel.CharLimit = 2036 inputModel.CharLimit = 15637 inputModel.Width = 203839 return model{40 textInput: inputModel,41 err: nil,42 }43}4445func (m model) Init() tea.Cmd {43 return input.Blink(m.textInput)46 return textinput.Blink47}4849func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {50 var cmd tea.Cmd
14 unmodified lines
65 m.err = msg66 return m, nil67 }6866 m.textInput, cmd = input.Update(msg, m.textInput)69 m.textInput, cmd = m.textInput.Update(msg)70 return m, cmd71}7273func (m model) View() string {74 return fmt.Sprintf(75 "What’s your favorite Pokémon?\n\n%s\n\n%s",73 input.View(m.textInput),76 m.textInput.View(),77 "(esc to quit)",78 ) + "\n"79}
modified:examples/textinputs/main.go+21 added-22 removed
5 unmodified lines
6import (7 "fmt"8 "os"910 "github.com/charmbracelet/bubbles/textinput"11 input "github.com/charmbracelet/bubbles/textinput"12 tea "github.com/charmbracelet/bubbletea"13 te "github.com/muesli/termenv"14)
17 unmodified lines
3233type model struct {34 index int35 nameInput input.Model35 nickNameInput input.Model36 emailInput input.Model37 passwordInput input.Model38 submitButton string39}4041func initialModel() model {42 name := input.NewModel()42 name.Placeholder = "Name"43 name.Placeholder = "Nickname"44 name.Focus()45 name.Prompt = focusedPrompt46 name.TextColor = focusedTextColor47 name.CharLimit = 324848 nickName := input.NewModel()49 nickName.Placeholder = "Nickname"50 nickName.Prompt = blurredPrompt51 nickName.CharLimit = 325249 email := input.NewModel()50 email.Placeholder = "Email"51 email.Prompt = blurredPrompt52 email.CharLimit = 645358 return model{0, name, nickName, email, blurredSubmitButton}54 password := input.NewModel()55 password.Placeholder = "Password"56 password.Prompt = blurredPrompt57 password.EchoMode = textinput.EchoPassword58 password.EchoCharacter = '•'59 password.CharLimit = 326061 return model{0, name, email, password, blurredSubmitButton}6263}64func (m model) Init() tea.Cmd {62 return tea.Batch(63 input.Blink(m.nameInput),64 input.Blink(m.nickNameInput),65 input.Blink(m.emailInput),66 )65 return textinput.Blink66}6768func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {69 var cmd tea.Cmd
9 unmodified lines
79 case "tab", "shift+tab", "enter", "up", "down":8081 inputs := []input.Model{82 m.nameInput,84 m.nickNameInput,83 m.emailInput,84 m.passwordInput,85 }8687 s := msg.String()88
30 unmodified lines
119 inputs[i].TextColor = ""120 }121122 m.nameInput = inputs[0]124 m.nickNameInput = inputs[1]125 m.emailInput = inputs[2]123 m.emailInput = inputs[1]124 m.passwordInput = inputs[2]125126 if m.index == len(inputs) {127 m.submitButton = focusedSubmitButton128 } else {
17 unmodified lines
146 cmd tea.Cmd147 cmds []tea.Cmd148 )149151 m.nameInput, cmd = input.Update(msg, m.nameInput)150 m.nameInput, cmd = m.nameInput.Update(msg)151 cmds = append(cmds, cmd)152154 m.nickNameInput, cmd = input.Update(msg, m.nickNameInput)153 m.emailInput, cmd = m.emailInput.Update(msg)154 cmds = append(cmds, cmd)155157 m.emailInput, cmd = input.Update(msg, m.emailInput)156 m.passwordInput, cmd = m.passwordInput.Update(msg)157 cmds = append(cmds, cmd)158159 return m, tea.Batch(cmds...)160}
1 unmodified line
162func (m model) View() string {163 s := "\n"164165 inputs := []string{167 input.View(m.nameInput),168 input.View(m.nickNameInput),169 input.View(m.emailInput),166 m.nameInput.View(),167 m.emailInput.View(),168 m.passwordInput.View(),169 }170171 for i := 0; i < len(inputs); i++ {172 s += inputs[i]
8 unmodified lines
modified:examples/go.mod+1 added-1 removed
1 unmodified line
23go 1.1345require (6 github.com/charmbracelet/bubbles v0.7.16 github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c7 github.com/charmbracelet/bubbletea v0.12.18 github.com/charmbracelet/glamour v0.2.09 github.com/fogleman/ease v0.0.0-20170301025033-8da417bf177610 github.com/lucasb-eyer/go-colorful v1.0.3
7 unmodified lines
modified:examples/go.sum+2 added-2 removed
7 unmodified lines
8github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=9github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=10github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=11github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=12github.com/charmbracelet/bubbles v0.7.1 h1:qvXoIh7ItTA+IA+IO2xxuI9ntp+uVprDAK+IoMzC5OI=13github.com/charmbracelet/bubbles v0.7.1/go.mod h1:UV3dot0XR45cnQX2d8gtohfUFMepquRG2WE56LPKWNc=12github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c h1:sXhe4YmFER1XE+Xl4z5aKmxB1vgYFS35rYHl+SdqStw=13github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c/go.mod h1:UV3dot0XR45cnQX2d8gtohfUFMepquRG2WE56LPKWNc=14github.com/charmbracelet/glamour v0.2.0 h1:mTgaiNiumpqTZp3qVM6DH9UB0NlbY17wejoMf1kM8Pg=15github.com/charmbracelet/glamour v0.2.0/go.mod h1:UA27Kwj3QHialP74iU6C+Gpc8Y7IOAKupeKMLLBURWM=16github.com/containerd/console v1.0.1 h1:u7SFAJyRqWcG6ogaMAx3KjSTy1e3hT9QxqX7Jco7dRc=17github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw=
66 unmodified lines