Documentation
¶
Overview ¶
Package passwordinput is a thin wrapper over textinput.Model that masks every rendered character of a non-empty value. Update's behavior (typing, deletion, navigation, paste, focus) is reused unchanged from textinput.Model — Model.Update exists only to re-wrap the result as Model instead of textinput.Model (see its doc comment); only View differs otherwise.
Example ¶
A passwordinput shows a mask instead of what was typed, but Value still returns the real text.
package main
import (
"fmt"
"github.com/ows4444/tui"
"github.com/ows4444/tui/ansi"
"github.com/ows4444/tui/passwordinput"
)
func main() {
m := passwordinput.New()
m.Focus()
for _, r := range "hunter2" {
m, _ = m.Update(tui.Key{Type: tui.KeyRunes, Text: string([]rune{r})})
}
fmt.Println(m.Value())
fmt.Println(ansi.StripANSI(m.View()))
}
Output: hunter2 •••••••
Index ¶
Examples ¶
Constants ¶
const Mask = '•'
Mask is the rune each character of a non-empty value is rendered as.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
textinput.Model
// Theme supplies the mask glyph (theme.Glyphs.Mask): Mask under the
// default theme, '*' under an ASCII one. New sets theme.DarkTheme(); a zero Theme
// draws Mask.
Theme theme.Theme
}
Model wraps a textinput.Model, masking its rendered value.
func (Model) LayoutNode ¶
LayoutNode adapts the field to a layout.Node, like textinput.Model's, but renders the masked View, never the typed value. This override is required: Model embeds textinput.Model, whose LayoutNode would otherwise be promoted and draw the real value on screen.
func (Model) Linearize ¶
Linearize renders the field as one plain-text line for accessible output (see tui.Linearizer): its label, "password field", ", focused" when it has focus, and how many characters were entered, e.g. `Password, password field, 8 characters entered`. It never includes the typed value. This override is required: Model embeds textinput.Model, whose own Linearize would otherwise be promoted and speak the real value.
func (Model) SetTheme ¶
SetTheme returns m with t applied. It makes Model a tui.ThemeSetter, so a root model can forward the Program's theme (see tui.WithTheme).
func (Model) Tokens ¶
Tokens returns the embedded textinput's colour overrides, as set by WithTokens.
func (Model) Update ¶
Update forwards msg to the embedded textinput.Model unchanged and re-wraps the result — without this override, the promoted textinput.Model.Update would be selected instead, whose return type is textinput.Model, not Model: the standard `m, cmd := m.Update(msg)` pattern every other widget in this library supports would silently change m's type out from under a caller expecting Model.