2022-07-06 20:38:40 +02:00
|
|
|
package write
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-03-08 23:23:46 +01:00
|
|
|
"strings"
|
2022-07-06 20:38:40 +02:00
|
|
|
|
2022-07-13 04:12:02 +02:00
|
|
|
"github.com/charmbracelet/gum/internal/stdin"
|
2024-03-29 12:19:03 +01:00
|
|
|
"github.com/charmbracelet/huh"
|
2022-07-06 20:38:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Run provides a shell script interface for the text area bubble.
|
|
|
|
// https://github.com/charmbracelet/bubbles/textarea
|
2022-07-13 04:12:02 +02:00
|
|
|
func (o Options) Run() error {
|
|
|
|
in, _ := stdin.Read()
|
|
|
|
if in != "" && o.Value == "" {
|
2023-03-09 18:45:52 +01:00
|
|
|
o.Value = strings.ReplaceAll(in, "\r", "")
|
2022-07-13 04:12:02 +02:00
|
|
|
}
|
|
|
|
|
2024-03-29 12:19:03 +01:00
|
|
|
var value = o.Value
|
|
|
|
|
|
|
|
theme := huh.ThemeCharm()
|
|
|
|
theme.Focused.Base = o.BaseStyle.ToLipgloss()
|
|
|
|
theme.Focused.TextInput.Cursor = o.CursorStyle.ToLipgloss()
|
|
|
|
theme.Focused.Title = o.HeaderStyle.ToLipgloss()
|
|
|
|
theme.Focused.TextInput.Placeholder = o.PlaceholderStyle.ToLipgloss()
|
|
|
|
theme.Focused.TextInput.Prompt = o.PromptStyle.ToLipgloss()
|
|
|
|
|
|
|
|
err := huh.NewForm(
|
|
|
|
huh.NewGroup(
|
|
|
|
huh.NewText().
|
|
|
|
Title(o.Header).
|
|
|
|
Placeholder(o.Placeholder).
|
|
|
|
CharLimit(o.CharLimit).
|
|
|
|
ShowLineNumbers(o.ShowLineNumbers).
|
|
|
|
Value(&value),
|
|
|
|
),
|
|
|
|
).
|
|
|
|
WithWidth(o.Width).
|
|
|
|
WithHeight(o.Height).
|
|
|
|
WithShowHelp(false).Run()
|
2022-07-07 23:46:22 +02:00
|
|
|
|
2022-08-05 00:45:19 +02:00
|
|
|
if err != nil {
|
2024-03-29 12:19:03 +01:00
|
|
|
return err
|
2022-07-31 03:41:18 +02:00
|
|
|
}
|
|
|
|
|
2024-03-29 12:19:03 +01:00
|
|
|
fmt.Println(value)
|
2022-08-05 00:45:19 +02:00
|
|
|
return nil
|
2022-07-06 20:38:40 +02:00
|
|
|
}
|