feat: Make input and write textarea CharLimit configurable through options

Removes the hardcoded 400 chars CharLimit (default for textarea), and make the CharLimit configurable through an Option.
This commit is contained in:
Mathias Griffe 2022-08-03 10:44:00 +02:00 committed by Maas Lalani
parent 197e52a362
commit 06e8546366
4 changed files with 4 additions and 0 deletions

View file

@ -28,6 +28,7 @@ func (o Options) Run() error {
i.Width = o.Width
i.PromptStyle = o.PromptStyle.ToLipgloss()
i.CursorStyle = o.CursorStyle.ToLipgloss()
i.CharLimit = o.CharLimit
if o.Password {
i.EchoMode = textinput.EchoPassword

View file

@ -10,6 +10,7 @@ type Options struct {
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 (can also be passed via stdin)" default:""`
CharLimit int `help:"Maximum value length (0 for no limit)" default:"400"`
Width int `help:"Input width" default:"40"`
Password bool `help:"Mask input characters" default:"false"`
}

View file

@ -26,6 +26,7 @@ func (o Options) Run() error {
a.Prompt = o.Prompt
a.Placeholder = o.Placeholder
a.ShowLineNumbers = o.ShowLineNumbers
a.CharLimit = o.CharLimit
style := textarea.Style{
Base: o.BaseStyle.ToLipgloss(),

View file

@ -12,6 +12,7 @@ type Options struct {
ShowCursorLine bool `help:"Show cursor line" default:"false"`
ShowLineNumbers bool `help:"Show line numbers" default:"false"`
Value string `help:"Initial value (can be passed via stdin)" default:""`
CharLimit int `help:"Maximum value length (0 for no limit)" default:"400"`
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"`