mirror of
https://github.com/charmbracelet/gum
synced 2024-05-17 21:56:42 +02:00
fix: textinput stdin read
This commit is contained in:
parent
4a560b1953
commit
589be38936
|
@ -2,8 +2,9 @@ package input
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/huh"
|
"github.com/charmbracelet/huh"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
|
||||||
|
@ -13,21 +14,21 @@ import (
|
||||||
// Run provides a shell script interface for the text input bubble.
|
// Run provides a shell script interface for the text input bubble.
|
||||||
// https://github.com/charmbracelet/bubbles/textinput
|
// https://github.com/charmbracelet/bubbles/textinput
|
||||||
func (o Options) Run() error {
|
func (o Options) Run() error {
|
||||||
i := textinput.New()
|
|
||||||
|
var value string
|
||||||
if o.Value != "" {
|
if o.Value != "" {
|
||||||
i.SetValue(o.Value)
|
value = o.Value
|
||||||
} else if in, _ := stdin.Read(); in != "" {
|
} else if in, _ := stdin.Read(); in != "" {
|
||||||
i.SetValue(in)
|
value = in
|
||||||
}
|
}
|
||||||
|
|
||||||
theme := huh.ThemeCharm()
|
theme := huh.ThemeCharm()
|
||||||
theme.Focused.Base = lipgloss.NewStyle()
|
theme.Focused.Base = lipgloss.NewStyle()
|
||||||
theme.Focused.TextInput.Cursor = o.CursorStyle.ToLipgloss()
|
// theme.Focused.TextInput.Cursor = o.CursorStyle.ToLipgloss()
|
||||||
theme.Focused.TextInput.Placeholder = o.PlaceholderStyle.ToLipgloss()
|
theme.Focused.TextInput.Placeholder = o.PlaceholderStyle.ToLipgloss()
|
||||||
theme.Focused.TextInput.Prompt = o.PromptStyle.ToLipgloss()
|
theme.Focused.TextInput.Prompt = o.PromptStyle.ToLipgloss()
|
||||||
theme.Focused.Title = o.HeaderStyle.ToLipgloss()
|
theme.Focused.Title = o.HeaderStyle.ToLipgloss()
|
||||||
|
|
||||||
var value string
|
|
||||||
var echoMode huh.EchoMode
|
var echoMode huh.EchoMode
|
||||||
|
|
||||||
if o.Password {
|
if o.Password {
|
||||||
|
@ -49,6 +50,7 @@ func (o Options) Run() error {
|
||||||
).
|
).
|
||||||
WithShowHelp(false).
|
WithShowHelp(false).
|
||||||
WithTheme(theme).
|
WithTheme(theme).
|
||||||
|
WithProgramOptions(tea.WithOutput(os.Stderr)).
|
||||||
Run()
|
Run()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue