A ratatui library for creating shader-like effects in terminal UIs. Build complex animations by composing and layering simple effects, bringing smooth transitions and visual polish to the terminal.
β‘οΈ Try exabind - experience tachyonfx in your browser without installing anything!
- 27 unique effects β color transformations, text animations, geometric distortions, plus support for custom effects
- Effect composition β chain and combine effects for sophisticated animations
- Interactive browser editor β design and preview effects in real-time with TachyonFX FTL
- Runtime effect compilation β create effects from strings using the built-in DSL
- Cell-precise targeting β apply effects to specific regions or cells matching custom criteria
Add tachyonfx to your Cargo.toml
:
cargo add tachyonfx
Create your first effect:
use std::{io, time::Instant};
use ratatui::{crossterm::event, prelude::*, widgets::Paragraph};
use tachyonfx::{fx, EffectManager, Interpolation};
fn main() -> io::Result<()> {
let mut terminal = ratatui::init();
let mut effects: EffectManager<()> = EffectManager::default();
// Add a simple fade-in effect
let fx = fx::fade_to(Color::Cyan, Color::Gray, (1_000, Interpolation::SineIn));
effects.add_effect(fx);
let mut last_frame = Instant::now();
loop {
let elapsed = last_frame.elapsed();
last_frame = Instant::now();
terminal.draw(|frame| {
let screen_area = frame.area();
// Render your content
let text = Paragraph::new("Hello, TachyonFX!").alignment(Alignment::Center);
frame.render_widget(text, screen_area);
// Apply effects
effects.process_effects(elapsed.into(), frame.buffer_mut(), screen_area);
})?;
// Exit on any key press
if event::poll(std::time::Duration::from_millis(16))? {
if let event::Event::Key(_) = event::read()? {
break;
}
}
}
ratatui::restore();
Ok(())
}
Explore the examples to see effects in action:
# Basic effects showcase
cargo run --example basic-effects
# Interactive DSL playground
cargo run --example dsl-playground
# Effect timeline visualization
cargo run --example fx-chart
# Minimal setup example
cargo run --example minimal
TachyonFX FTL is a browser-based editor for creating and tweaking effects in real-time.
- Effects are stateful β Create once, apply every frame
- Effects transform rendered content β Apply after widgets render
- Effects compose β Build complex animations from simple pieces
use tachyonfx::{fx, Effect, CellFilter};
// Create a fade-in effect
let mut fade = fx::fade_from(Color::Black, Color::White,
EffectTimer::from_ms(500, QuadOut));
// Apply to red text only
fade.set_cell_filter(CellFilter::FgColor(Color::Red));
// In your render loop
fade.process(delta_time, buf, area);
// Run multiple effects in parallel
let effects = fx::parallel(&[
fx::fade_from_fg(Color::Red, 500),
fx::slide_in(Direction::LeftToRight, 800),
]);
// Or sequence them
let effects = fx::sequence(&[
fx::fade_from_fg(Color::Black, 300),
fx::coalesce(500),
]);
Create effects from strings at runtime:
use tachyonfx::dsl::EffectDsl;
let effect = EffectDsl::new()
.compiler()
.compile("fx::dissolve(500)")
.expect("valid effect");
Transform colors over time for smooth transitions.
fade_from
/fade_to
β Transition colorsfade_from_fg
/fade_to_fg
β Foreground color transitionshsl_shift
β Animate through HSL color spaceterm256_colors
β Downsample to 256-color mode
Animate text and cell positions for dynamic content.
coalesce
/dissolve
β Text materialization effectsslide_in
/slide_out
β Directional sliding animationssweep_in
/sweep_out
β Color sweep transitionsexplode
β Particle dispersion effect
Fine-tune timing and behavior.
parallel
β Run multiple effects simultaneouslysequence
β Chain effects one after anotherrepeat
β Loop effects with optional limitsping_pong
β Play forward then reversewith_duration
β Override effect duration
Transform positions and layout.
translate
β Move content by offsetresize_area
β Scale effect boundstranslate_buf
β Copy and move buffer content
Apply effects selectively:
// Only apply to cells with specific colors
fx::dissolve(500)
.with_filter(CellFilter::FgColor(Color::Red))
// Target specific regions
let filter = CellFilter::AllOf(vec![
CellFilter::Outer(Margin::new(1, 1)),
CellFilter::Text,
]);
Create your own effects:
fx::effect_fn(state, timer, |state, context, cell_iter| {
// Your custom effect logic
timer.progress()
})
Alternatively, implement the Shader
trait and use it together with .into_effect()
.
The DSL supports:
- Most built-in effects (excludes:
effect_fn
,effect_fn_buf
,glitch
,offscreen_buffer
,resize_area
,translate
,translate_buf
) - Variable bindings
- Method chaining
- Complex compositions
let expr = r#"
let duration = 300;
fx::sequence(&[
fx::fade_from(black, white, duration),
fx::dissolve(duration)
])
"#;
dsl
β Effect DSL support (enabled by default)sendable
β Make effectsSend
(but notSync
)std-duration
β Usestd::time::Duration
instead of 32-bit custom typeweb-time
β WebAssembly compatibility
Contributions welcome! Please check existing issues or create new ones to discuss changes.
MIT License - see LICENSE for details.