### Clone and Run ZFish Examples - Git and Cargo Setup Source: https://zfish-devdocs.vercel.app/examples Instructions for cloning the ZFish repository and running examples locally using Cargo. Demonstrates compilation and execution of the hello_world example with typical build output. ```bash git clone https://github.com/JeetKarena/ZFish.git cd ZFish cargo run --example 01_hello_world ``` -------------------------------- ### ZFish Quick Start: Hello World Example (Rust) Source: https://zfish-devdocs.vercel.app/index A basic 'Hello World' example demonstrating how to use the ZFish framework in Rust to print colored text to the terminal. It utilizes the `print` macro and color styles. ```Rust use zfish::{style::Color, print}; fn main() { print("Hello, ", Color::Green); print("ZFish!", Color::Blue.bold()); println!(); } ``` -------------------------------- ### Hello World - Basic Colored Output in Rust Source: https://zfish-devdocs.vercel.app/examples Demonstrates basic ZFish usage with colored text output. Uses the print function with Color enum to display text in different colors. This is the entry point example for new users learning ZFish. ```rust use zfish::{style::Color, print}; fn main() { print("Hello, ", Color::Green); print("ZFish!", Color::Blue.bold()); println!(); } ``` -------------------------------- ### Complete CLI - Full-Featured CLI Application in Rust Source: https://zfish-devdocs.vercel.app/examples Comprehensive example combining multiple ZFish features (argument parsing, progress tracking, logging) into a complete CLI application. Demonstrates error handling and pattern for building production-ready CLI tools. ```rust use zfish::{args::Args, style::Color, progress::Progress}; fn main() -> Result<(), Box> { let mut args = Args::new(); args.add_positional("file", "File to process"); args.add_flag("verbose", "Verbose output"); let matches = args.parse()?; let file = matches.get_positional("file")?; let verbose = matches.get_flag("verbose"); if verbose { println!("Processing file: {}", file); } let mut progress = Progress::new(100); for i in 0..=100 { progress.set_position(i); std::thread::sleep(std::time::Duration::from_millis(10)); } progress.finish_with_message("Processing complete!"); Ok(()) } ``` -------------------------------- ### Install ZFish CLI Framework (Rust) Source: https://zfish-devdocs.vercel.app/index Instructions for installing the ZFish CLI framework using Cargo, the Rust package manager. This can be done by adding it as a dependency to your project. ```Rust cargo add zfish ``` ```TOML [dependencies] zfish = "0.1" ``` -------------------------------- ### ZFish Progress Bar Implementation Source: https://zfish-devdocs.vercel.app/getting-started A Rust example demonstrating the creation and usage of a ZFish progress bar. It shows how to initialize a progress bar, update its status, set messages, and finish with a completion message. ```rust use zfish::progress::Progress; use std::thread; use std::time::Duration; let mut progress = Progress::new(100); progress.set_message("Processing..."); for i in 0..=100 { progress.set_position(i); thread::sleep(Duration::from_millis(50)); } progress.finish_with_message("Done!"); ``` -------------------------------- ### Implementing Subcommands with ZFish Source: https://zfish-devdocs.vercel.app/components/args Shows how to create CLI applications with subcommands, similar to Git, using `zfish::command::{App, Command}`. This example defines 'build' and 'run' subcommands with their own arguments and demonstrates how to match and handle subcommand execution. Dependencies include `zfish` crate. ```rust use zfish::command::{App, Command}; let app = App::new("myapp") .version("0.1.0") .about("My awesome CLI tool"); // Add subcommands let build_cmd = Command::new("build") .about("Build the project") .arg("--release", "Build in release mode"); let run_cmd = Command::new("run") .about("Run the application") .arg("--debug", "Run in debug mode"); app.command(build_cmd) .command(run_cmd) .parse(); match app.matches()?.subcommand() { Some(("build", matches)) => { let release = matches.get_flag("release"); println!("Building in {} mode", if release { "release" } else { "debug" }); } Some(("run", matches)) => { println!("Running application..."); } _ => println!("No subcommand specified"), } ``` -------------------------------- ### Install ZFish using Cargo Source: https://zfish-devdocs.vercel.app/getting-started This snippet demonstrates how to add the ZFish crate as a dependency to your Rust project using the `cargo add` command. It's the recommended method for easy integration. ```shell cargo add zfish ``` -------------------------------- ### Interactive Prompts - User Input and Selection in Rust Source: https://zfish-devdocs.vercel.app/examples Shows ZFish's interactive prompt components (Confirm, Input, Select) for gathering user input. Each prompt type supports customization with defaults and placeholders for enhanced user experience. ```rust use zfish::prompt::{Confirm, Input, Select}; let confirmed = Confirm::new("Do you want to continue?") .default(true) .prompt()?; let name = Input::new("What is your name?") .placeholder("Enter your name") .prompt()?; let choice = Select::new("Choose an option:") .items(&["Option 1", "Option 2", "Option 3"]) .default(0) .prompt()?; ``` -------------------------------- ### Basic Colored Terminal Output in ZFish Source: https://zfish-devdocs.vercel.app/examples/01_hello_world Demonstrates ZFish's Color module for creating colored terminal output. It shows basic colors, bright variants, and the 256-color palette using the `paint()` method. Dependencies include the `zfish::style::Color` module. ```rust // Example 1: Hello World - The simplest zfish program use zfish::style::Color; fn main() { println!("{}", Color::Green.paint("Hello, zfish! 🐟")); // Multiple colors println!( "{} {} {}", Color::Red.paint("Red"), Color::Yellow.paint("Yellow"), Color::Blue.paint("Blue") ); // Bright colors println!("{}", Color::BrightCyan.paint("Bright Cyan Text")); // Custom 256 colors println!("{}", Color::Custom(208).paint("Orange (256-color palette)")); } ``` -------------------------------- ### Convert Multiple Files Source: https://zfish-devdocs.vercel.app/examples/10_arg_features_v2 Example of converting multiple files to a target format. Shows how variadic arguments can accept a list of files. ```shell cargo run --example 10_arg_features_v2 -- convert file1.md file2.md file3.md --target pdf ``` -------------------------------- ### Terminal Control - Cursor and Screen Manipulation in Rust Source: https://zfish-devdocs.vercel.app/examples Demonstrates ZFish terminal control functions for cursor movement, screen clearing, and size detection. Enables fine-grained control over terminal output positioning and layout. ```rust use zfish::term; // Clear screen and move cursor term::clear_screen()?; term::move_cursor(5, 10)?; print("Hello at position 5,10!", Color::Green); // Get terminal size let (width, height) = term::size()?; println!("Terminal size: {}x{}", width, height); ``` -------------------------------- ### Process File with Tags Source: https://zfish-devdocs.vercel.app/examples/10_arg_features_v2 Example of processing a single file with specified output format and tags. Demonstrates passing multiple flag arguments. ```shell cargo run --example 10_arg_features_v2 -- process input.txt -o output.json -f json -t rust,cli,tool ``` -------------------------------- ### Creating Interactive Prompts with ZFish Source: https://zfish-devdocs.vercel.app/components Facilitates user interaction through prompts for input, confirmations, and selections. The `Confirm` prompt, for example, asks a yes/no question and returns a boolean result. Dependencies include the `zfish::prompt` module. ```rust use zfish::prompt::Confirm; fn main() -> Result<(), Box> { let answer = Confirm::new("Continue?") .prompt()?; println!("User answered: {}", answer); Ok(()) } ``` -------------------------------- ### Progress Bar - Animated Progress Tracking in Rust Source: https://zfish-devdocs.vercel.app/examples Illustrates ZFish's Progress API for displaying animated progress bars with position updates and completion messages. Useful for long-running operations that need user feedback. ```rust use zfish::progress::Progress; let mut progress = Progress::new(100); progress.set_message("Downloading..."); for i in 0..=100 { progress.set_position(i); std::thread::sleep(std::time::Duration::from_millis(20)); } progress.finish_with_message("Download complete!"); ``` -------------------------------- ### Colored Text - 16 and 256 Color Palette in Rust Source: https://zfish-devdocs.vercel.app/examples Demonstrates ZFish's comprehensive color support using both basic 16-color palette and extended 256-color mode. Shows how to apply colors to text output and create visually rich terminal applications. ```rust use zfish::style::Color; // 16 basic colors print("Red", Color::Red); print("Green", Color::Green); print("Blue", Color::Blue); // 256 colors print("Orange", Color::from_256(208)); print("Purple", Color::from_256(129)); ``` -------------------------------- ### Argument Parsing - CLI Argument Handling in Rust Source: https://zfish-devdocs.vercel.app/examples Shows how to parse command-line arguments and flags using ZFish Args API. Demonstrates adding positional arguments and flags, then parsing and retrieving values. Essential for building CLI tools that accept user input. ```rust use zfish::args::{Args, Command}; let mut args = Args::new(); args.add_positional("name", "Your name"); args.add_flag("verbose", "Enable verbose output"); let matches = args.parse()?; let name = matches.get_positional("name")?; let verbose = matches.get_flag("verbose"); ``` -------------------------------- ### Automatic Help Generation with ZFish Command Source: https://zfish-devdocs.vercel.app/components/args Explains how to leverage ZFish's `command::App` to automatically generate help text for your CLI application. By defining arguments and options with `arg()`, ZFish can produce a standard help message including usage, options, and version information. This example shows how to define arguments like `--config`, `--verbose`, and `-h, --help`. ```rust use zfish::command::App; let app = App::new("myapp") .version("0.1.0") .author("Your Name ") .about("Description of your app") .arg("--config", "Configuration file path") .arg("--verbose", "Enable verbose output") .arg("-h, --help", "Print help information"); // Running with --help will print: app.parse(); ``` -------------------------------- ### Basic Progress Bar Example - Rust Source: https://zfish-devdocs.vercel.app/components/progress Demonstrates how to create and update a basic progress bar to its completion. This involves initializing the progress bar with a total value, setting the current progress in a loop, and finally finishing with a message. It utilizes the `ProgressBar` struct from the `zfish` crate. ```rust use zfish::ProgressBar; use std::thread; use std::time::Duration; let mut pb = ProgressBar::new(100); for i in 0..=100 { pb.set(i); thread::sleep(Duration::from_millis(50)); } pb.finish("✓ Complete!"); ``` -------------------------------- ### ZFish Terminal Coloring Examples Source: https://zfish-devdocs.vercel.app/getting-started This Rust code illustrates ZFish's capabilities for terminal coloring, including basic colors and text styles like bold and italic. It uses the `Color` enum and its methods for applying styles. ```rust use zfish::style::Color; // Basic colors print("Red text", Color::Red); print("Green text", Color::Blue.bold()); // Styles print("Bold text", Color::Blue.bold()); print("Italic text", Color::Yellow.italic()); ``` -------------------------------- ### Incremental Progress Bar Example - Rust Source: https://zfish-devdocs.vercel.app/components/progress Shows how to incrementally update a progress bar using the `.inc()` method. This is useful for tasks where progress is advanced in fixed steps. The example increments the progress bar by 1 in each iteration of a loop until completion, followed by a final message. ```rust use zfish::ProgressBar; use std::time::Duration; let mut pb = ProgressBar::new(50); for _ in 0..50 { pb.inc(1); std::thread::sleep(Duration::from_millis(30)); } pb.finish("✓ Incremental done!"); ``` -------------------------------- ### Basic Logging in Rust with ZFish Logger Source: https://zfish-devdocs.vercel.app/components/logger This example demonstrates basic logging using the ZFish Logger. It shows how to instantiate a logger and log messages at different severity levels: INFO, WARN, ERROR, DEBUG, and TRACE. The output will display these messages with their corresponding levels. ```rust use zfish::log::{Logger, Level}; let logger = Logger::new(); logger.info("Application started"); logger.warn("This is a warning"); logger.error("An error occurred"); logger.debug("Debug information"); logger.trace("Trace message"); ``` -------------------------------- ### Render Table with Unicode Characters and Emoji (Rust) Source: https://zfish-devdocs.vercel.app/components/tables Illustrates the ZFish table module's capability to handle and render Unicode characters, including emojis, correctly within table cells. This example adds rows with various Unicode characters and prints the table, showcasing proper display. It requires no special setup beyond importing the Table struct. ```rust use zfish::table::Table; // Create table with headers let mut table = Table::new(vec!["Emoji", "Name", "Category"]); table.add_row(vec!["🚀", "Rocket", "Transport"]); table.add_row(vec!["🎨", "Palette", "Art"]); table.add_row(vec!["🐟", "Fish", "Animal"]); table.add_row(vec!["你好", "Hello (Chinese)", "Language"]); table.print(); ``` -------------------------------- ### ZFish: Combine Text Styles and Colors Source: https://zfish-devdocs.vercel.app/components/colors Illustrates how to combine different text styles (bold, italic, underline) with colors using ZFish. It also includes an example of creating a rainbow effect by iterating through a list of colors. ```Rust use zfish::style::{Color, Style}; // Combine multiple styles println!("{}", Color::Cyan.paint("Bold + Italic + Underline").style(Style::Bold).style(Style::Italic).style(Style::Underline)); // Rainbow example let rainbow_colors = [ Color::Red, Color::Yellow, Color::Green, Color::Cyan, Color::Blue, Color::Magenta, ]; for color in rainbow_colors { print!("{}", color.paint("█████ ")); } println!(); ``` -------------------------------- ### Parsing Options with Values in ZFish Source: https://zfish-devdocs.vercel.app/components/args Illustrates how to parse command-line options that accept values using `zfish::Args`. It covers retrieving option values like 'output', 'config', and 'count', including type casting for numerical options. Usage example provided. ```rust use zfish::Args; let args = Args::parse(); // Get option values if let Some(output) = args.get_option("output").or_else(|| args.get_option("o")) { println!("Output file: {}", output); } if let Some(config) = args.get_option("config") { println!("Config: {}", config); } if let Some(count) = args.get_option("count") { let count: usize = count.parse().unwrap(); println!("Count: {}", count); } // Usage: myapp --output file.txt --count 5 ``` -------------------------------- ### Logger - Structured Logging with Levels in Rust Source: https://zfish-devdocs.vercel.app/examples Shows how to use ZFish's Logger for structured logging with different severity levels (info, warn, error, debug). Each log level produces colored, prefixed output for easy debugging and monitoring. ```rust use zfish::log::{Logger, Level}; let logger = Logger::new(); // Different log levels logger.info("Application started"); logger.warn("This is a warning"); logger.error("This is an error"); logger.debug("Debug information"); ``` -------------------------------- ### Formatted Logging in Rust with ZFish Logger Source: https://zfish-devdocs.vercel.app/components/logger This example demonstrates how to use formatted log messages with the ZFish Logger. It utilizes Rust's `format!` macro to include dynamic data, such as user names and counts, within log messages. This allows for more informative and context-aware logging. ```rust use zfish::log::Logger; let logger = Logger::new(); let user = "Alice"; let count = 42; logger.info(&format!("User {} logged in", user)); logger.debug(&format!("Processing {} items", count)); logger.error(&format!("Failed to process item {}", count)); ``` -------------------------------- ### Get Terminal Size with ZFish Source: https://zfish-devdocs.vercel.app/components/terminal Retrieves the current dimensions (width and height) of the terminal. This function is useful for responsive terminal applications. It returns an `Option<(u16, u16)>`. Outputs the terminal size or an error message. ```rust use zfish::term::Terminal; // Get terminal size (width, height) if let Some((width, height)) = Terminal::size() { println!("Terminal size: {}x{}", width, height); } else { println!("Could not detect terminal size"); } ``` -------------------------------- ### Create Styled Table with Colors and Double Borders (Rust) Source: https://zfish-devdocs.vercel.app/components/tables Illustrates how to customize the appearance of a table using colors for borders and text, along with applying a double box style. This example showcases setting a specific box style and border color before adding rows, resulting in a visually distinct table output. Requires the zfish::style::Color enum. ```rust use zfish::table::Table; use zfish::style::Color; // Create table with headers let mut table = Table::new(vec!["Product", "Price", "Stock"]); table.set_box_style(BoxStyle::Double); // Add colored rows table.add_row(&["Laptop", "$999", "In Stock"]); table.add_row(&["Mouse", "$25", "Low Stock"]); table.add_row(&["Keyboard", "$75", "Out of Stock"]); // Set border color table.set_border_color(Color::Blue); table.print(); ``` -------------------------------- ### ZFish: Use 256-Color Palette for Custom Terminal Colors Source: https://zfish-devdocs.vercel.app/components/colors Shows how to utilize the extended 256-color palette in ZFish by using the `Color::Custom(n)` variant, where `n` is a number from 0 to 255. Examples include specific colors and a loop to print a range of colors. ```Rust use zfish::style::Color; // Use 256-color palette with Custom(n) println!("{}", Color::Custom(208).paint("Orange")); println!("{}", Color::Custom(129).paint("Purple")); println!("{}", Color::Custom(213).paint("Pink")); println!("{}", Color::Custom(80).paint("Teal")); // Colors range from 0-255 for i in [196, 202, 208, 214, 220, 226] { println!("{}", Color::Custom(i).paint(format!("Color {}", i))); } ``` -------------------------------- ### Align Table Columns Left, Center, and Right (Rust) Source: https://zfish-devdocs.vercel.app/components/tables Shows how to control the alignment of text within individual columns of a table. This example sets specific alignments (Left, Center, Right) for each column before adding rows, demonstrating precise control over table formatting. It utilizes the Alignment enum from zfish::table. ```rust use zfish::table::{Table, Alignment}; // Create table with headers let mut table = Table::new(vec!["Item", "Quantity", "Price"]); // Set column alignments table.set_column_alignment(0, Alignment::Left); table.set_column_alignment(1, Alignment::Center); table.set_column_alignment(2, Alignment::Right); // Add rows table.add_row(vec!["Apple", "10", "$1.50"]); table.add_row(vec!["Banana", "5", "$0.80"]); table.add_row(vec!["Orange", "8", "$1.20"]); table.print(); ``` -------------------------------- ### Custom Log Levels in Rust with ZFish Logger Source: https://zfish-devdocs.vercel.app/components/logger This example shows how to filter log messages by setting a minimum severity level using the ZFish Logger. By setting the level to WARN, only messages with severity WARN or higher (ERROR) will be displayed. INFO, DEBUG, and TRACE messages will be suppressed. ```rust use zfish::log::{Logger, Level}; // Set log level using builder pattern let logger = Logger::new().level(Level::Warn); // These will be shown logger.error("Error message"); logger.warn("Warning message"); // These will be hidden (below Warn level) logger.info("Info message"); logger.debug("Debug message"); ``` -------------------------------- ### Hello World with ZFish Styling Source: https://zfish-devdocs.vercel.app/getting-started A basic Rust program that utilizes the ZFish crate to print colored and styled text to the console. It showcases the `print` function with different color and style options. ```rust use zfish::{style::Color, print}; fn main() { print("Hello, ", Color::Green); print("ZFish!", Color::Blue.bold()); println!(); // New line } ``` -------------------------------- ### Create Basic Table with Headers and Rows (Rust) Source: https://zfish-devdocs.vercel.app/components/tables Demonstrates how to create a simple table with headers and add data rows using the ZFish table module. This function initializes a table, adds multiple rows of data, and then prints the formatted table to the console. No external dependencies beyond the zfish crate are required. ```rust use zfish::table::Table; // Create table with headers let mut table = Table::new(vec!["Name", "Age", "City"]); // Add data rows table.add_row(vec!["Alice", "25", "New York"]); table.add_row(vec!["Bob", "30", "London"]); table.add_row(vec!["Charlie", "28", "Tokyo"]); // Print the table table.print(); ``` -------------------------------- ### Structured Logging with ZFish Source: https://zfish-devdocs.vercel.app/components Implements structured logging with support for different levels (e.g., INFO, WARN, ERROR), colors, and configurable output. It requires initializing a `Logger` instance. Dependencies include the `zfish::log` module. ```rust use zfish::log::{Logger, Level}; fn main() { let logger = Logger::new(); logger.info("Application started"); logger.warn("Configuration file not found"); } ``` -------------------------------- ### Basic Argument Parsing with ZFish Args Source: https://zfish-devdocs.vercel.app/components/args Demonstrates how to parse command-line arguments using the `zfish::Args` struct. It shows how to access the command, check for flags like 'verbose' or 'v', and retrieve positional arguments. Dependencies include the `zfish` crate. ```rust use zfish::Args; // Parse command-line arguments let args = Args::parse(); println!("Command: {}", args.command); // Check for flags if args.has_flag("verbose") || args.has_flag("v") { println!("Verbose mode enabled"); } if args.has_flag("help") || args.has_flag("h") { println!("Help requested"); } // Get positional arguments if !args.positional.is_empty() { println!("Files: {:?}", args.positional); } ``` -------------------------------- ### Rendering Tables with ZFish Source: https://zfish-devdocs.vercel.app/components Automates the rendering of tables in the terminal, supporting Unicode characters and custom styling. Rows are added as string slices, and the `print` method outputs the formatted table. Dependencies include the `zfish::table::Table` module. ```rust use zfish::table::Table; fn main() { let mut table = Table::new(); table.add_row(vec!["Name", "Age", "City"]); table.add_row(vec!["Alice", "25", "NYC"]); table.print(); } ``` -------------------------------- ### ZFish: Apply Text Styling (Bold, Italic, Underline) Source: https://zfish-devdocs.vercel.app/components/colors Demonstrates applying various text styles like bold, italic, underline, and dim to text using the `.style()` method in ZFish. It lists the available style options. ```Rust use zfish::style::{Color, Style}; // Apply styles using .style() method println!("{}", Color::White.paint("Bold text").style(Style::Bold)); println!("{}", Color::White.paint("Italic text").style(Style::Italic)); println!("{}", Color::White.paint("Underlined").style(Style::Underline)); println!("{}", Color::White.paint("Dim text").style(Style::Dim)); // Available styles: // Style::Bold, Style::Dim, Style::Italic // Style::Underline, Style::Blink, Style::Reverse, Style::Hidden ``` -------------------------------- ### ZFish: List of Available Colors Source: https://zfish-devdocs.vercel.app/components/colors Provides a comprehensive list of all available colors in ZFish, including standard 16 ANSI colors, their bright variants, and how to reference custom colors from the 256-color palette. ```Rust use zfish::style::Color; // Standard colors // Color::Black, Color::Red, Color::Green, Color::Yellow // Color::Blue, Color::Magenta, Color::Cyan, Color::White // Bright variants // Color::BrightBlack, Color::BrightRed, Color::BrightGreen // Color::BrightYellow, Color::BrightBlue, Color::BrightMagenta // Color::BrightCyan, Color::BrightWhite // Custom 256-color (0-255) // Color::Custom(208) // Orange // Color::Custom(129) // Purple ``` -------------------------------- ### Applying Colors and Styles to Terminal Output with ZFish Source: https://zfish-devdocs.vercel.app/components Renders text in the terminal with support for 16, 256, and true color, including styles like bold. It takes string literals and `Color` enum variants as input and prints styled output directly to the console. Dependencies include the `zfish::style::Color` module. ```rust use zfish::style::Color; fn main() { print!("{}", Color::Red.paint("Hello")); print!("{}", Color::Green.bold().paint("World")); } ``` -------------------------------- ### Confirmation Prompt - Rust Source: https://zfish-devdocs.vercel.app/components/prompts Asks the user a yes/no question and returns a boolean based on their input. The second parameter sets the default value if the user just presses Enter. Returns a Result, so error handling is required. ```rust use zfish::Prompt; // Prompt for yes/no confirmation // Second parameter is default value let answer = Prompt::confirm("Do you want to continue?", true)?; if answer { println!("Continuing..."); } else { println!("Aborted."); } ``` -------------------------------- ### Rust: Advanced CLI Argument Parsing with ZFish v0.2.1 Source: https://zfish-devdocs.vercel.app/examples/10_arg_features_v2 This Rust code snippet demonstrates advanced argument parsing using the ZFish library version 0.2.1. It showcases positional arguments, variadic arguments, environment variable fallbacks, argument dependencies, conflicts, value delimiters, and command aliases for creating sophisticated command-line interfaces. The code expects CLI arguments as input and outputs parsed values or subcommand-specific information. ```rust // Argument Features v0.2.1 Example // Demonstrates all v0.2.1 advanced argument parsing features use zfish::Color; use zfish::command::{App, Arg, Command}; fn main() { let app = App::new("myapp") .version("2.0.0") .about("Advanced CLI with v0.2.1 features") .arg( Arg::new("config") .short('c') .long("config") .about("Configuration file path") .env("MYAPP_CONFIG") // Falls back to MYAPP_CONFIG environment variable .default_value("config.toml"), ) .arg( Arg::new("verbose") .short('v') .long("verbose") .about("Enable verbose output") .takes_value(false) .conflicts_with("quiet"), // Cannot be used with --quiet ) .arg( Arg::new("quiet") .short('q') .long("quiet") .about("Suppress output") .takes_value(false) .conflicts_with("verbose"), // Cannot be used with --verbose ) .subcommand( Command::new("process") .alias("proc") // Alias: can use "proc" instead of "process" .alias("p") .about("Process files with advanced options") .arg( Arg::new("input") .index(0) // Positional argument at position 0 .about("Input file to process") .required(true), ) .arg( Arg::new("output") .short('o') .long("output") .about("Output file") .requires("format"), // Requires --format to be specified ) .arg( Arg::new("format") .short('f') .long("format") .about("Output format") .possible_values(&["json", "xml", "yaml"])), ) .arg( Arg::new("tags") .short('t') .long("tags") .about("Comma-separated tags") .value_delimiter(','), // Parses "rust,cli,tool" into ["rust", "cli", "tool"] ), ) .subcommand( Command::new("convert") .alias("cv") .about("Convert files with multiple inputs") .arg( Arg::new("files") .index(0) .last(true) // Variadic positional: captures all remaining args .about("Files to convert") .required(true), ) .arg( Arg::new("target") .long("target") .about("Target format") .required(true) .possible_values(&["pdf", "png", "svg"])), ); let matches = app.get_matches(); // Check config (from CLI, env var, or default) if let Some(config) = matches.value_of("config") { println!("→ Using config: {}", Color::Cyan.paint(config)); } // Check verbose/quiet if matches.is_present("verbose") { println!("→ Verbose mode enabled"); } else if matches.is_present("quiet") { println!("→ Quiet mode enabled"); } // Handle subcommands match matches.subcommand() { Some(("process", sub_matches)) | Some(("proc", sub_matches)) | Some(("p", sub_matches)) => { println!("\n{} Processing file", Color::Green.paint("✓")); if let Some(input) = sub_matches.value_of("input") { println!(" Input: {}", Color::Yellow.paint(input)); } if let Some(output) = sub_matches.value_of("output") { println!(" Output: {}", Color::Yellow.paint(output)); if let Some(format) = sub_matches.value_of("format") { println!(" Format: {}", Color::Yellow.paint(format)); } } if let Some(tags) = sub_matches.values_of("tags") { println!(" Tags: {}", tags.join(", ")); } } Some(("convert", sub_matches)) | Some(("cv", sub_matches)) => { println!("\n{} Converting files", Color::Green.paint("✓")); if let Some(files) = sub_matches.values_of("files") { println!(" Files: {}", files.join(", ")); } if let Some(target) = sub_matches.value_of("target") { println!(" Target format: {}", Color::Yellow.paint(target)); } } _ => { println!("\n{} No subcommand specified", Color::Yellow.paint("⚠")); println!("Run with --help for usage information"); } } } ``` -------------------------------- ### Argument Parsing with Flags and Options in ZFish Source: https://zfish-devdocs.vercel.app/components Parses command-line arguments including flags, options, and subcommands using ZFish's `Args` struct. It takes no specific input but processes `std::env::args()` and returns a `Result` containing the parsed arguments or an error. Dependencies include the `zfish::args` module. ```rust use zfish::args::Args; fn main() -> Result<(), Box> { let mut args = Args::new(); args.add_flag("verbose", "Verbose output"); let matches = args.parse()?; // Use matches here... Ok(()) } ``` -------------------------------- ### Displaying Progress Bars with ZFish Source: https://zfish-devdocs.vercel.app/components Creates and updates visual progress bars in the terminal with various styles and real-time feedback. It requires an initial total value and allows setting the current position to reflect progress. Dependencies include the `zfish::progress::Progress` module. ```rust use zfish::progress::Progress; fn main() { let mut progress = Progress::new(100); progress.set_position(50); // Progress bar will be displayed in the terminal } ``` -------------------------------- ### Text Input Prompt - Rust Source: https://zfish-devdocs.vercel.app/components/prompts Obtains text input from the user. The `Prompt::input()` function is used, and `Prompt::text()` is an alias for the same functionality. The input is returned as a String. Requires error handling. ```rust use zfish::Prompt; // Prompt for text input let name = Prompt::input("What is your name?")?; println!("Hello, {}!", name); // Alternative: Prompt::text() (alias for input) let lang = Prompt::text("Favorite language?")?; println!("You chose: {}", lang); ``` -------------------------------- ### Parse CLI Arguments with ZFish in Rust Source: https://zfish-devdocs.vercel.app/examples/02_argument_parsing This Rust code snippet demonstrates how to parse command-line arguments using the `zfish::Args` struct. It handles flags like 'verbose' and 'help', options such as 'output' and 'count', and collects positional arguments. The code also includes a function to print a help message based on the parsed arguments. ```rust use zfish::Args; fn main() { // Parse command-line arguments let args = Args::parse(); println!("Command: {}", args.command); // Check for flags if args.has_flag("verbose") || args.has_flag("v") { println!("Verbose mode enabled"); } if args.has_flag("help") || args.has_flag("h") { print_help(); return; } // Get option values if let Some(output) = args.get_option("output").or_else(|| args.get_option("o")) { println!("Output file: {}", output); } if let Some(count) = args.get_option("count") { println!("Count: {}", count); } // Get positional arguments if !args.positional.is_empty() { println!("Files: {:?}", args.positional); } } fn print_help() { println!("Usage: {} [OPTIONS] [FILES...]", std::env::args().next().unwrap()); println!(); println!("Options:"); println!(" -h, --help Show this help message"); println!(" -v, --verbose Enable verbose output"); println!(" -o, --output Output file path"); println!(" --count Number of iterations"); } ``` -------------------------------- ### Create Table with ASCII Box Style (Rust) Source: https://zfish-devdocs.vercel.app/components/tables Demonstrates using a different set of box-drawing characters by applying the ASCII style to a table. This is useful for environments where Unicode characters might not render correctly. The code snippet initializes a table, sets the box style to Ascii, adds a row, and prints the result. ```rust use zfish::table::{Table, BoxStyle}; // Create table with headers let mut table = Table::new(vec!["Header 1", "Header 2", "Header 3"]); // Use ASCII style instead of Unicode table.set_box_style(BoxStyle::Ascii); table.add_row(vec!["Data 1", "Data 2", "Data 3"]); table.print(); ``` -------------------------------- ### Use Command Alias in Execution Source: https://zfish-devdocs.vercel.app/examples/10_arg_features_v2 Demonstrates using a defined command alias ('p') to execute the 'process' command. ```shell cargo run --example 10_arg_features_v2 -- p input.txt # "p" is alias for "process" ``` -------------------------------- ### Environment Variable Fallback for Config Source: https://zfish-devdocs.vercel.app/examples/10_arg_features_v2 Shows how an environment variable (`MYAPP_CONFIG`) can provide a configuration file path, overriding default behavior. ```shell export MYAPP_CONFIG=/etc/myapp.toml cargo run --example 10_arg_features_v2 -- --help ``` -------------------------------- ### ZFish: Print Text with Basic ANSI Colors Source: https://zfish-devdocs.vercel.app/components/colors Demonstrates how to print text using the 16 basic ANSI colors provided by the ZFish `style::Color` enum. This includes standard and bright variants for common colors. ```Rust use zfish::style::Color; // Print with basic colors println!("{}", Color::Red.paint("Red text")); println!("{}", Color::Green.paint("Green text")); println!("{}", Color::Blue.paint("Blue text")); println!("{}", Color::Yellow.paint("Yellow text")); // Bright variants println!("{}", Color::BrightRed.paint("Bright red")); println!("{}", Color::BrightGreen.paint("Bright green")); ``` -------------------------------- ### Define Command Aliases Source: https://zfish-devdocs.vercel.app/examples/10_arg_features_v2 Allows defining short aliases for commands for convenience. Multiple aliases can be associated with a single command. ```rust Command::new("process") .alias("proc") .alias("p") // Can use "process", "proc", or "p" ``` -------------------------------- ### Custom Progress Bar Styles and Width - Rust Source: https://zfish-devdocs.vercel.app/components/progress Illustrates how to apply different visual styles and set a custom width for the ZFish progress bar. It demonstrates using `ProgressStyle` enum variants like `Arrow`, `Dots`, and `Spinner`, as well as the `.width()` method to control the bar's character width. ```rust use zfish::{ProgressBar, ProgressStyle}; // Classic style (default): [========== ] let mut pb = ProgressBar::new(100); // Arrow style: [=========> ] let mut pb = ProgressBar::new(100).with_style(ProgressStyle::Arrow); // Dots style: [********** ] let mut pb = ProgressBar::new(100).with_style(ProgressStyle::Dots); // Spinner style: [/|/|/|/| ] let mut pb = ProgressBar::new(100).with_style(ProgressStyle::Spinner); // Custom width let mut pb = ProgressBar::new(80).width(60); ``` -------------------------------- ### Terminal Control Operations with ZFish Source: https://zfish-devdocs.vercel.app/components Provides functionalities for direct terminal manipulation, including clearing the screen and controlling the cursor position. These operations return a `Result` to handle potential terminal errors. Dependencies include the `zfish::term` module. ```rust use zfish::term; fn main() -> Result<(), Box> { term::clear_screen()?; term::move_cursor(10, 5)?; println!("Cursor is now at 10,5"); Ok(()) } ``` -------------------------------- ### Password Input Prompt - Rust Source: https://zfish-devdocs.vercel.app/components/prompts Securely prompts the user for a password. Input is hidden during typing for security and is not echoed to the terminal. Requires error handling and returns the password as a String. ```rust use zfish::Prompt; // Prompt for password with hidden input let password = Prompt::password("Enter password:")?; println!("✓ Password accepted (hidden)"); // Password input is not echoed to terminal // The input is completely hidden for security ``` -------------------------------- ### Draw Custom Boxes with Colored Borders (Rust) Source: https://zfish-devdocs.vercel.app/components/tables Demonstrates drawing custom boxes with optional colored borders and titles using the `draw_box` function from the ZFish table module. This function allows for creating simple, distinct visual elements in the terminal output. It requires importing `draw_box` and the `Color` enum. ```rust use zfish::table::draw_box; use zfish::style::Color; // Draw a colored box draw_box( "Hello, ZFish!", Color::Green, Some(60), true ); // Draw a simple box draw_box( "Simple message", Color::Blue, None, false ); ``` -------------------------------- ### Short Flags Support in ZFish Args Source: https://zfish-devdocs.vercel.app/components/args Demonstrates how to add short, single-letter versions for flags in ZFish argument parsing using `Args::add_flag_with_short`. This allows users to use either the full flag name (e.g., `--verbose`) or its short equivalent (e.g., `-v`), and also supports combining short flags (e.g., `-vf`). ```rust use zfish::args::Args; let mut args = Args::new(); // Add flags with short versions args.add_flag_with_short("verbose", 'v', "Verbose output"); args.add_flag_with_short("quiet", 'q', "Quiet mode"); args.add_flag_with_short("force", 'f', "Force operation"); let matches = args.parse()?; // Can use either --verbose or -v if matches.get_flag("verbose") { println!("Verbose mode"); } // Can combine: -vf for --verbose --force if matches.get_flag("force") { println!("Force mode"); } ``` -------------------------------- ### Move Cursor and Print with ZFish Source: https://zfish-devdocs.vercel.app/components/terminal Allows precise control over cursor positioning within the terminal. You can move the cursor to a specific row and column, and then print text at that location. Uses `zfish::term::Terminal`. Outputs cursor movements and printed text. ```rust use zfish::term::Terminal; // Move cursor to position (row, col) - 1-indexed Terminal::move_cursor(10, 5)?; // Print at specific position Terminal::print_at(5, 10, "Hello at row 5, col 10")?; // Move and print Terminal::move_cursor(1, 1)?; println!("Top-left corner"); ``` -------------------------------- ### Clear Terminal Screen with ZFish Source: https://zfish-devdocs.vercel.app/components/terminal Clears the entire terminal screen and moves the cursor to the top-left corner. Requires the `zfish::term::Terminal` module. Outputs a cleared terminal screen. ```rust use zfish::term::Terminal; // Clear entire screen Terminal::clear_screen()?; // Move to top-left corner Terminal::move_cursor(1, 1)?; println!("Screen cleared!"); ``` -------------------------------- ### Handle Variadic Positional Arguments Source: https://zfish-devdocs.vercel.app/examples/10_arg_features_v2 Enables capturing multiple arguments into a single positional argument. Useful for handling lists of files or other repeating inputs. The `last(true)` setting ensures it captures all remaining arguments. ```rust Arg::new("files") .index(0) .last(true) // Captures all remaining arguments ``` -------------------------------- ### Hide and Show Cursor with ZFish Source: https://zfish-devdocs.vercel.app/components/terminal Controls the visibility of the terminal cursor. Useful for preventing cursor flicker during animations or lengthy operations. Requires the `zfish` crate. Outputs no visible change but affects cursor visibility during execution. ```rust use zfish; // Hide cursor term::hide_cursor()?; // Do some work... std::thread::sleep(std::time::Duration::from_secs(2)); // Show cursor again term::show_cursor()?; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.