diff options
| author | raven <citrons@mondecitronne.com> | 2025-10-22 16:28:22 -0500 |
|---|---|---|
| committer | raven <citrons@mondecitronne.com> | 2026-02-09 13:13:55 -0600 |
| commit | ff0f6ba724748dbe340187fdd831a4d4f7f0ae5e (patch) | |
| tree | ab27a0c9f40d803c2bf130ef7c82cdf6540e9018 /tui/text_input.go | |
| parent | 4b54a1d11fd0fa355b244637612a3fd0af18c60c (diff) | |
passwords
Diffstat (limited to 'tui/text_input.go')
| -rw-r--r-- | tui/text_input.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/tui/text_input.go b/tui/text_input.go index 7f8e539..24792bc 100644 --- a/tui/text_input.go +++ b/tui/text_input.go @@ -13,8 +13,11 @@ type TextInput struct { selection string selectionBefore bool afterCursor string + Private bool } +var selectedStyle = Style {Bg: Blue, Fg: White, selected: true} + func (t *TextInput) Text() string { return t.beforeCursor + t.selection + t.afterCursor } @@ -225,19 +228,27 @@ func (t *TextInput) Update(ev Event) (usedKeybind bool) { return true } +func (t *TextInput) showText(text string, style *Style) { + if !t.Private { + Text(text, style) + } else { + Text(strings.Repeat("*", len([]rune(text))), style) + } +} + func (t *TextInput) Show(id string) { t.id = id Push(id, Box {Width: Fill, Height: TextSize}) - Text(t.beforeCursor, nil) + t.showText(t.beforeCursor, nil) if t.selectionBefore { - Text(t.selection, &Style {Bg: Blue, Fg: White, selected: true}) + t.showText(t.selection, &selectedStyle) } if t.selection == "" { Cursor() } if !t.selectionBefore { - Text(t.selection, &Style {Bg: Blue, Fg: White, selected: true}) + t.showText(t.selection, &selectedStyle) } - Text(t.afterCursor, nil) + t.showText(t.afterCursor, nil) Pop() } |
