### Quick Start: Ratkit Application Setup Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/api/core/index.md This example demonstrates the basic setup for a Ratkit TUI application using the CoordinatorApp trait and the run function. Ensure you have the ratkit and ratatui crates included in your project. ```rust use ratkit::prelude::*; use ratatui::Frame; struct MyApp; impl CoordinatorApp for MyApp { fn on_event(&mut self, _event: CoordinatorEvent) -> LayoutResult { Ok(CoordinatorAction::Continue) } fn on_draw(&mut self, _frame: &mut Frame) {} } fn main() -> std::io::Result<()> { run(MyApp, RunnerConfig::default()) } ``` -------------------------------- ### Add to Get Started Page (mdx) Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/scripts/README.md Example of adding a link to a new provider in the 'Model Providers' section of the 'Get Started' page. Links must be in alphabetical order. ```mdx ## Model Providers AISDK supports a wide range of AI providers, including: - Anthropic - Cohere - Google - OpenAI - more to come ``` -------------------------------- ### Quick Start Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md A basic Rust example demonstrating how to set up and run a RatKit application. ```rust use ratkit::prelude::*; use ratatui::Frame; struct MyApp; impl CoordinatorApp for MyApp { fn on_event(&mut self, event: CoordinatorEvent) -> LayoutResult { match event { CoordinatorEvent::Keyboard(keyboard) => { if keyboard.is_escape() { return Ok(CoordinatorAction::Quit); } } _ => {} } Ok(CoordinatorAction::Continue) } fn on_draw(&mut self, frame: &mut Frame) { // Render your UI here } } fn main() -> std::io::Result<()> { run(MyApp, RunnerConfig::default()) } ``` -------------------------------- ### Start Development Server Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/README.md Run this command to start the development server for the documentation. Open http://localhost:3000 to view the documentation. ```bash pnpm dev ``` -------------------------------- ### Setup RepoWatcher Service Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/services/repo-watcher.mdx Initializes and starts the RepoWatcher service, handling both file and git events. Includes a sleep to keep the watcher active and then stops it. ```rust use ratkit::services::repo_watcher::{RepoWatcher, RepoEvent}; fn setup_repo_watcher() -> std::io::Result<()> { let watcher = RepoWatcher::new("./") .on_change(|event: RepoEvent| { match event { RepoEvent::File(event) => { handle_file_event(event); } RepoEvent::Git(event) => { handle_git_event(event); } } }); watcher.start()?; std::thread::sleep(std::time::Duration::from_secs(60)); watcher.stop()?; Ok(()) } ``` -------------------------------- ### Run All Examples Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Command to run all interactive examples using 'just'. ```bash just demo ``` -------------------------------- ### Create and Start a FileClocker Service Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/services/index.mdx Demonstrates how to instantiate a FileClocker service, set up a change handler, and start the watching process. Ensure the path provided to `FileClocker::new` is valid. ```rust use ratkit::services::file_watcher::FileClocker; // Create the service let watcher = FileClocker::new("./src"); // Set up event handling watcher.on_change(|event| { println!("File changed: {:?}", event); }); // Start watching watcher.start()?; // Later, stop the service watcher.stop()?; ``` -------------------------------- ### Feature Flags Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md Demonstrates how to enable specific features for examples. ```bash just demo --features markdown-preview ``` -------------------------------- ### ResizableGrid Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates the usage of draggable split panels. ```bash cargo run --example resizable-grid_resizable_grid_demo --features resizable-grid ``` -------------------------------- ### Event Handling Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/api/core/events.md Example demonstrating how to handle different `RunnerEvent` types using a match statement. ```APIDOC ## Example Usage ```rust use ratkit::prelude::*; fn handle_event(event: RunnerEvent) { match event { RunnerEvent::Keyboard(k) if k.is_enter() => println!("Enter pressed"), RunnerEvent::Mouse(m) if m.is_click() => println!("Mouse clicked at {:?}", m.position()), _ => {} } } ``` ``` -------------------------------- ### Example Interactive Session Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/scripts/README.md Demonstrates an interactive session for generating provider documentation, showing prompts and auto-suggestions. ```bash 🚀 Provider Documentation Generator This will create a new provider documentation file. Press Enter to accept suggested values. Provider name (e.g., Anthropic, Google, OpenAI): Cohere Provider lowercase [cohere]: Environment variable name [COHERE_API_KEY]: Example model method (e.g., gpt_5, claude_3_5_sonnet): command_r_plus Model string (kebab-case) [command-r-plus]: Model type example (PascalCase, e.g., Gpt5, Claude35Sonnet): CommandRPlus Default base URL (e.g., https://api.openai.com): https://api.cohere.ai Output filename [cohere.mdx]: ✅ Successfully created: /path/to/content/docs/providers/cohere.mdx Next steps: 1. Review the generated file 2. Customize if needed 3. Add entry to meta.json if required ``` -------------------------------- ### Run Provider Documentation Generator (Short Arguments) Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/scripts/README.md Example using short argument flags for the provider documentation generator script. ```bash pnpm gen:provider -n "DeepSeek" -l "deepseek" -e "DEEPSEEK_API_KEY" -m "deepseek_chat" -s "deepseek-chat" -t "DeepseekChat" -b "https://api.deepseek.com/" -o "deepseek.mdx" ``` -------------------------------- ### GitWatcher Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates Git repository monitoring. ```bash cargo run --example git_watcher_demo --features git-watcher ``` -------------------------------- ### Run Specific Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Command to run a specific example with its required features. ```bash cargo run --example --features ``` -------------------------------- ### HotkeyService Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates global hotkey management with scope filtering. ```bash cargo run --example hotkey_service_demo --features hotkey-service ``` -------------------------------- ### FileWatcher Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates file change monitoring. ```bash cargo run --example file_watcher_demo --features file-watcher ``` -------------------------------- ### Run Markdown Demo Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/src/widgets/markdown_preview/widgets/markdown_widget/README.md Execute the markdown demo using cargo run. Ensure the 'markdown' feature is enabled. ```bash cargo run --example markdown_demo --features markdown ``` -------------------------------- ### FileSystemTree Enable/Install Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md How to enable and install the FileSystemTree feature. ```rust features = ["file-system-tree"] ``` -------------------------------- ### MenuBar Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates the usage of the horizontal menu bar. ```bash cargo run --example menu-bar_menu_bar_demo --features menu-bar ``` -------------------------------- ### Build with specific features Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md Example command to build the project with a specific set of features enabled. ```bash cargo build --features "button,pane,dialog" ``` -------------------------------- ### Basic MarkdownWidget Usage Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/src/widgets/markdown_preview/widgets/markdown_widget/README.md This example demonstrates the recommended basic usage of the MarkdownWidget with unified state management. It initializes the state, sets content, and configures the widget with common options. ```rust use ratatui_toolkit::{MarkdownWidget, MarkdownState}; let mut state = MarkdownState::default(); state.source.set_content("# Hello World\n\nWelcome to the markdown widget!"); let content = state.content().to_string(); let widget = MarkdownWidget::from_state(&content, &mut state) .show_toc(true) .show_statusline(true) .show_scrollbar(true); ``` -------------------------------- ### Toast Notification Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates the usage of Toast notifications. ```bash cargo run --example toast_toast_demo --features toast ``` -------------------------------- ### HotkeyService Enable/Install Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md How to enable and install the HotkeyService feature. ```rust features = ["hotkey-service"] ``` -------------------------------- ### RepoWatcher Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates combined file and Git watching for comprehensive repository change tracking. ```bash cargo run --example repo_watcher_demo --features repo-watcher ``` -------------------------------- ### Render FileSystemTree Widget Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/widgets/file-system-tree.mdx Basic setup for rendering the FileSystemTree widget. Requires importing `FileSystemTree` and `FileTreeState` from `ratkit::widgets::file_system_tree`. ```rust use ratkit::widgets::file_system_tree::{FileSystemTree, FileTreeState}; use ratatui::Frame; fn render_file_tree(frame: &mut Frame) { let tree = FileSystemTree::new("./src"); let mut state = FileTreeState::default(); frame.render_stateful_widget(tree, frame.area(), &mut state); } ``` -------------------------------- ### StatusLine Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates the usage of Powerline-style status bar. ```bash cargo run --example statusline_statusline_demo --features statusline ``` -------------------------------- ### Install ratkit via Cargo Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/(get-started)/installation.mdx Use the cargo command to add the dependency to your project. ```bash cargo add ratkit ``` -------------------------------- ### FileWatcher Enable/Install Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md How to enable and install the FileWatcher feature. ```rust features = ["file-watcher"] (uses notify crate) ``` -------------------------------- ### Initialize and start FileWatcher in Rust Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/services/file-watcher.mdx Sets up a watcher on a directory and defines a callback to handle various file system events. ```rust use ratkit::services::file_watcher::{FileWatcher, FileEvent}; fn setup_watcher() -> std::io::Result<()> { let watcher = FileWatcher::new("./src") .on_change(|event: FileEvent| { match event { FileEvent::Created(path) => { println!("Created: {:?}", path); } FileEvent::Modified(path) => { println!("Modified: {:?}", path); } FileEvent::Deleted(path) => { println!("Deleted: {:?}", path); } FileEvent::Renamed(old, new) => { println!("Renamed: {:?} -> {:?}", old, new); } } }); watcher.start()?; // Keep the watcher alive std::thread::sleep(std::time::Duration::from_secs(60)); watcher.stop()?; Ok(()) } ``` -------------------------------- ### Feature Flags Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md This snippet shows an example of enabling specific features for ratkit, disabling default features. ```toml ratkit = { version = "0.2.16", default-features = false, features = ["tree-view", "toast"] } ``` -------------------------------- ### CodeWidget Enable/Install Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md How to enable and install the CodeWidget feature, including its dependencies. ```rust features = ["code-widget"] (enables syntect, syntect-tui, pane, statusline) ``` -------------------------------- ### TermTui Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates the usage of the terminal emulator with mprocs-style copy mode. ```bash cargo run --example termtui_term_mprocs_demo --features termtui ``` -------------------------------- ### Verify ratkit installation Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/(get-started)/installation.mdx Run a simple test to ensure the library is correctly integrated. ```rust use ratatui::DefaultTerminal; use ratkit::primitives::button::Button; fn main() -> std::io::Result<()> { let terminal = ratatui::init(); let button = Button::new("Hello ratkit!"); println!("ratkit is installed and working!"); ratatui::restore(); Ok(()) } ``` -------------------------------- ### TreeView Widget Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates the usage of the hierarchical tree widget. ```bash cargo run --example tree-view_tree_view_demo --features tree-view ``` -------------------------------- ### WidgetEvent Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates the usage of the shared widget event model. ```bash cargo run --example widget-event_widget_event_demo --features widget-event ``` -------------------------------- ### Initialize and start GitWatcher in Rust Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/services/git-watcher.mdx Configures a watcher for the current directory with event callbacks and manages the lifecycle of the service. ```rust use ratkit::services::git_watcher::{GitWatcher, GitEvent}; fn setup_git_watcher() -> std::io::Result<()> { let watcher = GitWatcher::new("./") .on_change(|event: GitEvent| { match event { GitEvent::BranchChanged { old, new } => { println!("Branch changed: {} -> {}", old, new); } GitEvent::CommitsAhead(ahead) => { println!("{} commits ahead of remote", ahead); } GitEvent::CommitsBehind(behind) => { println!("{} commits behind remote", behind); } GitEvent::StatusChanged(status) => { println!("Working directory changed"); println!("Modified: {:?}", status.modified); println!("Staged: {:?}", status.staged); } } }); watcher.start()?; std::thread::sleep(std::time::Duration::from_secs(60)); watcher.stop()?; Ok(()) } ``` -------------------------------- ### Mouse Support in Components Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Example demonstrating how to handle mouse events within a component. ```rust // Handle mouse events if let Some(event) = component.handle_mouse(mouse_event, area) { match event { WidgetEvent::Clicked => { ... } _ => {} } } ``` -------------------------------- ### Scroll Offset Helpers Example Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Demonstrates the usage of scroll offset helpers for managing viewport and cursor movement. ```bash cargo run --example scroll_scroll_demo --features scroll ``` -------------------------------- ### Configure ratkit feature flags Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/(get-started)/installation.mdx Control the installation size and included components using feature flags. ```toml [dependencies] ratkit = { version = "0.2.5", default-features = false } ``` ```toml [dependencies] ratkit = { version = "0.2.5", features = ["primitives", "widgets"] } ``` -------------------------------- ### Dialog Interaction Patterns Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md Examples of configuring dialog interaction patterns using Ratkit. ```rust .actions_layout(DialogActionsLayout::Vertical) ``` ```rust .actions_layout(DialogActionsLayout::Horizontal) ``` ```rust .buttons(vec![]) ``` ```rust .body_renderer(Box::new(...)) ``` ```rust .modal_mode(DialogModalMode::Blocking) ``` ```rust blocks_background_events() ``` ```rust .next_keys(...) ``` ```rust .previous_keys(...) ``` -------------------------------- ### Cargo.toml - enable specific features Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md Example of how to enable specific features for the ratkit dependency in Cargo.toml. ```toml [dependencies] ratkit = { version = "0.2.16", features = ["button", "dialog", "pane"] } ``` -------------------------------- ### Update Sidebar Navigation (meta.json) Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/scripts/README.md Example of how to add a new provider to the sidebar navigation by editing the `meta.json` file. Entries must be in alphabetical order. ```json { "title": "Providers", "icon": "Workflow", "pages": ["index", "antropic", "cohere", "google"] } ``` -------------------------------- ### Basic Ratkit Application Structure Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md A minimal example of a Ratkit application implementing the CoordinatorApp trait and running the application. ```rust use ratkit::prelude::*; use ratatui::Frame; struct MyApp; impl CoordinatorApp for MyApp { fn on_event(&mut self, event: CoordinatorEvent) -> LayoutResult { match event { CoordinatorEvent::Keyboard(keyboard) => { if keyboard.is_escape() { return Ok(CoordinatorAction::Quit); } } _ => {} } Ok(CoordinatorAction::Continue) } fn on_draw(&mut self, frame: &mut Frame) { // Render your UI here } } fn main() -> std::io::Result<()> { let app = MyApp; run(app, RunnerConfig::default()) } ``` -------------------------------- ### Render StatusLine Widget Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/statusline.mdx Basic usage example for rendering a StatusLine widget. Requires importing StatusLine and Frame from ratkit and ratatui respectively. The status line is configured with left and right text. ```rust use ratkit::primitives::statusline::StatusLine; use ratatui::Frame; fn render_status(frame: &mut Frame) { let status = StatusLine::new() .left("Ready") .right("UTF-8 | Rust"); frame.render_widget(status, bottom_area); } ``` -------------------------------- ### Basic ResizableGrid Usage Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/resizable-grid.mdx Demonstrates how to create and render a basic ResizableGrid with specified dimensions and column constraints. Ensure `ratkit::primitives::resizable_grid::ResizableGrid` and `ratatui::Frame` are imported. ```rust use ratkit::primitives::resizable_grid::ResizableGrid; use ratatui::Frame; fn render_grid(frame: &mut Frame) { let grid = ResizableGrid::new(3, 3) .column_constraints(vec![ Constraint::Percentage(33), Constraint::Percentage(33), Constraint::Percentage(33), ]) .resizable(true); frame.render_widget(grid, frame.area()); } ``` -------------------------------- ### Run Provider Documentation Generator (Non-Interactive) Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/scripts/README.md Use command line arguments for batch generation or CI/CD pipelines. All options can be passed as arguments. ```bash pnpm gen:provider --provider-name "Groq" --provider-lowercase "groq" --env-var-name "GROQ_API_KEY" --example-model-method "llama_3_1_8b_instruct" --example-model-string "llama-3.1-8b-instruct" --model-type-example "MetaLlamaLlama318bInstructV10" --default-base-url "https://api.groq.com/openai/" --output-filename "groq.mdx" ``` -------------------------------- ### Initialize a ratkit application Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/(get-started)/basic-usage.mdx Sets up a basic TUI loop using ratatui and ratkit components. ```rust use ratatui::{ crossterm::event::{self, Event, KeyCode}, DefaultTerminal, Frame, }; use ratkit::primitives::button::{Button, ButtonState}; fn main() -> std::io::Result<()> { let mut terminal = ratatui::init(); let app_result = run(&mut terminal); ratatui::restore(); app_result } fn run(terminal: &mut DefaultTerminal) -> std::io::Result<()> { let mut button_state = ButtonState::default(); loop { terminal.draw(|frame| render(frame, &mut button_state))?; if let Event::Key(key) = event::read()? { match key.code { KeyCode::Char('q') | KeyCode::Esc => break, KeyCode::Enter => { // Handle button click } _ => {} } } } Ok(()) } fn render(frame: &mut Frame, button_state: &mut ButtonState) { let button = Button::new("Click Me") .style(Style::default().fg(Color::White)) .highlight_style(Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)); frame.render_stateful_widget(button, frame.area(), button_state); } ``` -------------------------------- ### Markdown Demo Startup Profiling Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md Command to profile the startup time of the markdown preview demo. ```bash target/debug/examples/markdown_preview_markdown_preview_demo --startup-probe ``` -------------------------------- ### Just Commands for Demos Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md Shows how to run interactive demos using 'just'. ```bash just demo just demo-* ``` -------------------------------- ### Render a Basic MenuBar - Rust Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/menu-bar.mdx Demonstrates how to create and render a basic MenuBar with a 'File' menu containing several options and a separator, and an 'Edit' menu. Ensure `ratkit::primitives::menu_bar::{MenuBar, MenuItem}` and `ratatui::Frame` are imported. ```rust use ratkit::primitives::menu_bar::{MenuBar, MenuItem}; use ratatui::Frame; fn render_menu(frame: &mut Frame) { let menu = MenuBar::new() .add_item(MenuItem::new("File") .submenu(vec![ MenuItem::new("Open").shortcut("Ctrl+O"), MenuItem::new("Save").shortcut("Ctrl+S"), MenuItem::separator(), MenuItem::new("Exit").shortcut("Ctrl+Q"), ])) .add_item(MenuItem::new("Edit")); frame.render_widget(menu, top_area); } ``` -------------------------------- ### Initialize and Configure TermTUI Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/termtui.mdx Sets up the terminal environment by enabling raw mode and ensuring restoration on exit. ```rust use ratkit::primitives::termtui::TermTUI; fn setup_terminal() { let term = TermTUI::new(); // Enable raw mode term.enable_raw_mode(); // Clear screen term.clear(); // Restore terminal on exit term.restore(); } ``` -------------------------------- ### Initialize and use FocusManager Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/api/core/focus.md Demonstrates creating a new focus manager instance and issuing a navigation request. ```rust use ratkit::prelude::*; let mut focus_manager = FocusManager::new(); focus_manager.handle_request(FocusRequest::Next)?; ``` -------------------------------- ### Initialize and Render MarkdownPreview Widget Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/widgets/index.mdx Instantiate a MarkdownPreview widget and render it using a stateful frame. Requires importing MarkdownPreview and MarkdownState from ratkit. ```rust use ratkit::widgets::markdown_preview::{MarkdownPreview, MarkdownState}; use ratatui::Frame; let preview = MarkdownPreview::new("# Hello\n\nWorld!"); let mut state = MarkdownState::default(); frame.render_stateful_widget(preview, area, &mut state); ``` -------------------------------- ### Configure dependencies with ratatui and crossterm Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/(get-started)/installation.mdx Include required backend dependencies alongside ratkit. ```toml [dependencies] ratatui = "0.29" crossterm = "0.28" ratkit = "0.2.5" ``` -------------------------------- ### Run Provider Documentation Generator (Interactive) Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/scripts/README.md Execute the script in interactive mode to be prompted for provider details. ```bash pnpm gen:provider ``` -------------------------------- ### Initialize and Render a Button Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/index.mdx Demonstrates the standard lifecycle of a ratkit primitive, including instantiation, state management, and rendering within a ratatui frame. ```rust use ratkit::primitives::button::{Button, ButtonState}; use ratatui::Frame; // Create the component let button = Button::new("Click Me"); // Manage state let mut state = ButtonState::default(); // Render frame.render_stateful_widget(button, area, &mut state); ``` -------------------------------- ### Feature Flags Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/widgets/code-widget-plan.mdx Example of how to add a feature flag for the code widget. ```toml code-widget = ["syntect", "syntect-tui", "pane", "statusline"] ``` -------------------------------- ### Render Go Code Block Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/examples/markdown_demo_full.md Demonstrates rendering a simple Go program with package declaration, import, and main function. The markdown parser should support Go syntax highlighting. ```go package main import "fmt" func main() { fmt.Println("Hello, World!") } ``` -------------------------------- ### Register Basic Hotkeys with HotkeyService Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/services/hotkey-service.mdx Sets up global hotkeys for common actions like save, open, and quit. Ensure the necessary imports are present. ```rust use ratkit::services::hotkey_service::{HotkeyService, KeyCombo}; fn setup_hotkeys() -> std::io::Result<()> { let service = HotkeyService::new() .register("ctrl+s", || { println!("Save triggered!"); save_file(); }) .register("ctrl+o", || { println!("Open triggered!"); open_file(); }) .register("ctrl+q", || { println!("Quit triggered!"); std::process::exit(0); }); service.start()?; Ok(()) } ``` -------------------------------- ### Customizable Keybindings for TreeView Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md Example of how to define custom keybindings for the TreeView component using a configuration struct. ```rust use ratkit::TreeKeyBindings; use crossterm::event::KeyCode; let bindings = TreeKeyBindings::new() .with_next(vec![KeyCode::Char('n'), KeyCode::Down]) .with_previous(vec![KeyCode::Char('p'), KeyCode::Up]) .with_expand(vec![KeyCode::Char('e'), KeyCode::Right]) .with_collapse(vec![KeyCode::Char('c'), KeyCode::Left]); ``` -------------------------------- ### Render Dialog Widget Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/dialog.mdx Demonstrates how to create and render a basic Dialog widget using the Dialog::new() constructor and frame.render_widget(). Requires importing Dialog and DialogAction. ```rust use ratkit::primitives::dialog::{Dialog, DialogAction}; use ratatui::Frame; fn show_dialog(frame: &mut Frame) { let dialog = Dialog::new() .title("Confirm Action") .content("Are you sure you want to continue?") .button("Yes", DialogAction::Confirm) .button("No", DialogAction::Cancel); frame.render_widget(dialog, frame.area()); } ``` -------------------------------- ### Define Custom Themes Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/widgets/theme-picker.mdx Creates a custom theme with specific color attributes and initializes the ThemePicker with it. ```rust let custom_theme = Theme::new("Custom") .background(Color::Black) .foreground(Color::White) .accent(Color::Cyan) .error(Color::Red) .warning(Color::Yellow) .success(Color::Green); let picker = ThemePicker::new(vec![custom_theme]); ``` -------------------------------- ### MouseEvent Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/api/core/events.md Represents mouse input events. Provides methods to get mouse position, check for clicks, drags, scrolls, and if the position is within a rectangle. ```APIDOC ## MouseEvent Mouse input event. ### Methods - **`from_crossterm(event: crossterm::event::MouseEvent) -> Self`**: Convert from crossterm event. - **`position(&self) -> (u16, u16)`**: Get mouse position (x, y). - **`x(&self) -> u16`**: Get x coordinate. - **`y(&self) -> u16`**: Get y coordinate. - **`is_click(&self) -> bool`**: Check if event is a click. - **`is_drag(&self) -> bool`**: Check if event is a drag. - **`is_scroll(&self) -> bool`**: Check if event is scroll. - **`is_inside(&self, rect: Rect) -> bool`**: Check if position is inside rect. ``` -------------------------------- ### Initialize MarkdownWidget with Individual State Modules Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/src/widgets/markdown_preview/widgets/markdown_widget/README.md Use individual state modules for granular control over the widget's behavior and appearance. ```rust use ratatui_toolkit::markdown_widget::{MarkdownWidget, state::*}; let mut scroll = ScrollState::default(); let mut source = SourceState::default(); let mut cache = CacheState::default(); let display = DisplaySettings::default(); let mut collapse = CollapseState::default(); let mut expandable = ExpandableState::default(); let mut git_stats = GitStatsState::default(); let mut vim = VimState::default(); let mut selection = SelectionState::default(); let mut double_click = DoubleClickState::default(); let widget = MarkdownWidget::new( content, &mut scroll, &mut source, &mut cache, &display, &mut collapse, &mut expandable, &mut git_stats, &mut vim, &mut selection, &mut double_click, ) .show_toc(true) .show_statusline(true) .show_scrollbar(true); ``` -------------------------------- ### Render Python Code Block Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/examples/markdown_demo_full.md Shows how to render a Python function with a docstring and example usage in a markdown code block. The parser should recognize Python syntax. ```python def greet(name: str) -> str: """Return a greeting message.""" return f"Hello, {name}!" # Example usage print(greet("ratatui")) ``` -------------------------------- ### Dynamically Update StatusLine Sections Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/statusline.mdx Example demonstrating how to dynamically update the left, center, and right sections of a StatusLine based on application state variables like filename, line, column, and modification status. ```rust let status = StatusLine::new() .left(format!("File: {}", filename)) .center(format!("Line: {}, Col: {}", line, col)) .right(if modified { "[Modified]" } else { "" }); ``` -------------------------------- ### Enable Mouse Capture with Crossterm Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/src/widgets/markdown_preview/widgets/markdown_widget/README.md To enable mouse interactions like clicks and scrolls for the widget, you must configure crossterm to capture mouse events. This setup should be performed on application startup and cleaned up on exit. ```rust use crossterm:: event::{EnableMouseCapture, DisableMouseCapture}, execute, terminal::{EnterAlternateScreen, LeaveAlternateScreen}, }; fn main() -> std::io::Result<()> { let mut stdout = std::io::stdout(); // On startup: execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?; // ... your application code ... // On cleanup: execute!(stdout, LeaveAlternateScreen, DisableMouseCapture)?; Ok(()) } ``` -------------------------------- ### Render a basic Pane in Rust Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/pane.mdx Initializes a Pane with a title and blue border style, then renders it to the frame. ```rust use ratkit::primitives::pane::Pane; use ratatui::Frame; fn render_pane(frame: &mut Frame) { let pane = Pane::new("My Pane") .border_style(Style::default().fg(Color::Blue)); frame.render_widget(pane, frame.area()); } ``` -------------------------------- ### ResizableGrid State Management Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/resizable-grid.mdx Shows how to initialize and use `ResizableGridState` to manage resize operations. The `get_resize_delta` method can be used in event handling to apply resize adjustments. ```rust let mut state = ResizableGridState::default(); // In event handling if let Some((col, delta)) = state.get_resize_delta() { // Apply resize } ``` -------------------------------- ### Display a File System Tree Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/(get-started)/basic-usage.mdx Renders a browsable file system tree widget. ```rust use ratkit::widgets::file_system_tree::{FileSystemTree, FileSystemTreeState}; let tree = FileSystemTree::new("./src"); let mut state = FileSystemTreeState::default(); frame.render_stateful_widget(tree, area, &mut state); ``` -------------------------------- ### Render a Basic Button Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/button.mdx Demonstrates how to create and render a basic Button widget in a TUI frame. Requires importing Button and ButtonState from ratkit.primitives.button. ```rust use ratkit::primitives::button::{Button, ButtonState}; use ratatui::Frame; fn render_button(frame: &mut Frame) { let button = Button::new("Click Me"); let mut state = ButtonState::default(); frame.render_stateful_widget(button, frame.area(), &mut state); } ``` -------------------------------- ### Configure Table of Contents Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/src/widgets/markdown_preview/widgets/markdown_widget/README.md Initialize and configure the TOC extension for navigation. ```rust use ratatui_toolkit::markdown_widget::extensions::toc::{Toc, TocConfig}; let toc_config = TocConfig::default() .compact_width(3) .expanded_width(25) .show_border(true); let toc = Toc::new(&toc_state) .expanded(false); // Start in compact mode ``` -------------------------------- ### Build all features Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md Command to build the project with all available features enabled. ```bash cargo build --all-features ``` -------------------------------- ### Render Basic HotkeyFooter Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/widgets/hotkey-footer.mdx Use this snippet to render a basic HotkeyFooter with a predefined set of shortcuts. Ensure `ratkit::widgets::hotkey_footer::{HotkeyFooter, Hotkey}` and `ratatui::Frame` are imported. ```rust use ratkit::widgets::hotkey_footer::{HotkeyFooter, Hotkey}; use ratatui::Frame; fn render_footer(frame: &mut Frame) { let footer = HotkeyFooter::new(vec![ Hotkey::new("q", "Quit"), Hotkey::new("s", "Save"), Hotkey::new("n", "New File"), Hotkey::new("?", "Help"), ]); frame.render_widget(footer, bottom_area); } ``` -------------------------------- ### Render TreeView Widget Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/tree-view.mdx Demonstrates how to create and render a basic TreeView with nested nodes. Requires `TreeView`, `TreeNode`, and `TreeState` from `ratkit::primitives::tree_view`. ```rust use ratkit::primitives::tree_view::{TreeView, TreeNode, TreeState}; use ratatui::Frame; fn render_tree(frame: &mut Frame) { let tree = TreeView::new(vec![ TreeNode::new("src") .child(TreeNode::new("main.rs")) .child(TreeNode::new("lib.rs")), TreeNode::new("Cargo.toml"), ]); let mut state = TreeState::default(); frame.render_stateful_widget(tree, frame.area(), &mut state); } ``` -------------------------------- ### Syntax Highlighting Configuration Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/src/widgets/markdown_preview/widgets/markdown_widget/README.md Use the SyntaxHighlighter and palettes to customize code block appearance. ```rust use ratatui_toolkit::markdown_widget::extensions::theme::SyntaxHighlighter; let highlighter = SyntaxHighlighter::new(); // Highlight a line of code let highlighted = highlighter.highlight("fn main() {}", "rust"); ``` ```rust use ratatui_toolkit::markdown_widget::extensions::theme::palettes; let dark_palette = palettes::dark_default(); let light_palette = palettes::light_default(); ``` -------------------------------- ### Monitor files with File Watcher Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/(get-started)/basic-usage.mdx Sets up a service to watch for file system changes. ```rust use ratkit::services::file_watcher::FileWatcher; let watcher = FileWatcher::new("./src") .on_change(|event| { println!("File changed: {:?}", event); }); ``` -------------------------------- ### Initialize MouseRouter with custom configuration Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/api/core/mouse_router.md Create a new instance of MouseRouter using a custom MouseRouterConfig to define capture duration. ```rust use ratkit::prelude::*; let mut router = MouseRouter::with_config(MouseRouterConfig { capture_duration: Duration::from_secs(5), ..Default::default() }); ``` -------------------------------- ### For the full bundle of components Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md This snippet shows how to include all ratkit components by using the "all" feature flag. ```toml [dependencies] ratkit = { version = "0.2.16", features = ["all"] } ``` -------------------------------- ### Help Command Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md Command to display all available 'just' commands. ```bash just help ``` -------------------------------- ### Create a Button primitive Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/(get-started)/basic-usage.mdx Configures an interactive button with custom styles. ```rust use ratkit::primitives::button::{Button, ButtonState}; use ratatui::style::{Style, Color, Modifier}; let button = Button::new("Submit") .style(Style::default().fg(Color::White)) .highlight_style(Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)); ``` -------------------------------- ### For selected components Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/README.md This snippet demonstrates how to include specific ratkit components by listing them in the features. ```toml [dependencies] ratkit = { version = "0.2.16", default-features = false, features = ["markdown-preview", "tree-view", "button"] } ``` -------------------------------- ### FileSystemTree Import/Invoke Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md How to import and invoke the FileSystemTree widget. ```rust use ratkit::widgets::file_system_tree::{FileSystemTree, FileSystemTreeState, FileSystemTreeConfig}; ``` -------------------------------- ### Integrate Services with TUI Event Loop Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/services/index.mdx Shows how to integrate service updates within a ratatui application's main event loop. This pattern allows for continuous background processing while the UI remains responsive. ```rust use ratatui::crossterm::event::{self, Event, KeyCode}; use std::time::Duration; loop { // Poll for events with timeout if event::poll(Duration::from_millis(100))? { match event::read()? { Event::Key(key) => handle_key(key), _ => {} } } // Service updates happen automatically // Redraw UI terminal.draw(|frame| render(frame))?; } ``` -------------------------------- ### Load Markdown from a File Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/src/widgets/markdown_preview/widgets/markdown_widget/README.md Load document content from a file path using MarkdownState. ```rust use ratatui_toolkit::markdown_widget::{MarkdownState, MarkdownWidget}; let mut state = MarkdownState::default(); state.source.set_source_file("path/to/document.md"); let content = state.content().to_string(); let widget = MarkdownWidget::from_state(&content, &mut state) .show_toc(true); ``` -------------------------------- ### Configure RepoWatcher File and Git Settings Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/services/repo-watcher.mdx Configures the file watching include/exclude patterns and the git polling interval for the RepoWatcher service. ```rust let watcher = RepoWatcher::new("./") .file_config(|config| { config .include(vec!["*.rs"]) .exclude(vec!["target/*"]) }) .git_config(|config| { config.poll_interval(Duration::from_secs(5)) }); ``` -------------------------------- ### Build Command Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/skills/ratkit/SKILL.md Command to build the Ratkit project. ```bash just build cargo build -p ratkit --all-features ``` -------------------------------- ### Configure Display Settings Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/src/widgets/markdown_preview/widgets/markdown_widget/README.md Adjust the visual appearance of the widget, including line numbers and themes. ```rust use ratatui_toolkit::markdown_widget::state::DisplaySettings; let display = DisplaySettings::default() .show_line_numbers(true) .show_document_line_numbers(true) .show_heading_collapse(true) .set_code_block_theme(CodeBlockTheme::DarkDefault); ``` -------------------------------- ### Handle Button Click Event Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/button.mdx Illustrates how to detect and handle a button click event, specifically when the Enter key is pressed while the button is focused. Requires importing Event and KeyCode from ratatui.crossterm.event. ```rust use ratatui::crossterm::event::{Event, KeyCode}; if let Event::Key(key) = event.read()? { match key.code { KeyCode::Enter if button_state.is_focused() => { // Button clicked } _ => {} } } ``` -------------------------------- ### Show Basic Toast Notification Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/primitives/toast.mdx Demonstrates how to create and display a success toast notification with a specified duration. Requires importing Toast and ToastType. ```rust use ratkit::primitives::toast::{Toast, ToastType}; fn show_notification() { let toast = Toast::new("Operation completed!") .toast_type(ToastType::Success) .duration(Duration::from_secs(3)); toast.show(); } ``` -------------------------------- ### Configure Widget Styling Source: https://github.com/alpha-innovation-labs/ratkit/blob/master/docs/content/docs/widgets/index.mdx Apply custom themes and code highlighting themes to a widget instance. These settings override the default widget appearance. ```rust let widget = MarkdownPreview::new(content) .theme(Theme::Dark) .code_theme(CodeTheme::Dracula); ```