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 ¶
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 (Model) LayoutNode ¶
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 ¶
Linearize is the embedded textinput's line with the field named "number field".
func (Model) SetTheme ¶
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 ¶
Tokens returns the embedded textinput's colour overrides, as set by WithTokens. The widget shares theme.ComponentTextInput with textinput.
func (Model) Update ¶
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.