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
Provenance
- Commit
1e02835- Tree
a91c1c3- Author
Christian Rocha <christian@rocha.is>- Committer
Christian Rocha <meowgorithm@users.noreply.github.com>- Parent
30e88cb
4 files changed+31 added−29 removed
modified:examples/textinput/main.go+7 added-4 removed
5 unmodified lines6 import (7 "fmt"8 "log"9 10+ "github.com/charmbracelet/bubbles/textinput"11 input "github.com/charmbracelet/bubbles/textinput"12 tea "github.com/charmbracelet/bubbletea"13 )14 15 func main() {16+ tea.LogToFile("debug.log", "input")17 p := tea.NewProgram(initialModel())18 19 if err := p.Start(); err != nil {20 log.Fatal(err)11 unmodified lines32 func initialModel() model {33 inputModel := input.NewModel()34 inputModel.Placeholder = "Pikachu"35 inputModel.Focus()34- inputModel.CharLimit = 2036+ inputModel.CharLimit = 15637+ inputModel.Width = 2038 39 return model{40 textInput: inputModel,41 err: nil,42 }43 }44 45 func (m model) Init() tea.Cmd {43- return input.Blink(m.textInput)46+ return textinput.Blink47 }48 49 func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {50 var cmd tea.Cmd14 unmodified lines65 m.err = msg66 return m, nil67 }68 66- m.textInput, cmd = input.Update(msg, m.textInput)69+ m.textInput, cmd = m.textInput.Update(msg)70 return m, cmd71 }72 73 func (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 lines6 import (7 "fmt"8 "os"9 10+ "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 lines32 33 type model struct {34 index int35 nameInput input.Model35- nickNameInput input.Model36 emailInput input.Model37+ passwordInput input.Model38 submitButton string39 }40 41 func 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 = 3248 48- nickName := input.NewModel()49- nickName.Placeholder = "Nickname"50- nickName.Prompt = blurredPrompt51- nickName.CharLimit = 3252-49 email := input.NewModel()50 email.Placeholder = "Email"51 email.Prompt = blurredPrompt52 email.CharLimit = 6453 58- 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 = 3260 61+ return model{0, name, email, password, blurredSubmitButton}62+63 }64 func (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 }67 68 func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {69 var cmd tea.Cmd9 unmodified lines79 case "tab", "shift+tab", "enter", "up", "down":80 81 inputs := []input.Model{82 m.nameInput,84- m.nickNameInput,83 m.emailInput,84+ m.passwordInput,85 }86 87 s := msg.String()88 30 unmodified lines119 inputs[i].TextColor = ""120 }121 122 m.nameInput = inputs[0]124- m.nickNameInput = inputs[1]125- m.emailInput = inputs[2]123+ m.emailInput = inputs[1]124+ m.passwordInput = inputs[2]125 126 if m.index == len(inputs) {127 m.submitButton = focusedSubmitButton128 } else {17 unmodified lines146 cmd tea.Cmd147 cmds []tea.Cmd148 )149 151- m.nameInput, cmd = input.Update(msg, m.nameInput)150+ m.nameInput, cmd = m.nameInput.Update(msg)151 cmds = append(cmds, cmd)152 154- m.nickNameInput, cmd = input.Update(msg, m.nickNameInput)153+ m.emailInput, cmd = m.emailInput.Update(msg)154 cmds = append(cmds, cmd)155 157- m.emailInput, cmd = input.Update(msg, m.emailInput)156+ m.passwordInput, cmd = m.passwordInput.Update(msg)157 cmds = append(cmds, cmd)158 159 return m, tea.Batch(cmds...)160 }1 unmodified line162 func (m model) View() string {163 s := "\n"164 165 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 }170 171 for i := 0; i < len(inputs); i++ {172 s += inputs[i]8 unmodified linesmodified:examples/go.mod+1 added-1 removed
1 unmodified line2 3 go 1.134 5 require (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.37 unmodified linesmodified:examples/go.sum+2 added-2 removed
7 unmodified lines8 github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=9 github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=10 github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=11 github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=12-github.com/charmbracelet/bubbles v0.7.1 h1:qvXoIh7ItTA+IA+IO2xxuI9ntp+uVprDAK+IoMzC5OI=13-github.com/charmbracelet/bubbles v0.7.1/go.mod h1:UV3dot0XR45cnQX2d8gtohfUFMepquRG2WE56LPKWNc=12+github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c h1:sXhe4YmFER1XE+Xl4z5aKmxB1vgYFS35rYHl+SdqStw=13+github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c/go.mod h1:UV3dot0XR45cnQX2d8gtohfUFMepquRG2WE56LPKWNc=14 github.com/charmbracelet/glamour v0.2.0 h1:mTgaiNiumpqTZp3qVM6DH9UB0NlbY17wejoMf1kM8Pg=15 github.com/charmbracelet/glamour v0.2.0/go.mod h1:UA27Kwj3QHialP74iU6C+Gpc8Y7IOAKupeKMLLBURWM=16 github.com/containerd/console v1.0.1 h1:u7SFAJyRqWcG6ogaMAx3KjSTy1e3hT9QxqX7Jco7dRc=17 github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw=66 unmodified lines