feat: allow initial values of input and write to be set via stdin

This commit is contained in:
Maas Lalani 2022-07-12 16:30:17 -04:00
parent 02e925ea57
commit bf8d9964df
No known key found for this signature in database
GPG Key ID: 5A6ED5CBF1A0A000
3 changed files with 10 additions and 2 deletions

View File

@ -8,6 +8,6 @@ type Options struct {
Prompt string `help:"Prompt to display" default:"> "`
PromptStyle style.Styles `embed:"" prefix:"prompt." set:"name=prompt"`
CursorStyle style.Styles `embed:"" prefix:"cursor." set:"defaultForeground=212" set:"name=cursor"`
Value string `help:"Initial value" default:""`
Value string `help:"Initial value (can also be passed via stdin)" default:""`
Width int `help:"Input width" default:"20"`
}

View File

@ -23,8 +23,16 @@ func main() {
)
switch ctx.Command() {
case "input":
v, _ := stdin.Read()
if v != "" {
gum.Input.Value = v
}
gum.Input.Run()
case "write":
v, _ := stdin.Read()
if v != "" {
gum.Write.Value = v
}
gum.Write.Run()
case "filter":
gum.Filter.Run()

View File

@ -10,7 +10,7 @@ type Options struct {
Prompt string `help:"Prompt to display" default:"┃ "`
ShowCursorLine bool `help:"Show cursor line" default:"false"`
ShowLineNumbers bool `help:"Show line numbers" default:"false"`
Value string `help:"Initial value" default:""`
Value string `help:"Initial value (can be passed via stdin)" default:""`
BaseStyle style.Styles `embed:"" prefix:"base." set:"name=base"`
CursorLineNumberStyle style.Styles `embed:"" prefix:"cursor-line-number." set:"defaultForeground=7" set:"name=cursor line number"`