From 5b7d0064874e732957525e9030402be1043695c5 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Fri, 29 Jul 2022 11:19:40 -0400 Subject: [PATCH] feat: add `--password` option for masked input --- input/command.go | 5 +++++ input/options.go | 1 + 2 files changed, 6 insertions(+) diff --git a/input/command.go b/input/command.go index ec529b8..0a3f8c4 100644 --- a/input/command.go +++ b/input/command.go @@ -31,6 +31,11 @@ func (o Options) Run() error { i.PromptStyle = o.PromptStyle.ToLipgloss() i.CursorStyle = o.CursorStyle.ToLipgloss() + if o.Password { + i.EchoMode = textinput.EchoPassword + i.EchoCharacter = '•' + } + p := tea.NewProgram(model{i}, tea.WithOutput(os.Stderr)) m, err := p.StartReturningModel() fmt.Println(m.(model).textinput.Value()) diff --git a/input/options.go b/input/options.go index 9881124..5d3d50f 100644 --- a/input/options.go +++ b/input/options.go @@ -10,4 +10,5 @@ type Options struct { CursorStyle style.Styles `embed:"" prefix:"cursor." set:"defaultForeground=212" set:"name=cursor"` Value string `help:"Initial value (can also be passed via stdin)" default:""` Width int `help:"Input width" default:"40"` + Password bool `help:"Mask input characters" default:"false"` }