": "Quit", // Quit the application 5 | "": "ScheduleIncrement", 6 | " ": "ScheduleDecrement", 7 | " ": "ToggleShowHelp", 8 | ">": "EnterInsert", 9 | " ": "Quit", // Another way to quit 10 | " ": "Quit", // Yet another way to quit 11 | " ": "Suspend", // Suspend the application 12 | }, 13 | }, 14 | } 15 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/.envrc: -------------------------------------------------------------------------------- 1 | export RATATUI_COUNTER_CONFIG=`pwd`/.config 2 | export RATATUI_COUNTER_DATA=`pwd`/.data 3 | export RATATUI_COUNTER_LOG_LEVEL=debug 4 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/.rustfmt.toml: -------------------------------------------------------------------------------- 1 | max_width = 120 2 | use_small_heuristics = "Max" 3 | match_block_trailing_comma = true 4 | reorder_imports = true 5 | tab_spaces = 2 6 | use_field_init_shorthand = true 7 | use_try_shorthand = true 8 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ratatui-counter" 3 | version = "0.1.0" 4 | edition = "2021" 5 | description = "Counter application with async-template" 6 | authors = ["Dheepak Krishnamurthy"] 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [dependencies] 11 | better-panic = "0.3.0" 12 | clap = { version = "4.5.16", features = [ 13 | "std", 14 | "color", 15 | "help", 16 | "usage", 17 | "error-context", 18 | "suggestions", 19 | "derive", 20 | "cargo", 21 | "wrap_help", 22 | "unicode", 23 | "string", 24 | "unstable-styles", 25 | ] } 26 | color-eyre = "0.6.3" 27 | config = "0.14.0" 28 | crossterm = { version = "0.28.1", features = ["serde", "event-stream"] } 29 | derive_deref = "1.1.1" 30 | directories = "5.0.1" 31 | futures = "0.3.30" 32 | human-panic = "2.0.1" 33 | json5 = "0.4.1" 34 | lazy_static = "1.5.0" 35 | libc = "0.2.158" 36 | log = "0.4.22" 37 | pretty_assertions = "1.4.0" 38 | ratatui = { version = "0.28.1", features = ["serde", "macros"] } 39 | serde = { version = "1.0.209", features = ["derive"] } 40 | serde_json = "1.0.127" 41 | signal-hook = "0.3.17" 42 | strip-ansi-escapes = "0.2.0" 43 | strum = { version = "0.26.3", features = ["derive"] } 44 | tokio = { version = "1.39.3", features = ["full"] } 45 | tokio-util = "0.7.11" 46 | tracing = "0.1.37" 47 | tracing-error = "0.2.0" 48 | tracing-subscriber = { version = "0.3.17", features = ["env-filter", "serde"] } 49 | tui-input = { version = "0.10.1", features = ["serde"] } 50 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Dheepak Krishnamurthy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/README.md: -------------------------------------------------------------------------------- 1 | # ratatui-counter 2 | 3 | Counter application with async-template 4 | 5 | ## Run demo 6 | 7 | ```rust 8 | export RATATUI_COUNTER_CONFIG=`pwd`/.config 9 | export RATATUI_COUNTER_DATA=`pwd`/.data 10 | export RATATUI_COUNTER_LOG_LEVEL=debug 11 | 12 | cargo run 13 | ``` 14 | 15 |  16 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "stable" 3 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/src/action.rs: -------------------------------------------------------------------------------- 1 | use std::{fmt, string::ToString}; 2 | 3 | use serde::{ 4 | de::{self, Deserializer, Visitor}, 5 | Deserialize, Serialize, 6 | }; 7 | use strum::Display; 8 | 9 | // ANCHOR: action_enum 10 | #[derive(Debug, Clone, PartialEq, Eq, Serialize, Display, Deserialize)] 11 | pub enum Action { 12 | Tick, 13 | Render, 14 | Resize(u16, u16), 15 | Suspend, 16 | Resume, 17 | Quit, 18 | Refresh, 19 | Error(String), 20 | Help, 21 | ToggleShowHelp, 22 | ScheduleIncrement, 23 | ScheduleDecrement, 24 | Increment(usize), 25 | Decrement(usize), 26 | CompleteInput(String), 27 | EnterNormal, 28 | EnterInsert, 29 | EnterProcessing, 30 | ExitProcessing, 31 | Update, 32 | } 33 | // ANCHOR_END: action_enum 34 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/src/cli.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | 3 | use clap::Parser; 4 | 5 | use crate::utils::version; 6 | 7 | #[derive(Parser, Debug)] 8 | #[command(author, version = version(), about)] 9 | pub struct Cli { 10 | #[arg(short, long, value_name = "FLOAT", help = "Tick rate, i.e. number of ticks per second", default_value_t = 1.0)] 11 | pub tick_rate: f64, 12 | 13 | #[arg( 14 | short, 15 | long, 16 | value_name = "FLOAT", 17 | help = "Frame rate, i.e. number of frames per second", 18 | default_value_t = 60.0 19 | )] 20 | pub frame_rate: f64, 21 | } 22 | -------------------------------------------------------------------------------- /code/templates/async-template-counter/src/components.rs: -------------------------------------------------------------------------------- 1 | use color_eyre::eyre::Result; 2 | use ratatui::{ 3 | crossterm::event::{KeyEvent, MouseEvent}, 4 | layout::Rect, 5 | Frame, 6 | }; 7 | use tokio::sync::mpsc::UnboundedSender; 8 | 9 | use crate::{action::Action, config::Config, tui::Event}; 10 | 11 | pub mod fps; 12 | pub mod home; 13 | 14 | // ANCHOR: component 15 | pub trait Component { 16 | #[allow(unused_variables)] 17 | fn register_action_handler(&mut self, tx: UnboundedSender ) -> Result<()> { 18 | Ok(()) 19 | } 20 | #[allow(unused_variables)] 21 | fn register_config_handler(&mut self, config: Config) -> Result<()> { 22 | Ok(()) 23 | } 24 | fn init(&mut self) -> Result<()> { 25 | Ok(()) 26 | } 27 | fn handle_events(&mut self, event: Option ) -> Result