### Run Minimal Setup Example Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Command to run the minimal setup example provided by the tachyonfx library. ```bash cargo run -p minimal ``` -------------------------------- ### Run Complete Effect Showcase Example Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Command to run the complete effect showcase example provided by the tachyonfx library. ```bash cargo run -p effect-showcase ``` -------------------------------- ### Run Basic Effects Showcase Example Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Command to run the basic effects showcase example provided by the tachyonfx library. ```bash cargo run -p basic-effects ``` -------------------------------- ### Run Tweening Examples Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Command to run the tweening examples provided by the tachyonfx library. ```bash cargo run -p tweens ``` -------------------------------- ### Rust Example: Applying All CellFilter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Demonstrates applying the CellFilter::All to an effect. ```rust use tachyonfx::{fx, CellFilter}; fx::dissolve(1000) .with_filter(CellFilter::All) ``` -------------------------------- ### Create Inline Effect Example Source: https://github.com/ratatui/tachyonfx/blob/development/docs-assets/doc-header.html A simplified API to create an inline effect example. This function sets up a container for an effect and prepares it to display DSL code on hover. ```javascript window.effectExample = async function(containerId, dslCode, ansiContent = null) { const container = document.getElementById(containerId); if (!cont ``` -------------------------------- ### Example: EffectTimer from Milliseconds Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Creates an EffectTimer with a 1000ms duration and Linear interpolation. ```rust use tachyonfx::{EffectTimer, Interpolation}; let timer = EffectTimer::from_ms(1000, Interpolation::Linear); ``` -------------------------------- ### Example: New EffectTimer Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Instantiates an EffectTimer with a 500ms duration and CubicOut interpolation. ```rust use tachyonfx::{EffectTimer, Interpolation, Duration}; let timer = EffectTimer::new( Duration::from_millis(500), Interpolation::CubicOut ); ``` -------------------------------- ### Example: Reversed EffectTimer Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Demonstrates creating a forward timer and then a new timer that runs in reverse. ```rust let forward = EffectTimer::from_ms(1000, Interpolation::Linear); let backward = forward.reversed(); ``` -------------------------------- ### Run Interactive Effect Registry Demo Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Command to run the interactive effect registry demo example provided by the tachyonfx library. ```bash cargo run -p effect-registry ``` -------------------------------- ### Example: Mirrored EffectTimer Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Shows creating an EffectTimer with QuadIn interpolation and then mirroring it, resulting in reversed direction and QuadOut interpolation. ```rust use tachyonfx::{EffectTimer, Interpolation}; let timer = EffectTimer::from_ms(1000, Interpolation::QuadIn); let mirrored = timer.mirrored(); // Reversed direction, QuadOut interpolation ``` -------------------------------- ### Example: Get Alpha Value Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Instantiates an EffectTimer and retrieves its initial alpha value, which should be 0.0. ```rust let timer = EffectTimer::from_ms(1000, Interpolation::Linear); let alpha = timer.alpha(); // Returns 0.0 at start ``` -------------------------------- ### Usage Example for EffectTimer and Effects Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Demonstrates creating an EffectTimer and using it to define visual effects like fading. Shows shorthand conversions for timer creation. ```rust use tachyonfx::{fx, EffectTimer, Interpolation, Duration}; use ratatui_core::style::Color; // Create a fade effect with custom timing let timer = EffectTimer::from_ms(800, Interpolation::CubicOut); let effect = fx::fade_to_fg(Color::Blue, timer); // Or use shorthand conversions: let effect2 = fx::fade_to_fg(Color::Red, 500); // 500ms, Linear let effect3 = fx::fade_to_fg(Color::Green, (1000, Interpolation::BounceOut)); // Multiply timer duration: let extended_timer = timer * 2; // 1600ms ``` -------------------------------- ### Rust Example: Applying RefArea CellFilter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Illustrates using CellFilter::RefArea with a RefRect, which can be updated dynamically. ```rust use tachyonfx::{fx, CellFilter, RefRect}; use ratatui_core::layout::Rect; let ref_rect = RefRect::new(Rect::new(0, 0, 10, 10)); fx::dissolve(1000) .with_filter(CellFilter::RefArea(ref_rect.clone())) ``` -------------------------------- ### HSL Interpolation Example (Default) Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Demonstrates HSL interpolation, which is the default and offers a good balance between speed and visual quality with smooth hue transitions. No explicit `ColorSpace::Hsl` setting is needed. ```rust use tachyonfx::{fx, ColorSpace, Interpolation}; use ratatui_core::style::Color; // Default - no need to specify ColorSpace::Hsl fx::fade_to_fg(Color::Blue, (1000, Interpolation::Linear)) ``` -------------------------------- ### Rust: Delay Effect with Dissolve Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Delays the start of another effect. This example delays a dissolve effect by 500 milliseconds. ```rust fx::delay(Duration::from_millis(500), fx::dissolve(1000)) ``` -------------------------------- ### Rust Example: Applying Outer CellFilter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Demonstrates using CellFilter::Outer with a Margin to target the border cells. ```rust use tachyonfx::{fx, CellFilter}; use ratatui_core::layout::Margin; fx::dissolve(1000) .with_filter(CellFilter::Outer(Margin::new(1, 1))) ``` -------------------------------- ### Check if Timer Has Started Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Returns `true` if any time has elapsed on the timer, indicating it has started. ```rust pub fn started(&self) -> bool ``` -------------------------------- ### evolve_from Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Evolves content from underlying content at the start of the effect. ```APIDOC ## evolve_from(symbols, timer) ### Description Evolves content from underlying content at the start of the effect. ### Method `evolve_from` ### Parameters #### Path Parameters - **symbols** (impl Into) - Required - Symbol set or (SymbolSet, Style) tuple. - **timer** (T: Into) - Required - Duration and interpolation for the evolve effect. ``` -------------------------------- ### Implementing Shader Process Method Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/shader.md Example implementation of the `process` method, which is called each frame to modify the terminal buffer according to the effect's logic. It handles timer-based completion and buffer cell manipulation. ```rust fn process( &mut self, duration: Duration, buf: &mut Buffer, area: Rect, ) -> Option { if let Some(remaining) = self.timer.process(duration) { self.done = true; return Some(remaining); } // Modify buffer cells for pos in area.positions() { let cell = &mut buf[pos]; // Custom effect logic } None } ``` -------------------------------- ### Repeat Effect Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Repeats a given effect a specified number of times. Ensure RepeatMode is imported. ```rust use tachyonfx::fx::RepeatMode; fx::repeat(fx::fade_to_fg(Color::Red, 500), RepeatMode::Times(3)) ``` -------------------------------- ### Wave Pattern Modulation Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/patterns.md Applies a wave pattern with both frequency and amplitude modulation. Use for dynamic, oscillating visual effects. ```rust use tachyonfx::{fx, pattern::WavePattern}; fx::dissolve(2500) .with_pattern(WavePattern::new() .with_fm_depth(0.3) .with_am_depth(0.5)) ``` -------------------------------- ### RGB Interpolation Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Shows how to use RGB color space for interpolation, which is the fastest option but may produce less visually pleasing intermediate colors. Best for performance-critical scenarios. ```rust use tachyonfx::{fx, ColorSpace, Interpolation}; use ratatui_core::style::Color; fx::fade_to_fg(Color::Red, (1000, Interpolation::Linear)) .with_color_space(ColorSpace::Rgb) ``` -------------------------------- ### Basic Ratatui App with TachyonFX Fade-In Effect Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Demonstrates a minimal Ratatui application setup that includes a simple fade-in effect using tachyonfx. This snippet shows how to initialize the terminal, create an EffectManager, add a fade effect, and process it within the render loop. Exits on any key press. ```rust 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(()) } ``` -------------------------------- ### Rust Example: Applying Inner CellFilter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Shows how to apply CellFilter::Inner with a Margin to target cells inside a border region. ```rust use tachyonfx::{fx, CellFilter}; use ratatui_core::layout::Margin; fx::fade_to_fg(Color::Yellow, 1000) .with_filter(CellFilter::Inner(Margin::new(2, 1))) ``` -------------------------------- ### Ping Pong Effect Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Plays an effect forward and then backward. This is useful for creating a back-and-forth animation. ```rust fx::ping_pong(fx::coalesce(500)) ``` -------------------------------- ### Blended Pattern Transition Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/patterns.md Blends between a radial and a sweep pattern. Use for smooth visual transitions between different pattern types. ```rust use tachyonfx::{fx, pattern::{BlendPattern, RadialPattern, SweepPattern}}; fx::dissolve(2000) .with_pattern(BlendPattern::new( RadialPattern::center(), SweepPattern::left_to_right(20) )) ``` -------------------------------- ### TachyonFX Effect Example Source: https://github.com/ratatui/tachyonfx/blob/development/docs-assets/doc-header.html Renders an interactive TachyonFX demo within a specified container. It includes tooltip functionality for displaying DSL code on hover and opens the TachyonFX-FTL playground on click. Initializes the renderer and handles potential errors. ```javascript const effectExample = async (containerId, dslCode, ansiContent = null) => { const container = document.getElementById(containerId); if (!container) { console.error(`Container ${containerId} not found`); return null; } // Create HTML structure with inline-block layout const canvasId = `${containerId}-canvas`; const codeId = `${containerId}-code`; container.className = 'tachyonfx-example'; container.innerHTML = `
`; // Create tooltip in body (not inside container) for proper fixed positioning const tooltip = document.createElement('div'); tooltip.className = 'tachyonfx-code-tooltip'; tooltip.id = codeId; tooltip.innerHTML = `${escapeHtml(dslCode)}`; document.body.appendChild(tooltip); // Position and show/hide tooltip on hover const canvasWrapper = container.querySelector('.tachyonfx-canvas-wrapper'); let isVisible = false; canvasWrapper.addEventListener('mouseenter', () => { isVisible = true; tooltip.style.visibility = 'visible'; tooltip.style.opacity = '1'; }); canvasWrapper.addEventListener('mousemove', (e) => { if (!isVisible) return; // Simple positioning: 15px offset from cursor tooltip.style.left = (e.clientX + 15) + 'px'; tooltip.style.top = (e.clientY + 15) + 'px'; }); canvasWrapper.addEventListener('mouseleave', () => { isVisible = false; tooltip.style.opacity = '0'; tooltip.style.visibility = 'hidden'; }); // Click to open in tachyonfx-ftl playground canvasWrapper.addEventListener('click', () => { const playgroundUrl = `https://junkdog.github.io/tachyonfx-ftl/?canvas_id=tfxdocs&code_raw=${encodeURIComponent(dslCode)}`; window.open(playgroundUrl, '_blank'); }); // Initialize the renderer if (!await initTachyonFX()) { container.innerHTML = '
⚠️ Live demo unavailable
'; return null; } try { const config = new RendererConfig(canvasId) .withDsl(dslCode) .withCanvas(ansiContent || SAMPLE_ANSI) .withSleepBetweenReplay(3000); const renderer = createRenderer(config); // Store renderer globally for button onclick access window[`${containerId}_renderer`] = renderer; return renderer; } catch (error) { console.error('Failed to create demo:', error); container.innerHTML = `
⚠️ Demo error: ${error.message}
`; return null; } }; ``` -------------------------------- ### Setting Color Space for Effects Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Demonstrates how to configure the color space for an effect using the `.with_color_space()` method. This example sets the color space to HSV for a fade effect. ```rust use tachyonfx::{fx, ColorSpace, Interpolation}; use ratatui_core::style::Color; fx::fade_to_fg(Color::Blue, (1000, Interpolation::Linear)) .with_color_space(ColorSpace::Hsv) ``` -------------------------------- ### Rust Example: Applying Area CellFilter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Shows how to use CellFilter::Area with a Rect to target a specific region. ```rust use tachyonfx::{fx, CellFilter}; use ratatui_core::layout::Rect; fx::dissolve(1000) .with_filter(CellFilter::Area(Rect::new(5, 10, 20, 15))) ``` -------------------------------- ### HSV Interpolation Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Illustrates using HSV color space for interpolation, providing the most vibrant colors and perceptually uniform transitions. Ideal for animations requiring maximum visual impact. ```rust use tachyonfx::{fx, ColorSpace, Interpolation}; use ratatui_core::style::Color; fx::fade_to_fg(Color::Green, (1000, Interpolation::Linear)) .with_color_space(ColorSpace::Hsv) ``` -------------------------------- ### Rust Example: Applying FgColor CellFilter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Shows how to apply CellFilter::FgColor to target cells with a specific foreground color. This is a dynamic filter. ```rust use tachyonfx::{fx, CellFilter}; use ratatui_core::style::Color; fx::dissolve(1000) .with_filter(CellFilter::FgColor(Color::Red)) ``` -------------------------------- ### Expand Geometry Effect Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Expands an effect bidirectionally from the center using block characters. Requires ExpandDirection to be imported. ```rust use tachyonfx::fx::ExpandDirection; fx::expand( ExpandDirection::Horizontal, Style::default().bg(Color::Blue), (1000, Interpolation::Linear) ) ``` -------------------------------- ### Rust Example: Applying BgColor CellFilter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Illustrates using CellFilter::BgColor to target cells with a specific background color. This is a dynamic filter. ```rust use tachyonfx::{fx, CellFilter}; use ratatui_core::style::Color; fx::fade_to_fg(Color::Blue, 1000) .with_filter(CellFilter::BgColor(Color::Black)) ``` -------------------------------- ### AllOf Filter Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Selects cells matching ALL provided filters using an AND operation. Useful for combining multiple criteria. ```rust use tachyonfx::{fx, CellFilter}; use ratatui_core::style::Color; use ratatui_core::layout::Margin; fx::dissolve(1000) .with_filter(CellFilter::AllOf(vec![ CellFilter::Text, CellFilter::Inner(Margin::new(1, 1)), CellFilter::FgColor(Color::White), ])) ``` -------------------------------- ### Rust Example: Applying EvalCell CellFilter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Illustrates using CellFilter::EvalCell with a custom closure to filter cells based on specific criteria. This is a dynamic filter. ```rust use tachyonfx::{fx, CellFilter, ref_count}; use ratatui_core::buffer::Cell; let predicate = ref_count(|cell: &Cell| { cell.symbol() == "█" }); fx::dissolve(1000) .with_filter(CellFilter::EvalCell(predicate)) ``` -------------------------------- ### Combine Effects in Parallel and Sequence Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Demonstrates how to combine multiple tachyonfx effects. The first example runs effects in parallel, while the second sequences them, executing one after the other. ```rust // Run multiple effects in parallel let effects = fx::parallel(&[ fx::fade_from_fg(Color::Red, 500), fx::sweep_in(Motion::LeftToRight, 10, 0, Color::Black, 800), ]); // Or sequence them let effects = fx::sequence(&[ fx::fade_from_fg(Color::Black, 300), fx::coalesce(500), ]); ``` -------------------------------- ### Negated Helper Method Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Demonstrates the `negated()` helper method, which is a shorthand for `CellFilter::Not`. It inverts the filter's result. ```rust CellFilter::Text.negated() // Selects non-text cells ``` -------------------------------- ### Apply Spatial Patterns to Effects Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Illustrates how to use spatial patterns to control the application of effects. Examples include a radial dissolve from the center and a diagonal fade with a specified transition width. ```rust // Radial dissolve from center let effect = fx::dissolve(800) .with_pattern(RadialPattern::center()); // Diagonal fade with transition width let effect = fx::fade_to_fg(Color::Cyan, 1000) .with_pattern( DiagonalPattern::top_left_to_bottom_right() .with_transition_width(3.0) ); ``` -------------------------------- ### Convert Terminal Colors to HSL and HSV Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Provides examples for converting a `ratatui_core::style::Color` into its HSL and HSV representations. This is useful for color manipulation and analysis. ```rust use tachyonfx::{color_to_hsl, color_to_hsv}; use ratatui_core::style::Color; let (h, s, l) = color_to_hsl(&Color::Blue); let (h, s, v) = color_to_hsv(&Color::Blue); ``` -------------------------------- ### Remap Alpha Effect Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Remaps an effect's alpha progression to a specified range. The effect to remap is provided as the last argument. ```rust fx::remap_alpha(0.1, 0.5, fx::fade_to_fg(Color::Cyan, 3000)) ``` -------------------------------- ### Text Appearance with Radial Pattern Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Demonstrates how to make text appear with a radial spread pattern, starting from the center. This creates a visually appealing effect for titles or important text. ```rust fx::coalesce(1000) .with_pattern(RadialPattern::center()) ``` -------------------------------- ### AnyOf Filter Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Selects cells matching ANY of the provided filters using an OR operation. Useful for targeting cells with one of several attributes. ```rust use tachyonfx::{fx, CellFilter}; use ratatui_core::style::Color; fx::dissolve(1000) .with_filter(CellFilter::AnyOf(vec![ CellFilter::FgColor(Color::Red), CellFilter::FgColor(Color::Yellow), ])) ``` -------------------------------- ### Rust Example: Applying Text CellFilter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Shows how to apply CellFilter::Text to target cells with alphabetic, numeric, or common punctuation characters. This is a dynamic filter. ```rust use tachyonfx::{fx, CellFilter}; fx::dissolve(1000) .with_filter(CellFilter::Text) ``` -------------------------------- ### Create Custom Effect Function Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Provides an example of creating a custom effect by defining a function that takes state, timer, and cell iterator, allowing for custom animation logic. ```rust fx::effect_fn(state, timer, |state, context, cell_iter| { // Your custom effect logic timer.progress() }) ``` -------------------------------- ### BlendPattern Creation Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/patterns.md Creates a pattern that fades from a start pattern to an end pattern over the effect's lifetime. Use for smooth transitions between two visual states. ```rust pub fn new(start: P1, end: P2) -> Self where P1: Into, P2: Into, ``` ```rust use tachyonfx::pattern::BlendPattern; fx::dissolve(2000) .with_pattern(BlendPattern::new( RadialPattern::center(), DiagonalPattern::top_left_to_bottom_right() )) ``` -------------------------------- ### delay Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Delays the start of an effect by the specified duration. ```APIDOC ## delay(duration, effect) ### Description Delays the start of an effect by the specified duration. ### Method `delay` ### Parameters #### Path Parameters - **duration** (T: Into) - Required - Delay before the effect starts. - **effect** (Effect) - Required - The effect to be delayed. ### Request Example ```rust fx::delay(Duration::from_millis(500), fx::dissolve(1000)) ``` ``` -------------------------------- ### Create Live Tachyon Demo Source: https://github.com/ratatui/tachyonfx/blob/development/docs-assets/doc-header.html Creates a live demo of TachyonFX effects within a specified container. It takes the container ID, DSL code for the effect, and optional ANSI content. Requires `initTachyonFX` to have been successfully called. ```javascript window.createTachyonDemo = async function(containerId, dslCode, ansiContent = null) { if (!await initTachyonFX()) { document.getElementById(containerId).innerHTML = '
⚠️ Live demo requires local build
'; return null; } try { const config = new RendererConfig(containerId) .withDsl(dslCode) .withCanvas(ansiContent || SAMPLE_ANSI) .withSleepBetweenReplay(3000); const renderer = createRenderer(config); return renderer; } catch (error) { console.error('Failed to create demo:', error); document.getElementById(containerId).innerHTML = `
⚠️ Demo error: ${error.message}
`; return null; } }; ``` -------------------------------- ### Get Effect Area Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect.md Retrieves the area where the effect is applied, if it has been set. ```rust pub fn area(&self) -> Option ``` -------------------------------- ### Get Total Duration Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Returns the total `Duration` configured for the EffectTimer. ```rust pub fn duration(&self) -> Duration ``` -------------------------------- ### Auto-Initialize TachyonFX Demos Source: https://github.com/ratatui/tachyonfx/blob/development/docs-assets/doc-header.html Automatically initializes all TachyonFX demos found on the page that have the `data-tachyonfx-demo` attribute. It reads DSL and ANSI content from attributes and calls `effectExample` for each demo. Initializes TachyonFX if not already done. ```javascript // Auto-initialize all demos with data-tachyonfx-demo attribute async function autoInitializeDemos() { if (!await initTachyonFX()) return; // Find all elements with data-tachyonfx-demo attribute const demoElements = document.querySelectorAll('[data-tachyonfx-demo]'); for (const element of demoElements) { const demoId = element.getAttribute('data-tachyonfx-demo'); const dslCode = element.getAttribute('data-dsl'); const ansiContent = element.getAttribute('data-ansi') || null; if (!dslCode) { console.warn(`Demo ${demoId} missing data-dsl attribute`); continue; } // Normalize multi-line DSL code const normalizedDsl = normalizeDslCode(dslCode); // Convert the element into a proper demo container element.id = `demo-${demoId}`; await effectExample(`demo-${demoId}`, normalizedDsl, ansiContent); } document.dispatchEvent(new Event('tachyonfx-ready')); } ``` -------------------------------- ### Get Remaining Duration Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Returns the `Duration` value that is still remaining on the timer. ```rust pub fn remaining(&self) -> Duration ``` -------------------------------- ### Compile a Simple Dissolve Effect Source: https://github.com/ratatui/tachyonfx/blob/development/docs/dsl.md Demonstrates how to create a new DSL compiler and compile a basic dissolve effect. Ensure the 'dsl' feature is enabled. ```rust use tachyonfx::dsl::EffectDsl; // Create a new DSL compiler with all standard effects registered let dsl = EffectDsl::new(); // Compile a simple dissolve effect let effect = dsl.compiler() .compile("fx::dissolve(500)") .expect("Valid effect"); ``` -------------------------------- ### Get Effect Color Space Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect.md Retrieves the color space used for interpolation by the effect. ```rust pub fn color_space(&self) -> ColorSpace ``` -------------------------------- ### Get Effect Name Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect.md Retrieves the static string name of the underlying shader for the effect. ```rust pub fn name(&self) -> &'static str ``` -------------------------------- ### DOM Ready Initialization Source: https://github.com/ratatui/tachyonfx/blob/development/docs-assets/doc-header.html Ensures that TachyonFX demos are automatically initialized once the DOM is fully loaded. If the DOM is already ready, it calls the initialization function immediately. ```javascript // Auto-initialize demos when DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', autoInitializeDemos); } else { autoInitializeDemos(); } ``` -------------------------------- ### Get Effect Cell Filter Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect.md Retrieves the effect's cell filter, if one has been set. ```rust pub fn cell_filter(&self) -> Option<&CellFilter> ``` -------------------------------- ### Chain Effect Methods for Configuration Source: https://github.com/ratatui/tachyonfx/blob/development/docs/dsl.md Demonstrates chaining methods like .with_filter(), .with_area(), and .with_color_space() directly onto an effect in the DSL. This allows for fluent configuration of effect properties. ```rust let effect = dsl.compiler().compile(r#" fx::dissolve(1000) .with_filter(CellFilter::Text) .with_area(Rect::new(10, 10, 20, 5)) .with_color_space(ColorSpace::Hsv) "#).expect("Valid effect"); ``` -------------------------------- ### Create Complex Wave Patterns Source: https://github.com/ratatui/tachyonfx/blob/development/docs/dsl.md Shows how to build a complex wave pattern by combining oscillators and modulators using WaveLayer methods. ```rust WavePattern::new( WaveLayer::new(Oscillator::sin(2.0, 0.0, 1.0)) .multiply(Oscillator::cos(0.0, 3.0, 0.5).modulated_by( Modulator::sin(1.0, 1.0, 0.25).intensity(0.5) )) .amplitude(0.8) ).with_contrast(2) ``` -------------------------------- ### Configure Radial and Spiral Patterns Source: https://github.com/ratatui/tachyonfx/blob/development/docs/dsl.md Demonstrates method chaining for configuring transition width and center for RadialPattern, and arms for SpiralPattern. ```rust RadialPattern::center() .with_transition_width(2.5) .with_center(0.3, 0.7) SpiralPattern::center() .with_arms(6) .with_transition_width(1.5) ``` -------------------------------- ### Layout Filter Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Selects cells based on their position within the layout grid, such as even or odd columns/rows. ```rust use tachyonfx::{fx, CellFilter, LayoutKind}; fx::dissolve(1000) .with_filter(CellFilter::Layout(LayoutKind::EvenColumns)) ``` -------------------------------- ### Combine Effects using Sequence Source: https://github.com/ratatui/tachyonfx/blob/development/docs/dsl.md Shows how to combine multiple effects into a sequence using fx::sequence(). The effects will run one after another in the order they appear in the array. ```rust use tachyonfx::dsl::EffectDsl; let dsl = EffectDsl::new(); let effect = dsl.compiler().compile(r#" fx::sequence(&[ fx::dissolve(300), fx::fade_to_fg(Color::Red, 500), fx::fade_to_fg(Color::Blue, 500) ]) "#).expect("Valid effect"); ``` -------------------------------- ### EvalPos Filter Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Selects cells matching a custom position-based predicate. This is a dynamic filter evaluated per-frame. ```rust use tachyonfx::{fx, CellFilter, ref_count}; use ratatui_core::layout::Position; let predicate = ref_count(|pos: Position| { (pos.x + pos.y) % 2 == 0 // Checkerboard pattern }); fx::dissolve(1000) .with_filter(CellFilter::EvalPos(predicate)) ``` -------------------------------- ### Apply Animated Color Transitions Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Creates animated color transitions for foreground, background, or both, with specified durations and interpolation. Requires importing `fx` from tachyonfx. ```rust fx::fade_to_fg(Color::Cyan, (1000, Interpolation::Linear)) fx::fade_from_fg(Color::Black, 500) fx::fade_to(Color::Red, Color::Black, 1000) fx::fade_from(Color::White, Color::White, 500) ``` -------------------------------- ### Create Colors from HSL Values Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Demonstrates how to create `Color` objects from Hue, Saturation, and Lightness (HSL) values. This is useful for generating specific colors programmatically. ```rust use tachyonfx::color_from_hsl; let cyan = color_from_hsl(180.0, 100.0, 50.0); let red = color_from_hsl(0.0, 100.0, 50.0); let gray = color_from_hsl(0.0, 0.0, 50.0); ``` -------------------------------- ### Delay Effect Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Creates an effect that waits for a specified duration before starting another effect. Requires importing `fx` from tachyonfx. ```rust fx::delay(500, fx::dissolve(1000)) ``` -------------------------------- ### Register and Use Custom DSL Effects Source: https://github.com/ratatui/tachyonfx/blob/development/docs/dsl.md Demonstrates how to extend the DSL by registering custom effects. This involves providing a compiler function that takes arguments and returns an effect. ```rust use tachyonfx::dsl::{EffectDsl, Arguments, DslError}; use tachyonfx::{fx, Effect}; use ratatui::style::Color; let dsl = EffectDsl::new() .register("color_pulse", | args: &mut Arguments| { let color = args.color()?; let duration = args.read_u32()?; Ok(fx::sequence(&[ fx::fade_from_fg(color, duration / 2), fx::fade_to_fg(color, duration / 2) ])) }); // Use the custom effect let effect = dsl.compiler().compile(r#" fx::color_pulse(Color::Blue, 1000) "#).expect("Valid effect"); ``` -------------------------------- ### Instantly Paint Both Colors Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Instantly sets both foreground and background colors without any animation. ```Rust fx::paint(Color::Red, Color::Blue, 500) ``` -------------------------------- ### Not Filter Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Inverts the result of a single filter using a NOT operation. Useful for selecting cells that do NOT meet a specific criterion. ```rust use tachyonfx::{fx, CellFilter}; fx::dissolve(1000) .with_filter(CellFilter::Not(CellFilter::Text.into())) ``` -------------------------------- ### Create Basic Fade Effect Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Creates a basic fade-to-foreground color effect with a specified duration and linear interpolation. Requires importing `fx` and `EffectManager` from tachyonfx, and `Color` from ratatui_core. ```rust use tachyonfx::{fx, EffectManager}; use ratatui_core::style::Color; let effect = fx::fade_to_fg(Color::Blue, 1000); // 1 second, Linear interpolation ``` -------------------------------- ### Initialize TachyonFX Renderer Source: https://github.com/ratatui/tachyonfx/blob/development/docs-assets/doc-header.html Initializes the TachyonFX WebGL2 renderer. It first attempts to load from a local build and falls back to a CDN if the local build is unavailable. This function must be called before creating any renderers. ```javascript let tachyonModule = null; let createRenderer = null; let RendererConfig = null; async function initTachyonFX() { if (tachyonModule) return true; const paths = getRendererPath(); try { console.log('🔍 Loading TachyonFX renderer from local build...'); const module = await import(paths.local); await module.default(); tachyonModule = module; createRenderer = module.createRenderer; RendererConfig = module.RendererConfig; console.log('✅ TachyonFX renderer initialized (local)'); return true; } catch (localError) { try { const module = await import(paths.cdn); await module.default(); tachyonModule = module; createRenderer = module.createRenderer; RendererConfig = module.RendererConfig; return true; } catch (cdnError) { console.warn('⚠️ TachyonFX renderer not available'); console.warn(' Local:', localError.message); console.warn(' CDN:', cdnError.message); return false; } } } ``` -------------------------------- ### Create Colors from HSV Values Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Shows how to create `Color` objects from Hue, Saturation, and Value (HSV) values. This provides an alternative method for generating colors based on different color space parameters. ```rust use tachyonfx::color_from_hsv; let bright_cyan = color_from_hsv(180.0, 100.0, 100.0); let dark_red = color_from_hsv(0.0, 100.0, 50.0); ``` -------------------------------- ### Use Let Bindings within DSL Expressions Source: https://github.com/ratatui/tachyonfx/blob/development/docs/dsl.md Illustrates using 'let' bindings directly within the DSL string to define intermediate variables like colors and timers. This allows for more complex inline definitions. ```rust let effect = dsl.compiler().compile(r#" let color = Color::from_u32(0xff5500); let timer = (500, CircOut); fx::fade_to_fg(color, timer) "#).expect("Valid effect"); ``` -------------------------------- ### Get EffectTimer Alpha Value Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Computes and returns the current interpolated alpha value (0.0 to 1.0) based on elapsed time. ```rust pub fn alpha(&self) -> f32 ``` -------------------------------- ### NoneOf Filter Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Selects cells matching NONE of the provided filters using a NOR operation. Useful for excluding cells with specific attributes. ```rust use tachyonfx::{fx, CellFilter}; use ratatui_core::style::Color; fx::dissolve(1000) .with_filter(CellFilter::NoneOf(vec![ CellFilter::FgColor(Color::Black), ])) ``` -------------------------------- ### Standard Timing Control for Effects Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Demonstrates various ways to control effect timing, including simple milliseconds, tuples with interpolation, and explicit `EffectTimer` objects with custom durations and interpolations. Requires importing `EffectTimer`, `Duration`, and `Interpolation`. ```rust // Milliseconds (linear interpolation) fx::dissolve(1000) // With interpolation fx::dissolve((1000, Interpolation::BounceOut)) // Explicit timer use tachyonfx::{EffectTimer, Duration}; fx::dissolve(EffectTimer::new( Duration::from_secs(2), Interpolation::CubicInOut )) ``` -------------------------------- ### Instantly Paint Background Color Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Instantly sets the background color without any animation. ```Rust fx::paint_bg(Color::White, 500) ``` -------------------------------- ### Create Custom Effect with a Buffer Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Shows how to implement a custom effect by operating on a buffer, which represents a rectangular area of the terminal. This approach is efficient for effects that apply transformations to regions rather than individual cells. ```rust fx::effect_fn_buf((), 1000, |_state, _ctx, buf| { for pos in buf.area.positions() { let cell = &mut buf[pos]; cell.set_fg(Color::Yellow); } }) ``` -------------------------------- ### Get Mutable Effect Timer Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect.md Retrieves a mutable reference to the effect's timer, allowing modification. Returns None if the effect does not have a timer. ```rust pub fn timer_mut(&mut self) -> Option<&mut EffectTimer> ``` ```rust if let Some(timer) = effect.timer_mut() { timer.reset(); } ``` -------------------------------- ### Add tachyonfx Dependency Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Add the tachyonfx crate to your project's Cargo.toml file. ```bash cargo add tachyonfx ``` -------------------------------- ### Get Effect Timer Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect.md Retrieves the effect's timer if it is a timed effect. For composite effects, this may return an approximation of the total duration. ```rust pub fn timer(&self) -> Option ``` -------------------------------- ### Complex Combined Pattern Example Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/patterns.md Combines radial and diagonal patterns using multiplication. Use for intricate visual effects requiring layered logic. ```rust use tachyonfx::{fx, pattern::{CombinedPattern, PatternOp, RadialPattern, DiagonalPattern}}; fx::coalesce(1500) .with_pattern(CombinedPattern::new( RadialPattern::center(), PatternOp::Multiply, DiagonalPattern::bottom_right_to_top_left() )) ``` -------------------------------- ### Create and Configure a Fade-In Effect Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Shows how to create a fade-in effect with a specified duration and easing function, and then apply a cell filter to target specific cells (e.g., only red foreground color). ```rust // 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); ``` -------------------------------- ### Color Transformation with HSL Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Get a color's HSL values, modify them, and create new colors. This is useful for desaturating or darkening existing colors. ```rust use tachyonfx::{fx, color_from_hsl, color_to_hsl}; use ratatui_core::style::Color; // Get a color's HSL and modify it let original = Color::Red; let (h, s, l) = color_to_hsl(&original); // Create a desaturated version let desaturated = color_from_hsl(h, s * 0.5, l); // Create a darker version let darker = color_from_hsl(h, s, l * 0.7); // Use in effects let effect = fx::fade_to_fg(desaturated, 1000); ``` -------------------------------- ### paint Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effects.md Instantly sets both the foreground and background colors of a terminal cell without animation. ```APIDOC ## paint(fg, bg, timer) ### Description Instantly paints both foreground and background colors. ### Method ```rust pub fn paint, C: Into>(fg: C, bg: C, timer: T) -> Effect ``` ### Parameters #### Path Parameters - **fg** (C: Into) - Required - The foreground color to paint - **bg** (C: Into) - Required - The background color to paint - **timer** (T: Into) - Required - Duration and interpolation ``` -------------------------------- ### Custom Checkerboard Filter (Revisited) Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/cell-filter.md Reiterates the custom checkerboard pattern using EvalPos, demonstrating dynamic filtering based on cell position. ```rust use tachyonfx::{fx, CellFilter, ref_count}; use ratatui_core::layout::Position; fx::dissolve(1000) .with_filter(CellFilter::EvalPos(ref_count(|pos: Position| { (pos.x + pos.y) % 2 == 0 }))) ``` -------------------------------- ### HSV to Color Conversion Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Converts HSV color components (hue, saturation, value) into a ratatui Color. Examples show creating bright and dark cyan. ```rust use tachyonfx::color_from_hsv; // Bright cyan let bright_cyan = color_from_hsv(180.0, 100.0, 100.0); // Darker cyan let dark_cyan = color_from_hsv(180.0, 100.0, 50.0); ``` -------------------------------- ### Basic and Power Curve Easing Functions Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/quick-reference.md Demonstrates the usage of basic linear and reverse interpolations, as well as various power curves (Quad, Cubic, Quart, Quint) for animation easing. These functions control the rate of change in an animation. ```rust use tachyonfx::Interpolation; // Basic Interpolation::Linear, Interpolation::Reverse // Power curves Interpolation::QuadIn, Interpolation::QuadOut, Interpolation::QuadInOut Interpolation::CubicIn, Interpolation::CubicOut, Interpolation::CubicInOut Interpolation::QuartIn, Interpolation::QuartOut, Interpolation::QuartInOut Interpolation::QuintIn, Interpolation::QuintOut, Interpolation::QuintInOut ``` -------------------------------- ### Modify Terminal Cells with CellIterator Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/types.md Iterates over terminal cells within a buffer, allowing for per-cell modifications. This example demonstrates setting the foreground color of all cells to red. ```rust use tachyonfx::fx; use ratatui_core::style::Color; fx::effect_fn((), 1000, |_state, _ctx, cell_iter| { for (_pos, cell) in cell_iter { cell.set_fg(Color::Red); } }) ``` -------------------------------- ### Create Effect from String DSL Source: https://github.com/ratatui/tachyonfx/blob/development/README.md Demonstrates how to create an effect by compiling a string expression using the EffectDsl. This is useful for creating effects at runtime. ```rust use tachyonfx::dsl::EffectDsl; let effect = EffectDsl::new() .compiler() .compile("fx::dissolve(500)") .expect("valid effect"); ``` -------------------------------- ### Effect::new Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect.md Creates a new Effect instance, wrapping a given shader implementation. This is the fundamental constructor for effects. ```APIDOC ## Effect::new(shader) ### Description Creates a new `Effect` with the specified shader. ### Method `Effect::new` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use tachyonfx::{Effect, Shader}; // Typically created via fx:: constructors instead of directly let effect = Effect::new(some_shader_impl); ``` ### Response #### Success Response - **Self** (Effect) - A new Effect instance. #### Response Example None provided. ``` -------------------------------- ### Color to HSV Conversion Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Converts a ratatui Color into its HSV components (hue, saturation, value). The example demonstrates converting Color::Blue and printing the resulting HSV values. ```rust use tachyonfx::color_to_hsv; use ratatui_core::style::Color; let (h, s, v) = color_to_hsv(&Color::Blue); println!("Blue in HSV: h={}, s={}, v={}", h, s, v); // Output: Blue in HSV: h=240, s=100, v=100 ``` -------------------------------- ### Create WavePattern Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/patterns.md Creates a basic wave interference pattern. Use for effects that simulate wave-like progressions or interference. ```rust fx::dissolve(2000) .with_pattern(WavePattern::new()) ``` -------------------------------- ### Color to HSL Conversion Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Converts a ratatui Color into its HSL components (hue, saturation, lightness). The example demonstrates converting Color::Red and printing the resulting HSL values. ```rust use tachyonfx::color_to_hsl; use ratatui_core::style::Color; let (h, s, l) = color_to_hsl(&Color::Red); println!("Red in HSL: h={}, s={}, l={}", h, s, l); // Output: Red in HSL: h=0, s=100, l=50 ``` -------------------------------- ### Create EffectTimer with Duration and Interpolation Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/effect-timer.md Use this constructor to create a new EffectTimer with a specific total duration and an easing function. ```rust pub fn new(duration: Duration, interpolation: Interpolation) -> Self ``` -------------------------------- ### Dynamic Color Construction with Sequence Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Create a smooth hue shift animation by sequencing color fades. Each color is defined using HSL values. ```rust use tachyonfx::{fx, color_from_hsl, Interpolation}; // Create a smooth hue shift animation let effect = fx::sequence(&[ fx::fade_to_fg(color_from_hsl(0.0, 100.0, 50.0), 500), // Red fx::fade_to_fg(color_from_hsl(60.0, 100.0, 50.0), 500), // Yellow fx::fade_to_fg(color_from_hsl(120.0, 100.0, 50.0), 500), // Green fx::fade_to_fg(color_from_hsl(240.0, 100.0, 50.0), 500), // Blue ]); ``` -------------------------------- ### HSL to Color Conversion Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/color-space.md Converts HSL color components (hue, saturation, lightness) into a ratatui Color. Examples show creating pure cyan, muted red, and gray. ```rust use tachyonfx::color_from_hsl; // Pure cyan let cyan = color_from_hsl(180.0, 100.0, 50.0); // Red with 70% saturation and 45% lightness let muted_red = color_from_hsl(0.0, 70.0, 45.0); // Gray (desaturated color) let gray = color_from_hsl(0.0, 0.0, 50.0); ``` -------------------------------- ### Implementing Shader Name Source: https://github.com/ratatui/tachyonfx/blob/development/_autodocs/api-reference/shader.md Provides a concrete implementation for the `name` method, returning a static string literal for the shader's display name. ```rust fn name(&self) -> &'static str { "my_custom_effect" } ```