tui-slider
A simple TUI slider component library for ratatui.
Perfect for building music players, audio controls, equalizers, and any terminal UI that needs simple, clean sliders.
✨ Features
- 🎚️ Horizontal and Vertical sliders - Support for both orientations
- 🎨 Simple customization - Easily customize colors and symbols
- 🔧 Easy to use - Minimal configuration required
- 📊 State management - Built-in state for value tracking
- ⚡ Lightweight - No complex dependencies
📦 Installation
Add to your Cargo.toml:
[]
= "0.1"
= "0.28"
🚀 Quick Start
use *;
use ;
📖 Examples
Horizontal Slider
use Color;
use ;
let state = new;
let slider = from_state
.orientation
.label
.show_value
.filled_symbol
.empty_symbol
.handle_symbol
.filled_color
.empty_color
.handle_color;
Vertical Slider
use Color;
use ;
let state = new;
let slider = from_state
.orientation
.label
.show_value
.filled_symbol
.empty_symbol
.handle_symbol
.filled_color
.empty_color
.handle_color;
Custom Symbols
let slider = from_state
.filled_symbol
.empty_symbol
.handle_symbol
.filled_color
.show_handle;
Toggle Thumb/Handle Visibility
// Show the thumb indicator (default)
let slider = from_state
.show_thumb;
// Hide the thumb for a progress bar style
let slider = from_state
.show_thumb;
// show_handle() is an alias for show_thumb()
let slider = from_state
.show_handle;
🎮 Interactive Usage
use SliderState;
let mut state = new;
// Increase/decrease by a step
state.increase;
state.decrease;
// Set exact value
state.set_value;
// Get current value
let current = state.value;
// Get as percentage (0.0 to 1.0)
let percentage = state.percentage;
🎯 API Overview
Slider Widget
new(value, min, max)- Create a new sliderfrom_state(&state)- Create from a stateorientation(orientation)- Set horizontal or verticallabel(text)- Set label textshow_value(bool)- Show/hide value displayshow_handle(bool)- Show/hide handlefilled_symbol(symbol)- Set filled bar symbolempty_symbol(symbol)- Set empty bar symbolhandle_symbol(symbol)- Set handle symbolfilled_color(color)- Set filled bar colorempty_color(color)- Set empty bar colorhandle_color(color)- Set handle colorshow_handle(bool)- Show/hide thumb indicatorshow_thumb(bool)- Alias for show_handleblock(block)- Add border block
SliderState
new(value, min, max)- Create new statevalue()- Get current valueset_value(value)- Set valueincrease(step)- Increase by stepdecrease(step)- Decrease by stepmin()/max()- Get boundsset_min(min)/set_max(max)- Set boundspercentage()- Get value as percentage (0.0-1.0)set_percentage(percentage)- Set from percentage
🎨 Demos
Run the examples to see the sliders in action:
# Horizontal sliders with different styles
# Vertical sliders (equalizer style)
# Custom slider configurations
# Toggle thumb/handle visibility
🏗️ Architecture
The library consists of three main components:
- Slider - The widget that renders the slider
- SliderState - Manages value, bounds, and state
- SliderOrientation - Horizontal or Vertical orientation
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with ratatui
- Inspired by various TUI music players and audio applications
📝 Changelog
See CHANGELOG.md for a list of changes.