Update textinputs for next Bubbles release

This commit is contained in:
Christian Rocha
2020-10-26 21:20:28 -04:00
committed by Christian Rocha
parent 30e88cb04e
commit 1e0283511e
4 changed files with 31 additions and 29 deletions

View File

@@ -7,11 +7,13 @@ import (
"fmt"
"log"
"github.com/charmbracelet/bubbles/textinput"
input "github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)
func main() {
tea.LogToFile("debug.log", "input")
p := tea.NewProgram(initialModel())
if err := p.Start(); err != nil {
@@ -31,7 +33,8 @@ func initialModel() model {
inputModel := input.NewModel()
inputModel.Placeholder = "Pikachu"
inputModel.Focus()
inputModel.CharLimit = 20
inputModel.CharLimit = 156
inputModel.Width = 20
return model{
textInput: inputModel,
@@ -40,7 +43,7 @@ func initialModel() model {
}
func (m model) Init() tea.Cmd {
return input.Blink(m.textInput)
return textinput.Blink
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -63,14 +66,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
m.textInput, cmd = input.Update(msg, m.textInput)
m.textInput, cmd = m.textInput.Update(msg)
return m, cmd
}
func (m model) View() string {
return fmt.Sprintf(
"Whats your favorite Pokémon?\n\n%s\n\n%s",
input.View(m.textInput),
m.textInput.View(),
"(esc to quit)",
) + "\n"
}