ratin 0.1.0

Custom input field component for Ratatui TUI applications
Documentation
  • Coverage
  • 0%
    0 out of 16 items documented0 out of 0 items with examples
  • Size
  • Source code size: 61.11 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 724.33 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Fkernel653

ratin — Custom input field for Ratatui TUI

Rust Crates.io Docs.rs License Platform Rustfmt

Modular input field component for Ratatui terminal applications with character validation, cursor management, and customizable styling.

🚀 Quick Start

[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);

📋 Features

Input Field

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

Character Validator

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

Styling

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

🔧 Usage Examples

Basic Input

use ratin::InputField;

let mut input = InputField::new()
    .with_placeholder("Enter your name...")
    .with_max_length(50);

URL Input

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);

Numeric Input

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);

Custom Character Set

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...");

Custom Styling

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...");

Event Handling

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);
    })?;
}

📦 Installation

From crates.io

cargo add ratin

From GitHub

[dependencies]
ratin = { git = "https://github.com/Fkernel653/ratin" }

🧩 Module Structure

ratin/
├── src/
│   ├── lib.rs          # Public API
│   ├── input.rs        # Main InputField logic
│   ├── style.rs        # Styling and themes
│   ├── validator.rs    # Character validation
│   └── error.rs        # Error types

🔌 Requirements

Dependency Version Purpose
ratatui 0.24+ TUI framework
crossterm 0.27+ Terminal events

🎯 Key Features

  • 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

📄 License

MIT License — See License

Author: Fkernel653

Project: GitHubCrates.ioDocs.rs