gum/write/command.go

49 lines
1 KiB
Go
Raw Permalink Normal View History

package write
import (
"fmt"
2023-03-08 23:23:46 +01:00
"strings"
"github.com/charmbracelet/gum/internal/stdin"
2024-03-29 12:19:03 +01:00
"github.com/charmbracelet/huh"
)
// Run provides a shell script interface for the text area bubble.
// https://github.com/charmbracelet/bubbles/textarea
func (o Options) Run() error {
in, _ := stdin.Read()
if in != "" && o.Value == "" {
o.Value = strings.ReplaceAll(in, "\r", "")
}
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-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
}