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

@@ -3,7 +3,7 @@ module examples
go 1.13
require (
github.com/charmbracelet/bubbles v0.7.1
github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c
github.com/charmbracelet/bubbletea v0.12.1
github.com/charmbracelet/glamour v0.2.0
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776

View File

@@ -9,8 +9,8 @@ github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkx
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/charmbracelet/bubbles v0.7.1 h1:qvXoIh7ItTA+IA+IO2xxuI9ntp+uVprDAK+IoMzC5OI=
github.com/charmbracelet/bubbles v0.7.1/go.mod h1:UV3dot0XR45cnQX2d8gtohfUFMepquRG2WE56LPKWNc=
github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c h1:sXhe4YmFER1XE+Xl4z5aKmxB1vgYFS35rYHl+SdqStw=
github.com/charmbracelet/bubbles v0.7.3-0.20201029012715-9b47f26bdd8c/go.mod h1:UV3dot0XR45cnQX2d8gtohfUFMepquRG2WE56LPKWNc=
github.com/charmbracelet/glamour v0.2.0 h1:mTgaiNiumpqTZp3qVM6DH9UB0NlbY17wejoMf1kM8Pg=
github.com/charmbracelet/glamour v0.2.0/go.mod h1:UA27Kwj3QHialP74iU6C+Gpc8Y7IOAKupeKMLLBURWM=
github.com/containerd/console v1.0.1 h1:u7SFAJyRqWcG6ogaMAx3KjSTy1e3hT9QxqX7Jco7dRc=

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"
}

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"os"
"github.com/charmbracelet/bubbles/textinput"
input "github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
te "github.com/muesli/termenv"
@@ -32,38 +33,36 @@ func main() {
type model struct {
index int
nameInput input.Model
nickNameInput input.Model
emailInput input.Model
passwordInput input.Model
submitButton string
}
func initialModel() model {
name := input.NewModel()
name.Placeholder = "Name"
name.Placeholder = "Nickname"
name.Focus()
name.Prompt = focusedPrompt
name.TextColor = focusedTextColor
name.CharLimit = 32
nickName := input.NewModel()
nickName.Placeholder = "Nickname"
nickName.Prompt = blurredPrompt
nickName.CharLimit = 32
email := input.NewModel()
email.Placeholder = "Email"
email.Prompt = blurredPrompt
email.CharLimit = 64
return model{0, name, nickName, email, blurredSubmitButton}
password := input.NewModel()
password.Placeholder = "Password"
password.Prompt = blurredPrompt
password.EchoMode = textinput.EchoPassword
password.EchoCharacter = '•'
password.CharLimit = 32
return model{0, name, email, password, blurredSubmitButton}
}
func (m model) Init() tea.Cmd {
return tea.Batch(
input.Blink(m.nameInput),
input.Blink(m.nickNameInput),
input.Blink(m.emailInput),
)
return textinput.Blink
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -81,8 +80,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
inputs := []input.Model{
m.nameInput,
m.nickNameInput,
m.emailInput,
m.passwordInput,
}
s := msg.String()
@@ -121,8 +120,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
m.nameInput = inputs[0]
m.nickNameInput = inputs[1]
m.emailInput = inputs[2]
m.emailInput = inputs[1]
m.passwordInput = inputs[2]
if m.index == len(inputs) {
m.submitButton = focusedSubmitButton
@@ -148,13 +147,13 @@ func updateInputs(msg tea.Msg, m model) (model, tea.Cmd) {
cmds []tea.Cmd
)
m.nameInput, cmd = input.Update(msg, m.nameInput)
m.nameInput, cmd = m.nameInput.Update(msg)
cmds = append(cmds, cmd)
m.nickNameInput, cmd = input.Update(msg, m.nickNameInput)
m.emailInput, cmd = m.emailInput.Update(msg)
cmds = append(cmds, cmd)
m.emailInput, cmd = input.Update(msg, m.emailInput)
m.passwordInput, cmd = m.passwordInput.Update(msg)
cmds = append(cmds, cmd)
return m, tea.Batch(cmds...)
@@ -164,9 +163,9 @@ func (m model) View() string {
s := "\n"
inputs := []string{
input.View(m.nameInput),
input.View(m.nickNameInput),
input.View(m.emailInput),
m.nameInput.View(),
m.emailInput.View(),
m.passwordInput.View(),
}
for i := 0; i < len(inputs); i++ {