Example 01Beginner
Hello World
The simplest ZFish program - basic colored terminal output
Overview
Learn the basics of colored terminal output with ZFish
This example demonstrates how to create colored terminal output using ZFish's Color module. It shows basic colors, bright variants, and the 256-color palette.
Complete Code
01_hello_world.rs
// 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)"));
}Output
Hello, zfish! 🐟 Red Yellow Blue Bright Cyan Text Orange (256-color palette)
How It Works
1. Import the Color Module
use zfish::style::Color;Import the Color type to use terminal colors
2. Use Basic Colors
Color::Green.paint("Hello, zfish! 🐟")The paint() method applies color to text
3. Combine Multiple Colors
println!(
"{} {} {}",
Color::Red.paint("Red"),
Color::Yellow.paint("Yellow"),
Color::Blue.paint("Blue")
);Use format strings to combine multiple colored texts
4. Bright Color Variants
Color::BrightCyan.paint("Bright Cyan Text")Use Bright* variants for lighter colors
5. 256-Color Palette
Color::Custom(208).paint("Orange (256-color palette)")Use Custom(n) for 256-color palette (0-255)
Running the Example
Terminal
# Clone the repository
git clone https://github.com/JeetKarena/ZFish.git
cd ZFish
# Run the example
cargo run --example 01_hello_worldOutput
Compiling zfish v0.1.10
Finished dev [unoptimized + debuginfo] target(s) in 2.34s
Running `target/debug/examples/01_hello_world`
Hello, zfish! 🐟
Red Yellow Blue
Bright Cyan Text
Orange (256-color palette)