tui-checkbox
A customizable checkbox widget for Ratatui TUI applications.
Demo
Features
- ☑️ Simple checkbox with label
- 🎨 Customizable styling for checkbox and label separately
- 🔤 Custom symbols (unicode, emoji, ASCII)
- 📦 Optional block wrapper
- ⚡ Zero-cost abstractions
Installation
Add this to your Cargo.toml:
[]
= "0.2.0"
= "0.29"
Or install with cargo:
Quick Start
use ;
use Checkbox;
// Basic checkbox
let checkbox = new;
// Styled checkbox
let checkbox = new
.style
.checkbox_style
.label_style;
// Custom symbols
let checkbox = new
.checked_symbol
.unchecked_symbol;
// With a block
use Block;
let checkbox = new
.block;
Examples
Run the included example with two modes:
Interactive Mode (Default)
Navigate and toggle checkboxes with your keyboard:
- ↑/↓ or k/j - Navigate between checkboxes
- Space - Toggle checkbox state
- Tab - Switch to API Showcase mode
- q or Esc - Quit
The interactive mode demonstrates:
- Basic checkbox with default styling
- Styled checkboxes with colors (Info, Warning, Error)
- Emoji and Unicode symbols (✅, ●, ◆)
- Custom ASCII symbols ([X], [*], [+]/[-], (X)/(O))
API Showcase Mode
Press Tab to switch to the API showcase view, which displays all available features:
- All core API methods (
new(),default(),label(),checked()) - All styling methods (
style(),checkbox_style(),label_style()) - Symbol customization (
checked_symbol(),unchecked_symbol()) - All predefined symbols from the
symbolsmodule - Advanced usage (blocks, Styled trait, method chaining)
Styling
The widget supports multiple styling options:
style(): Sets the base style for the entire widgetcheckbox_style(): Sets the style specifically for the checkbox symbollabel_style(): Sets the style specifically for the label text
Styles are applied in order: base style, then specific styles override it.
Custom Symbols
The widget comes with default Unicode checkbox symbols (☐ and ☑), but you can use any symbols:
// Emoji style
new
.checked_symbol
.unchecked_symbol;
// ASCII style
new
.checked_symbol
.unchecked_symbol;
// Circle style
new
.checked_symbol
.unchecked_symbol;
Predefined Symbols
The symbols module provides some common checkbox symbols:
symbols::CHECKED- ☑symbols::UNCHECKED- ☐symbols::CHECKED_X- [X]symbols::UNCHECKED_SPACE- [ ]symbols::CHECKED_ASTERISK- [*]symbols::CHECKED_PLUS- [+]symbols::UNCHECKED_MINUS- [-]symbols::CHECKED_PARENTHESIS_X- (X)symbols::UNCHECKED_PARENTHESIS_O- (O)
Development
Prerequisites
Install tools:
Common Tasks
# Run example
# Run tests
# Format and lint
# Check all
# Generate demo GIF (requires VHS)
# Bump version
See all available commands:
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Acknowledgments
This widget was created for the Ratatui ecosystem.
Special thanks to the Ratatui team for creating such an amazing TUI framework.