Skip to content

junkdog/tachyonfx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

tachyonfx

Crates.io Documentation License Downloads Deps.rs

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.

demo

➑️ Try exabind - experience tachyonfx in your browser without installing anything!

✨ Features

  • 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

πŸš€ Quick Start

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(())
}

πŸ“Έ Examples

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

🎯 Getting Started

Try it in your browser

TachyonFX FTL is a browser-based editor for creating and tweaking effects in real-time.

Basic Concepts

  1. Effects are stateful β€” Create once, apply every frame
  2. Effects transform rendered content β€” Apply after widgets render
  3. Effects compose β€” Build complex animations from simple pieces

Simple Example: Fade In

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

Combining Effects

// 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),
]);

Using the DSL

Create effects from strings at runtime:

use tachyonfx::dsl::EffectDsl;

let effect = EffectDsl::new()
    .compiler()
    .compile("fx::dissolve(500)")
    .expect("valid effect");

πŸ“¦ Effect Reference

Color Effects

Transform colors over time for smooth transitions.

  • fade_from / fade_to β€” Transition colors
  • fade_from_fg / fade_to_fg β€” Foreground color transitions
  • hsl_shift β€” Animate through HSL color space
  • term256_colors β€” Downsample to 256-color mode

Text & Motion Effects

Animate text and cell positions for dynamic content.

  • coalesce / dissolve β€” Text materialization effects
  • slide_in / slide_out β€” Directional sliding animations
  • sweep_in / sweep_out β€” Color sweep transitions
  • explode β€” Particle dispersion effect

Control Effects

Fine-tune timing and behavior.

  • parallel β€” Run multiple effects simultaneously
  • sequence β€” Chain effects one after another
  • repeat β€” Loop effects with optional limits
  • ping_pong β€” Play forward then reverse
  • with_duration β€” Override effect duration

Geometry Effects

Transform positions and layout.

  • translate β€” Move content by offset
  • resize_area β€” Scale effect bounds
  • translate_buf β€” Copy and move buffer content

πŸ”§ Advanced Features

Cell Filtering

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

Custom Effects

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().

Effect DSL

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)
    ])
"#;

πŸ› οΈ Configuration

Features

  • dsl β€” Effect DSL support (enabled by default)
  • sendable β€” Make effects Send (but not Sync)
  • std-duration β€” Use std::time::Duration instead of 32-bit custom type
  • web-time β€” WebAssembly compatibility

🀝 Contributing

Contributions welcome! Please check existing issues or create new ones to discuss changes.

πŸ“ License

MIT License - see LICENSE for details.

About

shader-like effects library for ratatui applications

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •