From d56861ee4c87eae56123e1a218712c0c49716668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Fri, 4 Oct 2024 00:38:11 +0300 Subject: [PATCH] style(ui): add a simple shader effect via tachyonfx --- Cargo.lock | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/app.rs | 23 ++++++++++--- 3 files changed, 115 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e644f45..449f682 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -132,6 +132,29 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bon" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97493a391b4b18ee918675fb8663e53646fd09321c58b46afa04e8ce2499c869" +dependencies = [ + "bon-macros", + "rustversion", +] + +[[package]] +name = "bon-macros" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2af3eac944c12cdf4423eab70d310da0a8e5851a18ffb192c0a5e3f7ae1663" +dependencies = [ + "darling", + "ident_case", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "cassowary" version = "0.3.0" @@ -236,6 +259,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[package]] +name = "colorsys" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54261aba646433cb567ec89844be4c4825ca92a4f8afba52fc4dd88436e31bbd" + [[package]] name = "compact_str" version = "0.8.0" @@ -312,6 +341,41 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "dary_heap" version = "0.3.6" @@ -354,6 +418,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "generic-array" version = "0.14.7" @@ -392,6 +462,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "include-flate" version = "0.3.0" @@ -794,6 +870,12 @@ dependencies = [ "libc", ] +[[package]] +name = "simple-easing" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "832ddd7df0d98d6fd93b973c330b7c8e0742d5cb8f1afc7dea89dba4d2531aa1" + [[package]] name = "smallvec" version = "1.13.2" @@ -845,6 +927,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tachyonfx" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdbe5dec00875ec5508392048b1b95460520f2d174533527f525d98b474de79d" +dependencies = [ + "bon", + "colorsys", + "ratatui", + "simple-easing", +] + [[package]] name = "terminal_size" version = "0.3.0" @@ -863,6 +957,7 @@ dependencies = [ "color-eyre", "ratatui", "rust-embed", + "tachyonfx", "tui-term", "vt100", ] diff --git a/Cargo.toml b/Cargo.toml index 73610ac..cd2a5b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ vt100 = "0.15.2" rust-embed = { version = "8.5.0", features = ["compression", "debug-embed"] } color-eyre = "0.6.3" clap = { version = "4.5.17", features = ["derive", "env", "wrap_help", "cargo"] } +tachyonfx = "0.7.0" [profile.dev] opt-level = 0 diff --git a/src/app.rs b/src/app.rs index 6b0cd0f..1bc3207 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2,6 +2,10 @@ use std::{ io::{BufReader, Cursor}, time::{Duration, Instant}, }; +use tachyonfx::{ + fx::{self}, + Duration as FxDuration, Effect, EffectRenderer, Interpolation, Shader, +}; use vt100::Parser; use crate::{ @@ -43,11 +47,14 @@ pub struct App { pub frame_interval: Duration, /// FPS counter widget. pub fps: Fps, + /// Terminal effect. + pub effect: Effect, } impl App { /// Construct a new instance of [`App`]. pub fn new(event_handler: EventHandler, args: Args) -> Self { + let effect = fx::coalesce((800, Interpolation::SineOut)); Self { is_running: true, is_toggled: true, @@ -58,6 +65,7 @@ impl App { animation_area: Rect::default(), frame_interval: Duration::from_secs_f32(1.0 / args.fps), fps: Fps::default(), + effect, args, } } @@ -203,6 +211,11 @@ impl App { .position(Position::Bottom), ); + self.animation_area = area[1].inner(Margin { + vertical: 1, + horizontal: 1, + }); + if !self.animation.is_rendered { block = block.title( Title::from(Line::from(vec![ @@ -218,11 +231,12 @@ impl App { } frame.render_widget(block, area[1]); - self.animation_area = area[1].inner(Margin { - vertical: 1, - horizontal: 1, - }); frame.render_widget(&mut self.animation, self.animation_area); + frame.render_effect( + &mut self.effect, + self.animation_area, + FxDuration::from_millis(100), + ); } pub fn start_animation(&mut self) { @@ -237,5 +251,6 @@ impl App { parser: Parser::new(self.animation_area.height, self.animation_area.width, 0), buffer: String::new(), }; + self.effect.reset(); } }