emailinput

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package emailinput is a thin wrapper over textinput.Model that rejects whitespace runes as typed input. Everything else (navigation, deletion, paste, focus, styling, View) behaves exactly like textinput.Model. It also exposes a lightweight Valid heuristic for whether the current value looks like an email address.

Example

An emailinput is a textinput that rejects whitespace as typed input and can say whether its value looks like an address.

package main

import (
	"fmt"

	"github.com/ows4444/tui"
	"github.com/ows4444/tui/emailinput"
)

func main() {
	m := emailinput.New()
	m.Focus()
	for _, r := range "a b@c.io" {
		m, _ = m.Update(tui.Key{Type: tui.KeyRunes, Text: string([]rune{r})})
	}
	fmt.Println(m.Value(), m.Valid())
}
Output:
ab@c.io true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	textinput.Model
}

Model wraps a textinput.Model, filtering the runes it accepts. Its promoted Mouse and Bounds fields turn on click-to-place-cursor and drag-select exactly as on textinput.Model.

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. It is the embedded textinput.Model's node (natural size on one row, exact size on Render); the wrapper filters typed runes only, so View and layout are unchanged.

func (Model) Linearize

func (m Model) Linearize() string

Linearize is the embedded textinput's line with the field named "email field". The value is spoken, as an email address is not a secret.

func (Model) SetTheme

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

SetTheme returns m with t applied to the embedded textinput.Model. It is defined here so it returns this package's Model; the promoted textinput.Model.SetTheme would return the embedded type and drop the wrapper's filtering.

func (Model) Tokens

func (m Model) Tokens() theme.Tokens

Tokens returns the embedded textinput's colour overrides, as set by WithTokens. The widget shares theme.ComponentTextInput with textinput.

func (Model) Update

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

Update intercepts tui.KeyRunes to reject any whitespace rune (space, tab, and everything else unicode.IsSpace reports) so it can never be inserted into the value (criterion #514). Every other key or Msg (navigation, deletion, paste, blink ticks, ...) is forwarded unchanged to the embedded textinput.Model.

func (Model) Valid

func (m Model) Valid() bool

Valid reports whether the current value looks like an email address, via a lightweight heuristic: exactly one '@' with a non-empty part before it, and a '.' with a non-empty part after it somewhere following the '@'. This is not full RFC 5322 validation (criterion #515).

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. 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