You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all. I'm new to bubble tea and bubbles, and I'm trying to make multiple inputs blink, however I can only make the very first one work. All successive inputs don't have cursor blinking
Here's my code
package main
import (
"fmt"
"log"
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)
func main() {
p := tea.NewProgram(initialModel())
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
}
type (
errMsg error
)
type model struct {
nameInput textinput.Model
noteInput textarea.Model
step int
err error
}
func initialModel() model {
nameInput := textinput.New()
nameInput.Placeholder = "Dwight"
nameInput.Focus()
nameInput.CharLimit = 156
nameInput.Width = 20
noteInput := textarea.New()
noteInput.Placeholder = "Make a note..."
return model{
nameInput: nameInput,
noteInput: noteInput,
err: nil,
step: 1,
}
}
func (m model) Init() tea.Cmd {
return tea.Batch(
textinput.Blink,
textarea.Blink, // Add the blinking command for the textarea
)
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
// QUIT
case tea.KeyCtrlC, tea.KeyEsc:
return m, tea.Quit
// INCREMENT STEP
case tea.KeyEnter:
m.step += 1
return m, nil
}
case errMsg:
m.err = msg
return m, nil
}
switch m.step {
case 1:
m.nameInput, cmd = m.nameInput.Update(msg)
case 2:
m.nameInput.Blur()
m.noteInput.Focus()
m.noteInput, cmd = m.noteInput.Update(msg)
}
return m, cmd
}
func (m model) View() string {
var s string = fmt.Sprintf(
"What’s your name?\n\n%s",
m.nameInput.View(),
) + "\n"
if m.step == 2 {
s += fmt.Sprintf(
"Tell me a story.\n\n%s",
m.noteInput.View())
}
return s
}
nameInput's cursor blinks fine. But noteInput doesn't. Also changing noteInput to another textInput doesn't help.
The text was updated successfully, but these errors were encountered:
Move nameInput.Blur()/noteInput.Focus() to where the step is incremented. Now these methods are called each time a key is pressed when noteInput is focused.
noteInput.Focus() returns a command. Handle it to get the cursor to blink.
Hi all. I'm new to bubble tea and bubbles, and I'm trying to make multiple inputs blink, however I can only make the very first one work. All successive inputs don't have cursor blinking
Here's my code
nameInput's cursor blinks fine. But noteInput doesn't. Also changing noteInput to another textInput doesn't help.
The text was updated successfully, but these errors were encountered: