2022-07-06 20:38:40 +02:00
|
|
|
package write
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/charmbracelet/bubbles/textarea"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2022-07-12 22:05:40 +02:00
|
|
|
style := textarea.Style{
|
|
|
|
Base: o.BaseStyle.ToLipgloss(),
|
|
|
|
Placeholder: o.PlaceholderStyle.ToLipgloss(),
|
|
|
|
CursorLine: o.CursorLineStyle.ToLipgloss(),
|
|
|
|
CursorLineNumber: o.CursorLineNumberStyle.ToLipgloss(),
|
|
|
|
EndOfBuffer: o.EndOfBufferStyle.ToLipgloss(),
|
|
|
|
LineNumber: o.LineNumberStyle.ToLipgloss(),
|
|
|
|
Prompt: o.PromptStyle.ToLipgloss(),
|
|
|
|
}
|
2022-07-07 23:46:22 +02:00
|
|
|
|
2022-07-12 22:05:40 +02:00
|
|
|
a.BlurredStyle = style
|
|
|
|
a.FocusedStyle = style
|
|
|
|
a.Cursor.Style = o.CursorStyle.ToLipgloss()
|
2022-07-07 23:46:22 +02:00
|
|
|
|
2022-07-06 20:38:40 +02:00
|
|
|
a.SetWidth(o.Width)
|
2022-07-09 02:20:34 +02:00
|
|
|
a.SetHeight(o.Height)
|
2022-07-11 22:53:11 +02:00
|
|
|
a.SetValue(o.Value)
|
2022-07-06 20:38:40 +02:00
|
|
|
|
2022-07-11 23:16:30 +02:00
|
|
|
p := tea.NewProgram(model{textarea: a}, tea.WithOutput(os.Stderr))
|
2022-07-06 20:38:40 +02:00
|
|
|
m, _ := p.StartReturningModel()
|
|
|
|
fmt.Println(m.(model).textarea.Value())
|
|
|
|
}
|