mirror of
https://github.com/charmbracelet/gum
synced 2024-06-20 06:25:08 +02:00
fix(write): Hide textarea when quitting
When the user is done editing the text in the textarea this change hides the textarea and prints only the value to not clutter the terminal.
This commit is contained in:
parent
11e7e18256
commit
66ef277036
|
@ -32,7 +32,7 @@ func (o Options) Run() {
|
|||
a.SetHeight(o.Height)
|
||||
a.SetValue(o.Value)
|
||||
|
||||
p := tea.NewProgram(model{a}, tea.WithOutput(os.Stderr))
|
||||
p := tea.NewProgram(model{textarea: a}, tea.WithOutput(os.Stderr))
|
||||
m, _ := p.StartReturningModel()
|
||||
fmt.Println(m.(model).textarea.Value())
|
||||
}
|
||||
|
|
|
@ -5,15 +5,24 @@ import (
|
|||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type model struct{ textarea textarea.Model }
|
||||
type model struct {
|
||||
quitting bool
|
||||
textarea textarea.Model
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd { return textarea.Blink }
|
||||
func (m model) View() string { return m.textarea.View() }
|
||||
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:
|
||||
m.quitting = true
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue