gum/write/write.go
Maas Lalani 3e8153e140
fix(write): Add CtrlD as a quitting key
Add tea.KeyCtrlD as a way to quit the write as it signifies EOF.
2022-07-11 17:18:06 -04:00

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
}