feat: Allow setting initial value for input and write

This commit is contained in:
Maas Lalani 2022-07-11 16:53:11 -04:00
parent 46ddc28ae5
commit 593cf711be
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
4 changed files with 4 additions and 0 deletions

View file

@ -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

View file

@ -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"`
}

View file

@ -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()

View file

@ -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"`
}