2022-07-13 15:55:36 +02:00
|
|
|
// Package input provides a shell script interface for the text input bubble.
|
|
|
|
// https://github.com/charmbracelet/bubbles/tree/master/textinput
|
|
|
|
//
|
|
|
|
// It can be used to prompt the user for some input. The text the user entered
|
|
|
|
// will be sent to stdout.
|
|
|
|
//
|
|
|
|
// $ gum input --placeholder "What's your favorite gum?" > answer.text
|
|
|
|
//
|
2022-07-06 18:06:08 +02:00
|
|
|
package input
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/charmbracelet/bubbles/textinput"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
)
|
|
|
|
|
2022-07-31 03:29:09 +02:00
|
|
|
type model struct {
|
|
|
|
textinput textinput.Model
|
|
|
|
aborted bool
|
|
|
|
}
|
2022-07-06 18:06:08 +02:00
|
|
|
|
|
|
|
func (m model) Init() tea.Cmd { return textinput.Blink }
|
|
|
|
func (m model) View() string { return m.textinput.View() }
|
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
|
switch msg := msg.(type) {
|
|
|
|
case tea.KeyMsg:
|
|
|
|
switch msg.Type {
|
2022-07-31 03:29:09 +02:00
|
|
|
case tea.KeyEscape, tea.KeyCtrlC:
|
|
|
|
m.aborted = true
|
|
|
|
fallthrough
|
|
|
|
case tea.KeyEnter:
|
2022-07-06 18:06:08 +02:00
|
|
|
return m, tea.Quit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var cmd tea.Cmd
|
|
|
|
m.textinput, cmd = m.textinput.Update(msg)
|
|
|
|
return m, cmd
|
|
|
|
}
|