Examples

Explore 18 comprehensive examples covering all ZFish features. Each example includes runnable code and detailed explanations.

01Hello World
Basic usage with colored output
beginnercolors
Hello World Example
use zfish::{style::Color, print}; fn main() { print("Hello, ", Color::Green); print("ZFish!", Color::Blue.bold()); println!(); }
Output
Hello, ZFish!
02Argument Parsing
CLI argument handling and validation
intermediateargs
Argument Parsing Example
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");
Output
Usage: program [OPTIONS] <name>

Arguments:
  <name>  Your name

Options:
  --verbose  Enable verbose output
03Colored Text
16 + 256 color palette showcase
colorsstyling
Colored Text Example
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));
Output
RedGreenBlueOrangePurple
04Progress Bar
Beautiful progress bars with animations
progressui
Progress Bar Example
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!");
Output
[========================================] 100.0% (100/100) Downloading...
Download complete!
05Logger
Structured logging with colors
loggingdebug
Logger Example
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");
Output
[INFO] Application started
[WARN] This is a warning
[ERROR] This is an error
[DEBUG] Debug information
06Terminal Control
Cursor movement and screen manipulation
terminalcontrol
Terminal Control Example
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);
Output
Hello at position 5,10!
Terminal size: 80x24
07Interactive Prompts
User input and confirmation prompts
interactiveinput
Interactive Prompts Example
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()?;
Output
? Do you want to continue? (Y/n) y
? What is your name? John Doe
? Choose an option: (1) Option 1
  (2) Option 2
  (3) Option 3
> 1
08Complete CLI
Full-featured CLI application
advancedcomplete
Complete CLI Example
use zfish::{args::Args, style::Color, progress::Progress}; fn main() -> Result<(), Box<dyn std::error::Error>> { 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(()) }
Output
Processing file: data.txt
[========================================] 100.0% (100/100)
Processing complete!
Running Examples
All examples are available in the ZFish repository

Clone the repository and run any example:

Terminal
git clone https://github.com/JeetKarena/ZFish.git cd ZFish cargo run --example 01_hello_world
Output
   Compiling zfish v0.1.10
    Finished dev [unoptimized + debuginfo] target(s) in 2.34s
     Running `target/debug/examples/01_hello_world`
Hello, ZFish!