Skip to content

Commit e5a755a

Browse files
mvanhornandrinoff
authored andcommitted
feat(tui/login): add ctrl+v password visibility toggle (#593)
Closes #593. Typos in app-passwords are hard to spot under EchoPassword and the workaround was to delete and retype. This wires ctrl+v (only while the password input has focus) to flip between EchoPassword and EchoNormal on inputs[inputPassword], matching the approach the issue suggested. The help line under the form already lists the other chord shortcuts (enter / tab / esc), so the new chord is appended to that same line and only while the password field is focused — keeps the hint discoverable without cluttering the view when focus is elsewhere. Go build, go vet, and go test ./tui all pass locally.
1 parent c9da429 commit e5a755a

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

tui/login.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ func (m *Login) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
176176
case "esc":
177177
return m, func() tea.Msg { return GoToChoiceMenuMsg{} }
178178

179+
case "ctrl+v":
180+
// Toggle password visibility while focused on the password field,
181+
// so typos in app-passwords are catchable without retyping.
182+
if m.focusIndex == inputPassword {
183+
if m.inputs[inputPassword].EchoMode == textinput.EchoPassword {
184+
m.inputs[inputPassword].EchoMode = textinput.EchoNormal
185+
} else {
186+
m.inputs[inputPassword].EchoMode = textinput.EchoPassword
187+
}
188+
return m, nil
189+
}
190+
179191
case "enter":
180192
m.updateFlags()
181193
visible := m.visibleFields()
@@ -417,7 +429,11 @@ func (m *Login) View() tea.View {
417429
if !m.hideTips && tip != "" {
418430
views = append(views, TipStyle.Render("Tip: "+tip))
419431
}
420-
views = append(views, helpStyle.Render("\nenter: save • tab: next field • esc: back to menu"))
432+
helpLine := "enter: save • tab: next field • esc: back to menu"
433+
if m.focusIndex == inputPassword {
434+
helpLine += " • ctrl+v: toggle password visibility"
435+
}
436+
views = append(views, helpStyle.Render("\n"+helpLine))
421437

422438
return tea.NewView(lipgloss.JoinVertical(lipgloss.Left, views...))
423439
}

0 commit comments

Comments
 (0)