|
| 1 | +use console::{style, Color, Style}; |
| 2 | + |
| 3 | +fn main() { |
| 4 | + // Basic foreground gradient using the builder API |
| 5 | + println!( |
| 6 | + "Foreground gradient: {}", |
| 7 | + style("Hello, gradient world!") |
| 8 | + .fg(Color::TrueColor(255, 0, 0)) |
| 9 | + .fg_end(Color::TrueColor(0, 0, 255)) |
| 10 | + ); |
| 11 | + |
| 12 | + // Background gradient |
| 13 | + println!( |
| 14 | + "Background gradient: {}", |
| 15 | + style(" Rainbow background ") |
| 16 | + .bg(Color::TrueColor(255, 0, 0)) |
| 17 | + .bg_end(Color::TrueColor(0, 255, 0)) |
| 18 | + ); |
| 19 | + |
| 20 | + // Both foreground and background gradients |
| 21 | + println!( |
| 22 | + "Both gradients: {}", |
| 23 | + style("Fancy text!") |
| 24 | + .fg(Color::TrueColor(255, 255, 0)) |
| 25 | + .fg_end(Color::TrueColor(255, 0, 255)) |
| 26 | + .bg(Color::TrueColor(0, 0, 128)) |
| 27 | + .bg_end(Color::TrueColor(0, 128, 0)) |
| 28 | + ); |
| 29 | + |
| 30 | + // Using from_dotted_str for gradient specification |
| 31 | + let gradient_style = Style::from_dotted_str("#ff0000->#00ff00.bold"); |
| 32 | + println!( |
| 33 | + "From dotted string: {}", |
| 34 | + gradient_style.apply_to("Styled from_dotted_str") |
| 35 | + ); |
| 36 | + |
| 37 | + // Gradient with named colors (they get converted to RGB for interpolation) |
| 38 | + println!( |
| 39 | + "Named color gradient: {}", |
| 40 | + style("Red to Blue").fg(Color::Red).fg_end(Color::Blue) |
| 41 | + ); |
| 42 | + |
| 43 | + // Progress bar simulation |
| 44 | + let width = 40; |
| 45 | + let progress = 0.7; // 70% complete |
| 46 | + let filled = (width as f32 * progress) as usize; |
| 47 | + let bar: String = "█".repeat(filled) + &"░".repeat(width - filled); |
| 48 | + println!( |
| 49 | + "Progress: [{}] {}%", |
| 50 | + style(&bar) |
| 51 | + .fg(Color::TrueColor(0, 255, 0)) |
| 52 | + .fg_end(Color::TrueColor(0, 128, 255)), |
| 53 | + (progress * 100.0) as u32 |
| 54 | + ); |
| 55 | +} |
0 commit comments