gum/write/command.go
Maas Lalani a0e2cda3cb
feat: Add gum write command
Write provides a shell script interface for the text area bubble. It can
be used to ask the user to write some long form of text (multi-line)
input. The text the user entered will be sent to stdout.

```
gum write > output.text
```
2022-07-07 13:29:11 -04:00

32 lines
718 B
Go

package write
import (
"fmt"
"os"
"github.com/charmbracelet/bubbles/textarea"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
// Run provides a shell script interface for the text area bubble.
// https://github.com/charmbracelet/bubbles/textarea
func (o Options) Run() {
a := textarea.New()
a.Focus()
a.Prompt = o.Prompt
a.Placeholder = o.Placeholder
a.ShowLineNumbers = o.ShowLineNumbers
if !o.ShowCursorLine {
a.FocusedStyle.CursorLine = lipgloss.NewStyle()
a.BlurredStyle.CursorLine = lipgloss.NewStyle()
}
a.SetWidth(o.Width)
p := tea.NewProgram(model{a}, tea.WithOutput(os.Stderr))
m, _ := p.StartReturningModel()
fmt.Println(m.(model).textarea.Value())
}