charmbracelet / bubbles

TUI components for Bubble Tea 🫧
MIT License
5.57k stars 263 forks source link

Multiline Textinput #63

Closed laxman20 closed 2 years ago

laxman20 commented 3 years ago

I want to use the text input bubble to allow the user to enter some notes. They can enter newlines in the notes if they want. It looks like the text input component ignores the Enter key event. Is it possible to add multi-line support so that gets translated to "\n"? Or is there a more appropriate component for this?

meowgorithm commented 3 years ago

Multiline input isn’t supported yet, but it’s high on the list of features we’d like to support. We’ll keep this issue updated with progress.

laxman20 commented 3 years ago

That was quick. Thanks!

In the meantime, I'll share my temporary hack in case anyone is interested.

I just listen on the key enter message and append a rarely used character (I've chosen "¬").

case tea.KeyEnter:
    o := m.textInput.Value()
    m.textInput.Reset()
    m.textInput.SetValue(o + encodedEnter)
    return m, nil

Then in the render function, I just replace it with a newline decoded := strings.Replace(m.textInput.View(), encodedEnter, "\n", -1)

It works well enough for a personal project.

meowgorithm commented 3 years ago

@laxman20 That’s quite clever. Thanks for sharing!

LeonB commented 2 years ago

Any news on this? Just curious!

meowgorithm commented 2 years ago

I'm pleased to report this feature is now in development.

maaslalani commented 2 years ago

@LeonB @laxman20

textarea bubble is now merged into master and will be included in the next release! Excited to see what you all build :)

https://github.com/charmbracelet/bubbles

maaslalani commented 2 years ago

There are some examples on how to use it here: https://github.com/charmbracelet/bubbletea/pull/357

LeonB commented 2 years ago

@maaslalani thanks! Going to check it out!