From 593cf711be994d8ae92dd8fe3a46dab2ad6888d2 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Mon, 11 Jul 2022 16:53:11 -0400 Subject: [PATCH] feat: Allow setting initial value for `input` and `write` --- input/command.go | 1 + input/options.go | 1 + write/command.go | 1 + write/options.go | 1 + 4 files changed, 4 insertions(+) diff --git a/input/command.go b/input/command.go index 4bfabf7..22d1913 100644 --- a/input/command.go +++ b/input/command.go @@ -15,6 +15,7 @@ func (o Options) Run() { i := textinput.New() i.Focus() + i.SetValue(o.Value) i.Prompt = o.Prompt i.Placeholder = o.Placeholder i.Width = o.Width diff --git a/input/options.go b/input/options.go index 4abfdd8..e4a2e8a 100644 --- a/input/options.go +++ b/input/options.go @@ -6,5 +6,6 @@ type Options struct { Placeholder string `help:"Placeholder value" default:"Type something..."` Prompt string `help:"Prompt to display" default:"> "` PromptColor string `help:"Color of prompt" default:"7"` + Value string `help:"Initial value" default:""` Width int `help:"Input width" default:"20"` } diff --git a/write/command.go b/write/command.go index 2b2b50d..db38817 100644 --- a/write/command.go +++ b/write/command.go @@ -30,6 +30,7 @@ func (o Options) Run() { a.SetWidth(o.Width) a.SetHeight(o.Height) + a.SetValue(o.Value) p := tea.NewProgram(model{a}, tea.WithOutput(os.Stderr)) m, _ := p.StartReturningModel() diff --git a/write/options.go b/write/options.go index 0ae90cf..2b9ef53 100644 --- a/write/options.go +++ b/write/options.go @@ -9,5 +9,6 @@ type Options struct { PromptColor string `help:"Prompt color" default:"238"` ShowCursorLine bool `help:"Show cursor line" default:"false"` ShowLineNumbers bool `help:"Show line numbers" default:"false"` + Value string `help:"Initial value" default:""` Width int `help:"Text area width" default:"50"` }