### RefRect sharing example Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/ref_rect.rs.html Shows how to create a RefRect, clone it for sharing, update it with set(), and verify that all clones see the update via get(). ```rust use tachyonfx::RefRect; use ratatui_core::layout::Rect; let ref_rect = RefRect::new(Rect::new(0, 0, 10, 5)); // Multiple components can share the same area reference let shared_rect = ref_rect.clone(); // Update the area from one component ref_rect.set(Rect::new(5, 5, 20, 10)); // All sharing components see the update assert_eq!(shared_rect.get(), Rect::new(5, 5, 20, 10)); ``` -------------------------------- ### Quick Start: use tachyonfx::dsl::CompletionEngine Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/dsl/completions/mod.rs.html Shows the basic usage of the CompletionEngine: create an engine, pass source text and cursor position, and iterate over completion items. The example prints each item's label and detail. Requires the DSL feature. ```rust use tachyonfx::dsl::CompletionEngine; let engine = CompletionEngine::new(); // Get completions at cursor position let source = "fx::fade"; let cursor_pos = source.len() as u32; let completions = engine.completions(source, cursor_pos); // Filter to effects starting with "fade" for item in completions { println!("{}: {}", item.label, item.detail); } ``` -------------------------------- ### Example: prolong_start with fade_from_fg Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.prolong_start.html Example usage that creates a color, timer, and calls `prolong_start` with a 1000ms delay and a fade effect. The example is shown in two forms: a multi-line block and a single-line expression. ```rust use ratatui::prelude::Color; use tachyonfx::{fx, Interpolation}; let c = Color::from_u32(0x504945); let timer = (500, Interpolation::CircOut); fx::prolong_start(1000, fx::fade_from_fg(c, timer)); ``` ```rust let c = Color::from_u32(0x504945); let timer = (500, Interpolation::CircOut); fx::prolong_start(1000, fx::fade_from_fg(c, timer)) ``` -------------------------------- ### slide_in inline example Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.slide_in.html Inline example of `slide_in` with the same parameters as the previous example, shown in a single line. ```rust let c = Color::from_u32(0xffaf00); let timer = (1000, Interpolation::Linear); fx::slide_in(Motion::UpToDown, 5, 0, c, timer) ``` -------------------------------- ### Inline example of fade_from_fg Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.fade_from_fg.html A one-line version of the example, showing the same call to `fade_from_fg` with the color and timer arguments. ```rust let c = Color::from_u32(0x504945); fx::fade_from_fg(c, (1000, Interpolation::QuadInOut)) ``` -------------------------------- ### Inline example of fade_to_fg Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.fade_to_fg.html A one-line version of the example, showing the same usage in a compact form. ```rust `let c = Color::from_u32(0x504945); fx::fade_to_fg(c, (1000, Interpolation::CircOut))` ``` -------------------------------- ### Inline example of fx::expand Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.expand.html A compact inline version of the expand example, showing the same call without imports. ```rust fx::expand( ExpandDirection::Horizontal, Style::default().bg(Color::Blue), (1000, Interpolation::Linear) ) ``` -------------------------------- ### Inline fx::dissolve example Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.dissolve.html A concise inline example of calling `fx::dissolve(1000)`. ```rust `fx::dissolve(1000)` ``` -------------------------------- ### fade_to inline example Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.fade_to.html Inline version of the usage example, showing the same call in a single line. ```rust let c = Color::from_u32(0x1d2021); fx::fade_to(c, c, (1000, Interpolation::CircOut)) ``` -------------------------------- ### darken usage examples Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.darken.html Examples showing how to darken both foreground and background colors, and how to apply a sweep pattern. The first example uses a simple duration, the second uses a pattern. ```rust use tachyonfx::fx; use tachyonfx::pattern::SweepPattern; // darken both fg and bg fx::darken(Some(0.5), Some(0.3), 1000); // darken with a sweep pattern fx::darken(Some(0.5), None, 1000) .with_pattern(SweepPattern::left_to_right(25)); ``` -------------------------------- ### Inline Repeat Example Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.repeat.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E A one-liner example showing how to create a fade effect and repeat it three times using `fx::repeat`. ```rust `let fade = fx::fade_to_fg(Color::Red, (1000, Interpolation::CubicOut)); fx::repeat(fade, RepeatMode::Times(3))` ``` -------------------------------- ### fx::freeze_at Rust example Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/fx/mod.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Rust example for freeze_at, showing how to create a dissolve effect and freeze it at alpha 0.5. ```rust use tachyonfx::fx; let fade_effect = fx::dissolve(1000); fx::freeze_at(0.5, false, fade_effect); ``` -------------------------------- ### Inline example of hsl_shift_fg Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.hsl_shift_fg.html A compact version of the example, showing the same logic in a single line for quick reference. ```rust let timer = (1000, Interpolation::Linear); let fg_shift = [120.0, 25.0, 25.0]; fx::hsl_shift(Some(fg_shift), None, timer) ``` -------------------------------- ### expand usage example Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/fx/mod.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example usage of the expand function with a horizontal direction, blue background style, and linear interpolation over 1000ms. ```rust use ratatui_core::style::{Color, Style}; use tachyonfx::{fx, fx::ExpandDirection, Interpolation}; fx::expand( ExpandDirection::Horizontal, Style::default().bg(Color::Blue), (1000, Interpolation::Linear) ); ``` -------------------------------- ### Check if timer has started Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/effect_timer.rs.html?search= Example usage of the `started` method. Creates a timer with 1000ms and asserts it has not started. ```rust let timer = EffectTimer::from_ms(1000, Interpolation::Linear); assert!(!timer.started()); ``` -------------------------------- ### Example: Using the process method Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/shader.rs.html?search=u32+-%3E+bool Shows how to call the `process` method on a shader instance with a duration, buffer, and area. The example creates a shader, defines a 10x10 area, creates an empty buffer, and processes the shader for 100 milliseconds, capturing any overflow duration. ```rust use tachyonfx::Duration; use ratatui_core::buffer::Buffer; use ratatui_core::layout::Rect; let mut shader = MyShader::new(); let area = Rect::new(0, 0, 10, 10); let mut buffer = Buffer::empty(area); let overflow = shader.process(Duration::from_millis(100), &mut buffer, area); ``` -------------------------------- ### dispatch_event usage example Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/fx/mod.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates an effect that sends an event when it starts. Useful for coordinating visual effects with application logic. The example shows combining it with other effects in a sequence. ```rust use std::sync::mpsc; use tachyonfx::{fx, Effect}; #[derive(Clone, Debug)] #[allow(dead_code)] enum AppEvent { EffectStarted, EffectCompleted, } let (tx, rx) = mpsc::channel(); // Create an effect that sends an event when it starts let notify_effect = fx::dispatch_event(tx.clone(), AppEvent::EffectStarted); // Combine with other effects in a sequence let sequence = fx::sequence(&[ notify_effect, fx::fade_to_fg(ratatui_core::style::Color::Red, 1000), fx::dispatch_event(tx, AppEvent::EffectCompleted), ]); ``` -------------------------------- ### Get mutable reference with Rc::get_mut Source: https://docs.rs/tachyonfx/latest/tachyonfx/type.RefCount.html?search= Example showing how to use Rc::get_mut to get a mutable reference when there are no other Rc or Weak pointers. Demonstrates that it returns None when other Rc pointers exist. ```rust use std::rc::Rc; let mut x = Rc::new(3); *Rc::get_mut(&mut x).unwrap() = 4; assert_eq!(*x, 4); let _y = Rc::clone(&x); assert!(Rc::get_mut(&mut x).is_none()); ``` -------------------------------- ### CompletionEngine usage example Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/dsl/completions/engine.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to create a CompletionEngine and request completions for various DSL inputs. The first call returns all effect constructors, the second returns Rect instance methods, and the third returns fuzzy-matched color variants. ```rust use tachyonfx::dsl::CompletionEngine; let engine = CompletionEngine::new(); // Complete at top level let completions = engine.completions("fx::", 4); // Returns all effect constructors: dissolve, fade_to, sweep_in, etc. // Complete method chains let completions = engine.completions("Rect::new(0, 0, 10, 10).", 24); // Returns Rect instance methods: inner, intersection, union, etc. // Complete with partial input let completions = engine.completions("Color::R", 8); // Returns: Red, Rgb, Fuzzy (fuzzy matched) ``` -------------------------------- ### Unsafe mutable access with Rc::get_mut_unchecked (valid example) Source: https://docs.rs/tachyonfx/latest/tachyonfx/type.RefCount.html?search= Example showing how to use the unsafe Rc::get_mut_unchecked to get a mutable reference without checks. Requires the get_mut_unchecked feature. Demonstrates pushing a string to an Rc. ```rust #![feature(get_mut_unchecked)] use std::rc::Rc; let mut x = Rc::new(String::new()); unsafe { Rc::get_mut_unchecked(&mut x).push_str("foo") } assert_eq!(*x, "foo"); ``` -------------------------------- ### EffectTimer creation examples Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/effect_timer.rs.html Shows equivalent ways to create an EffectTimer using new, from_ms, and From conversions. ```rust use tachyonfx::{Duration, EffectTimer, Interpolation}; // timers a, b, c and d are equivalent let a = EffectTimer::new(Duration::from_millis(500), Interpolation::Linear); let b = EffectTimer::from_ms(500, Interpolation::Linear); let c: EffectTimer = 500.into(); let d: EffectTimer = (500, Interpolation::Linear).into(); ``` -------------------------------- ### CompletionEngine::new() with empty source Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/dsl/completions/engine.rs.html?search= Example for the new() method, showing that a newly created engine returns non-empty completions even with an empty source string. This is used in the documentation for the constructor. ```rust use tachyonfx::dsl::CompletionEngine; let engine = CompletionEngine::new(); let completions = engine.completions("", 0); assert!(!completions.is_empty()); ``` -------------------------------- ### dispatch_event function signature and usage example Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.dispatch_event.html The function signature shows the required trait bounds for the event type: Clone, Debug, ThreadSafetyMarker, and 'static. The example demonstrates creating an effect that sends an AppEvent through an mpsc channel when started, and combining it with other effects in a sequence. ```rust pub fn dispatch_event(sender: Sender, event: T) -> Effect where T: Clone + Debug + ThreadSafetyMarker + 'static, ``` ```rust use std::sync::mpsc; use tachyonfx::{fx, Effect}; #[derive(Clone, Debug)] enum AppEvent { EffectStarted, EffectCompleted, } let (tx, rx) = mpsc::channel(); // Create an effect that sends an event when it starts let notify_effect = fx::dispatch_event(tx.clone(), AppEvent::EffectStarted); // Combine with other effects in a sequence let sequence = fx::sequence(&[ notify_effect, fx::fade_to_fg(ratatui_core::style::Color::Red, 1000), fx::dispatch_event(tx, AppEvent::EffectCompleted), ]); ``` -------------------------------- ### InvertedPattern usage example Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/pattern/inverted.rs.html Shows how to create an InvertedPattern wrapping a RadialPattern::center() so the radial pattern starts active at the edges and reveals toward the center. ```rust use tachyonfx::pattern::{InvertedPattern, RadialPattern}; // radial pattern that starts active at the edges and reveals toward center let pattern = InvertedPattern::new(RadialPattern::center()); ``` -------------------------------- ### dispatch_event usage example Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/fx/mod.rs.html?search= Shows how to create an effect that sends an event when it starts, using std::sync::mpsc. The effect is combined in a sequence with fade_to_fg and another dispatch_event. Requires the 'std' feature. ```rust use std::sync::mpsc; use tachyonfx::{fx, Effect}; #[derive(Clone, Debug)] enum AppEvent { EffectStarted, EffectCompleted, } let (tx, rx) = mpsc::channel(); // Create an effect that sends an event when it starts let notify_effect = fx::dispatch_event(tx.clone(), AppEvent::EffectStarted); // Combine with other effects in a sequence let sequence = fx::sequence(&[ notify_effect, fx::fade_to_fg(ratatui_core::style::Color::Red, 1000), fx::dispatch_event(tx, AppEvent::EffectCompleted), ]); ``` -------------------------------- ### Usage example for SimpleRng Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/simple_rng.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to create a SimpleRng with a seed and generate random u32 and f32 values. The example prints the generated values. ```rust use tachyonfx::SimpleRng; let mut rng = SimpleRng::new(12345); let random_u32 = rng.gen(); let random_float = rng.gen_f32(); println!("u32={} f32={}", random_u32, random_float); ``` -------------------------------- ### Count strong pointers with Rc::strong_count Source: https://docs.rs/tachyonfx/latest/tachyonfx/type.RefCount.html?search= Example showing how to use Rc::strong_count to get the number of strong (Rc) pointers to an allocation. Creates an Rc, clones it, and asserts the count is 2. ```rust use std::rc::Rc; let five = Rc::new(5); let _also_five = Rc::clone(&five); assert_eq!(2, Rc::strong_count(&five)); ``` -------------------------------- ### Example: Rc::into_raw and Rc::from_raw Source: https://docs.rs/tachyonfx/latest/tachyonfx/type.RefCount.html?search= Demonstrates converting an Rc to a raw pointer and back, with a strong count check. ```rust use std::rc::Rc; let x = Rc::new("hello".to_owned()); let x_ptr = Rc::into_raw(x); assert_eq!(unsafe { &*x_ptr }, "hello"); ``` -------------------------------- ### Count weak pointers with Rc::weak_count Source: https://docs.rs/tachyonfx/latest/tachyonfx/type.RefCount.html?search= Example showing how to use Rc::weak_count to get the number of Weak pointers to an allocation. Creates an Rc, downgrades it to a Weak, and asserts the count is 1. ```rust use std::rc::Rc; let five = Rc::new(5); let _weak_five = Rc::downgrade(&five); assert_eq!(1, Rc::weak_count(&five)); ``` -------------------------------- ### Rc::new_in example Source: https://docs.rs/tachyonfx/latest/tachyonfx/type.RefCount.html?search= Shows how to construct an Rc in a provided allocator using the nightly allocator_api feature. The example creates an Rc in the System allocator. ```rust #![feature(allocator_api)] use std::rc::Rc; use std::alloc::System; let five = Rc::new_in(5, System); ``` -------------------------------- ### Increment strong count with Rc::increment_strong_count_in Source: https://docs.rs/tachyonfx/latest/tachyonfx/type.RefCount.html?search= Example showing how to use the unsafe Rc::increment_strong_count_in with a custom allocator. Requires the allocator_api feature. Demonstrates incrementing the strong count and then using from_raw_in to get a new Rc. ```rust #![feature(allocator_api)] use std::rc::Rc; use std::alloc::System; let five = Rc::new_in(5, System); unsafe { let (ptr, _alloc) = Rc::into_raw_with_allocator(five); Rc::increment_strong_count_in(ptr, System); let five = Rc::from_raw_in(ptr, System); assert_eq!(2, Rc::strong_count(&five)); Rc::decrement_strong_count_in(ptr, System); assert_eq!(1, Rc::strong_count(&five)); } ``` -------------------------------- ### Rc::as_ptr - Get raw pointer to data Source: https://docs.rs/tachyonfx/latest/tachyonfx/type.RefCount.html?search= Provides a raw pointer to the data without affecting reference counts. The pointer remains valid as long as strong counts exist. The example shows that two Rc clones share the same pointer. ```rust use std::rc::Rc; let x = Rc::new(0); let y = Rc::clone(&x); let x_ptr = Rc::as_ptr(&x); assert_eq!(x_ptr, Rc::as_ptr(&y)); assert_eq!(unsafe { *x_ptr }, 0); ``` -------------------------------- ### paint example Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/fx/mod.rs.html?search= Paints the foreground and background colors immediately without animation. The example applies Cyan foreground and DarkGray background for 1000ms. ```rust use ratatui::prelude::Color; use tachyonfx::fx; fx::paint(Color::Cyan, Color::DarkGray, 1000); ``` -------------------------------- ### Rc::new_uninit_in example Source: https://docs.rs/tachyonfx/latest/tachyonfx/type.RefCount.html?search= Demonstrates constructing an Rc with uninitialized contents in a provided allocator using nightly features. The example initializes the value manually and then assumes it is initialized. ```rust #![feature(get_mut_unchecked)] #![feature(allocator_api)] use std::rc::Rc; use std::alloc::System; let mut five = Rc::::new_uninit_in(System); let five = unsafe { // Deferred initialization: Rc::get_mut_unchecked(&mut five).as_mut_ptr().write(5); five.assume_init() }; assert_eq!(*five, 5) ``` -------------------------------- ### Basic CompletionEngine usage Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/dsl/completions/engine.rs.html?search= Shows basic usage of the CompletionEngine: creating an engine and calling completions() with different source strings and cursor positions to get context-aware suggestions. The comments indicate expected results for top-level, method chain, and partial input cases. ```rust use tachyonfx::dsl::CompletionEngine; let engine = CompletionEngine::new(); // Complete at top level let completions = engine.completions("fx::", 4); // Returns all effect constructors: dissolve, fade_to, sweep_in, etc. // Complete method chains let completions = engine.completions("Rect::new(0, 0, 10, 10).", 24); // Returns Rect instance methods: inner, intersection, union, etc. // Complete with partial input let completions = engine.completions("Color::R", 8); // Returns: Red, Rgb, Reset (fuzzy matched) ``` -------------------------------- ### started Source: https://docs.rs/tachyonfx/latest/tachyonfx/struct.EffectTimer.html Checks if the timer has started. ```APIDOC ## started ### Description Checks if the timer has started. ### Method started ### Signature pub fn started(&self) -> bool ### Returns - `true` if the timer has started, `false` otherwise. ### Example ```rust use tachyonfx::{EffectTimer, Interpolation}; let timer = EffectTimer::from_ms(1000, Interpolation::Linear); assert!(!timer.started()); ``` ``` -------------------------------- ### Inline example: evolve with RadialPattern (one-liner) Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.evolve.html Inline version of the evolve example, showing the same code in a single line. It is provided as an alternative representation. ```rust let p = RadialPattern::center().with_transition_width(10.0); fx::evolve(EvolveSymbolSet::CircleFill, 500) .with_pattern(p) ``` -------------------------------- ### started() -> bool Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/effect_timer.rs.html?search=u32+-%3E+bool Checks if the timer has been started by comparing total and remaining durations. Returns true if the timer has been started (i.e., some time has elapsed), false otherwise. ```APIDOC ## started() -> bool ### Description Checks if the timer has been started by comparing total and remaining durations. Returns `true` if the timer has been started (i.e., some time has elapsed), `false` otherwise. ### Method `pub fn started(&self) -> bool` ### Parameters None ### Returns - **bool** - `true` if the timer has been started (total != remaining), `false` otherwise. ### Example ```rust let timer = EffectTimer::from_ms(1000, Interpolation::Linear); assert!(!timer.started()); ``` ``` -------------------------------- ### get(&self) -> Rect Source: https://docs.rs/tachyonfx/latest/tachyonfx/struct.RefRect.html Gets the current rectangle value. ```APIDOC ## get(&self) -> Rect ### Description Gets the current rectangle value. ### Method `pub fn get(&self) -> Rect` ### Returns The current rectangle value ### Panics Panics if the internal lock is poisoned (sendable feature only). ### Example ```rust use tachyonfx::RefRect; use ratatui_core::layout::Rect; let ref_rect = RefRect::new(Rect::new(0, 0, 10, 5)); let rect = ref_rect.get(); ``` ``` -------------------------------- ### run_once example: fade_to_fg and dissolve Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/fx/mod.rs.html?search=u32+-%3E+bool Shows how to use fx::run_once to execute a sequence of effects only once. The example uses fade_to_fg and dissolve effects. ```rust fx::fade_to_fg(Color::Red, 1000), fx::run_once(fx::dissolve(500)), fx::fade_to_fg(Color::Blue, 1000), ``` -------------------------------- ### CompletionEngine implementation Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/dsl/completions/engine.rs.html?search= The full source code of the CompletionEngine struct and its implementation, including the new() and completions() methods. It shows how the engine is initialized with all DSL types and how completions are filtered based on token analysis, returning empty vectors for comments or after 'let' keywords. ```rust 1use alloc::collections::BTreeMap; 2use std::collections::HashMap; 3 4use super::{ 5 context::analyze_last_tokens, 6 dsl_type::{all_constants, all_constructors, all_methods}, 7 matcher::CompletionMatcher, 8 types::{ 9 tok, CallableItem, CompletionContext, CompletionItem, CompletionKind, LetBinding, 10 TokenCursor, 11 }, 12}; 13use crate::dsl::{completions::dsl_type::effect_types, tokenizer::Token}; 14 15/// Provides intelligent code completion for the tachyonfx DSL. 16/// 17/// The completion engine analyzes DSL source code and cursor position to suggest 18/// context-appropriate completions. It understands: 19/// 20/// - Type and Effect constructors and their parameters 21/// - Method chaining on typed objects 22/// - Struct field initialization 23/// - Let bindings and variable references /// - Constant values and enum variants /// /// The engine uses fuzzy matching to filter completions as the user types. /// /// # Examples /// /// Basic usage: /// /// ``` /// use tachyonfx::dsl::CompletionEngine; /// /// let engine = CompletionEngine::new(); /// /// // Complete at top level /// let completions = engine.completions("fx::", 4); /// // Returns all effect constructors: dissolve, fade_to, sweep_in, etc. /// /// // Complete method chains /// let completions = engine.completions("Rect::new(0, 0, 10, 10).", 24); /// // Returns Rect instance methods: inner, intersection, union, etc. /// /// // Complete with partial input /// let completions = engine.completions("Color::R", 8); /// // Returns: Red, Rgb, Reset (fuzzy matched) /// ``` #[derive(Debug, Clone)] pub struct CompletionEngine { effect_types: HashMap<&'static str, CallableItem>, constructors: HashMap<&'static str, &'static [CallableItem]>, methods: HashMap<&'static str, &'static [CallableItem]>, constants: HashMap<&'static str, &'static [&'static str]>, } impl CompletionEngine { /// Creates a new completion engine with all DSL types registered. /// /// The engine is pre-populated with: /// - tachyonfx effects (47 effects) /// - Ratatui types (Color, Layout, Rect, Style, etc.) /// - Enum constants (Interpolation, Motion, Direction, etc.) /// - Constructor and instance methods /// /// # Examples /// /// ``` /// use tachyonfx::dsl::CompletionEngine; /// /// let engine = CompletionEngine::new(); /// let completions = engine.completions("", 0); /// assert!(!completions.is_empty()); /// ``` #[must_use] pub fn new() -> Self { let methods = all_methods(); let constructors = all_constructors(); let constants = all_constants(); let effect_types = effect_types(); Self { methods, constructors, constants, effect_types } } /// Provides context-aware completions for DSL source code. /// /// Analyzes the source string up to the cursor position, determines the completion /// context (top-level, method chain, function call, etc.), and returns appropriate /// suggestions. Completions are filtered using fuzzy matching if the cursor is within /// or at the end of an identifier. /// /// # Arguments /// /// * `source` - The DSL source code string /// * `cursor_index` - Character offset of the cursor in the source string /// /// # Returns /// /// A vector of [`CompletionItem`]s sorted by relevance (best matches first). #[must_use] pub fn completions(&self, source: &str, cursor_index: u32) -> Vec { use crate::dsl::tokenizer::{sanitize_tokens, tokenize}; if let Ok(tokens) = tokenize(&source[..cursor_index as usize]) { // note: it would be nice to handle more cases around strings // and comments, but it requires passing more context after // the current cursor position. maybe in the future. if matches!(&tokens.last(), Some(tok!(LineComment))) { // no completions: cursor inside line comment return vec![]; } // removing whitespace and comments let tokens = sanitize_tokens(tokens); // no completions: cursor right after `let ` or `let ` if tokens.len() >= 2 && tokens[tokens.len() - 2..] .iter() .any(|t| matches!(t, tok!(Keyword == "let"))) { return vec![]; } return self.completions_from_tokens(&tokens, cursor_index); } vec![] } ``` -------------------------------- ### explode: usage example with no_run Source: https://docs.rs/tachyonfx/latest/src/tachyonfx/fx/mod.rs.html?search=std%3A%3Avec Example usage of the explode effect with a timer and area. ```rust use tachyonfx::{fx, Interpolation::Linear}; use ratatui_core::layout::Rect; use ratatui_core::style::Color; let timer = (1000, Linear); ``` -------------------------------- ### repeating inline example Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.repeating.html Inline version of the repeating example, showing the same usage in a single line. ```rust let fade = fx::fade_to_fg(Color::Red, (1000, Interpolation::Linear)); fx::repeating(fade) ``` -------------------------------- ### Inline example of fx::prolong_end Source: https://docs.rs/tachyonfx/latest/tachyonfx/fx/fn.prolong_end.html A one-line version of the example, showing the same usage in a compact form. ```rust let c = Color::from_u32(0x504945); let timer = (500, Interpolation::CircOut); fx::prolong_end(timer, fx::fade_to_fg(c, timer)) ```