summaryrefslogtreecommitdiff
path: root/tui
diff options
context:
space:
mode:
Diffstat (limited to 'tui')
-rw-r--r--tui/text_input.go19
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()
}