mirror of
https://github.com/charmbracelet/gum.git
synced 2024-11-05 05:46:36 +03:00
3e8153e140
Add tea.KeyCtrlD as a way to quit the write as it signifies EOF.
34 lines
625 B
Go
34 lines
625 B
Go
package write
|
|
|
|
import (
|
|
"github.com/charmbracelet/bubbles/textarea"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
type model struct {
|
|
quitting bool
|
|
textarea textarea.Model
|
|
}
|
|
|
|
func (m model) Init() tea.Cmd { return textarea.Blink }
|
|
func (m model) View() string {
|
|
if m.quitting {
|
|
return ""
|
|
}
|
|
return m.textarea.View()
|
|
}
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
switch msg.Type {
|
|
case tea.KeyEscape, tea.KeyCtrlC, tea.KeyCtrlD:
|
|
m.quitting = true
|
|
return m, tea.Quit
|
|
}
|
|
}
|
|
|
|
var cmd tea.Cmd
|
|
m.textarea, cmd = m.textarea.Update(msg)
|
|
return m, cmd
|
|
}
|