ratin β Custom input field for Ratatui TUI
Modular input field component for Ratatui terminal applications with character validation, cursor management, and customizable styling.
[dependencies ]
ratin = " 0.1.0"
use ratin:: { InputField , CharValidator } ;
let validator = CharValidator :: new ( )
. allow_url_chars ( )
. with_max_length ( 200 ) ;
let mut input = InputField :: new ( )
. with_validator ( validator)
. with_placeholder ( "Enter URL..." )
. with_max_length ( 100 ) ;
Feature
Description
new()
Create new input field
with_placeholder()
Set placeholder text
with_block()
Customize block widget
with_max_length()
Set maximum input length
with_validator()
Set character validator
get_text()
Get current input text
clear()
Clear input field
set_processing()
Set processing state (locks input)
set_focused()
Set focus state
set_error()
Set error message
Method
Description
new()
Create new validator
with_allowed_chars()
Set allowed characters (vector)
allow_letters()
Allow only letters A-Z, a-z
allow_digits()
Allow only digits 0-9
allow_alphanumeric()
Allow letters and digits
allow_url_chars()
Allow URL-safe characters
allow_email_chars()
Allow email-safe characters
with_case_sensitive()
Toggle case sensitivity
Method
Description
new()
Create new style
with_focused()
Set focused border color
with_error()
Set error border color
with_processing()
Set processing border color
with_text_color()
Set text color
with_placeholder_color()
Set placeholder color
use ratin:: InputField ;
let mut input = InputField :: new ( )
. with_placeholder ( "Enter your name..." )
. with_max_length ( 50 ) ;
use ratin:: { InputField , CharValidator } ;
let validator = CharValidator :: new ( )
. allow_url_chars ( )
. with_case_sensitive ( false ) ;
let mut input = InputField :: new ( )
. with_validator ( validator)
. with_placeholder ( "https://example.com..." )
. with_max_length ( 200 ) ;
use ratin:: { InputField , CharValidator } ;
let validator = CharValidator :: new ( )
. allow_digits ( )
. with_max_length ( 10 ) ;
let mut input = InputField :: new ( )
. with_validator ( validator)
. with_placeholder ( "Enter number..." )
. with_max_length ( 10 ) ;
use ratin:: { InputField , CharValidator } ;
let validator = CharValidator :: new ( )
. with_allowed_chars ( vec ! [ 'a' , 'b' , 'c' , '1' , '2' , '3' ] ) ;
let mut input = InputField :: new ( )
. with_validator ( validator)
. with_placeholder ( "Enter a/b/c or 1/2/3..." ) ;
use ratin:: { InputField , InputStyle } ;
use ratatui:: style:: Color ;
let style = InputStyle :: new ( )
. with_focused ( Color :: Green )
. with_error ( Color :: Red )
. with_processing ( Color :: Yellow )
. with_text_color ( Color :: White )
. with_placeholder_color ( Color :: DarkGray ) ;
let mut input = InputField :: new ( )
. with_style ( style)
. with_placeholder ( "Styled input..." ) ;
use crossterm:: event:: { KeyCode } ;
loop {
if let Event :: Key ( key) = event:: read ( ) ? {
if key. code == KeyCode :: Enter {
if let Err ( e) = input. validate ( ) {
input. set_error ( Some ( e. to_string ( ) ) ) ;
} else {
let text = input. get_text ( ) ;
input. set_processing ( true ) ;
// Process input...
}
} else if key. code == KeyCode :: Esc {
break ;
} else {
input. handle_key ( key. code , key. modifiers ) ;
}
}
terminal. draw ( |f| {
input. render ( f, area) ;
} ) ?;
}
[dependencies ]
ratin = { git = " https://github.com/Fkernel653/ratin" }
ratin/
βββ src/
β βββ lib.rs # Public API
β βββ input.rs # Main InputField logic
β βββ style.rs # Styling and themes
β βββ validator.rs # Character validation
β βββ error.rs # Error types
Dependency
Version
Purpose
ratatui
0.24+
TUI framework
crossterm
0.27+
Terminal events
Character Validation β Restrict input to specific characters
Cursor Management β Full cursor control with arrow keys
Placeholder Support β Show hints when empty
Processing State β Lock input during async operations
Error Handling β Visual error feedback
Max Length β Prevent overflow
Case Sensitivity β Optional case-sensitive validation
Clean API β Builder pattern for configuration
MIT License β See License
Author: Fkernel653
Project: GitHub β’ Crates.io β’ Docs.rs