From ff0f6ba724748dbe340187fdd831a4d4f7f0ae5e Mon Sep 17 00:00:00 2001 From: raven Date: Wed, 22 Oct 2025 16:28:22 -0500 Subject: passwords --- tui/text_input.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'tui/text_input.go') 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() } -- cgit v1.2.3