passwordinput

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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 New

func New() Model

New returns a Model with textinput's default styling.

func (Model) LayoutNode

func (m Model) LayoutNode() layout.Node

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

func (m Model) Linearize() string

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

func (m Model) SetTheme(t theme.Theme) Model

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

func (m Model) Tokens() theme.Tokens

Tokens returns the embedded textinput's colour overrides, as set by WithTokens.

func (Model) Update

func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)

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.

func (Model) View

func (m Model) View() string

View renders every character of a non-empty value masked with Mask (criterion #337), while Value() still returns the real, unmasked typed text. An empty value still renders Placeholder unmasked, matching textinput.Model's empty-value behavior (criterion #338).

func (Model) WithTokens

func (m Model) WithTokens(tok theme.Tokens) Model

WithTokens returns m with tok as its per-instance colour override, applied to the embedded textinput.Model (Text recolours the value, Muted the placeholder). It is defined here so it returns this package's Model.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL