Crates.io | tachyonfx |
lib.rs | tachyonfx |
version | |
source | src |
created_at | 2024-06-20 15:30:01.64187 |
updated_at | 2024-12-08 19:02:59.941789 |
description | A ratatui library for creating shader-like effects in TUIs. |
homepage | https://github.com/junkdog/tachyonfx |
repository | https://github.com/junkdog/tachyonfx |
max_upload_size | |
id | 1278080 |
Cargo.toml error: | TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
tachyonfx (ˈtakɪɒn ˌɛfˈɛks) is a ratatui library for creating shader-like effects in terminal UIs. It provides a collection of stateful effects that can enhance the visual appeal of terminal applications through color transformations, animations, and complex effect combinations.
Add tachyonfx to your Cargo.toml
:
tachyonfx = "0.10.1"
Effects in tachyonfx are stateful objects that evolve over time. When you create an effect, it typically maintains:
// Create the effect once
let mut fade_effect = fx::fade_to_fg(Color::Red, Duration::from_millis(1000));
// In your render loop:
loop {
widget.render(area, buf);
// Process the same effect each frame, updating its state
fade_effect.process(frame_duration, buf, area);
// Or use the helper trait:
// frame.render_effect(&mut fade_effect, area, frame_duration);
}
Effects in tachyonfx operate on terminal cells after widgets have been rendered to the screen. When an effect is applied, it modifies properties of the already-rendered cells - like their colors, characters, or visibility. This means the typical flow is:
The library includes a variety of effects, loosely categorized as follows:
CellIterator
.Buffer
.Additional effects can be created by implementing the Shader
trait.
Most effects are driven by an EffectTimer
that controls their duration and interpolation. It
allows for precise timing and synchronization of visual effects within your application.
fx::dissolve(EffectTimer::from_ms(500, BounceOut))
fx::dissolve((500, BounceOut)) // shorthand for the above
fx::dissolve(500) // linear interpolation
Effects can be applied to specific cells in the terminal UI, allowing for targeted visual modifications and animations.
// only apply to cells with `Light2` foreground color
fx::sweep_in(Direction::UpToDown, 15, 0, Dark0, timer)
.with_cell_selection(CellFilter::FgColor(Light2.into()))
CellFilter
s can be combined to form complex selection criteria.
// apply effect to cells on the outer border of the area
let margin = Margin::new(1, 1);
let border_text = CellFilter::AllOf(&[
CellFilter::Outer(margin),
CellFilter::Text
]);
prolong_start(duration, fx::fade_from(Dark0, Dark0, (320, QuadOut)),
.with_cell_selection(border_text)
sendable
: Enables the Send
trait for effects, shaders, and associated parameters. This allows effects to be
safely transferred across thread boundaries. Note that enabling this feature requires all Shader
implementations
to be Send
, which may impose additional constraints on custom shader implementations.
std-duration
: Uses std::time::Duration
instead of a custom 32-bit duration type.
cargo run --release --example=minimal
cargo run --release --example=tweens
cargo run --release --example=basic-effects
cargo run --release --example=open-window
A demo of the EffectTimelineWidget
showcasing the composition of effects. The widget is a "plain" widget
without any effects as part of its rendering. The effects are instead applied after rendering the widget.
cargo run --release --example=fx-chart