numberinput

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: 5 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 numberinput is a thin wrapper over textinput.Model that restricts typed input to digits and a single leading '-'. Everything else (navigation, deletion, paste, focus, styling, View) behaves exactly like textinput.Model.

Example

A numberinput accepts digits and a single leading minus sign; other runes are dropped.

package main

import (
	"fmt"

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

func main() {
	m := numberinput.New()
	m.Focus()
	for _, r := range "-1x2-3" {
		m, _ = m.Update(tui.Key{Type: tui.KeyRunes, Text: string([]rune{r})})
	}
	fmt.Println(m.Value())
}
Output:
-123

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 "number field".

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 rune that isn't an ASCII digit, except a single '-' which is accepted only when it would become the very first character of the value (criteria #335, #336). Every other key or Msg (navigation, deletion, paste, blink ticks, ...) is forwarded unchanged to the embedded textinput.Model.

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