pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
}Expand description
Represents an RGB color with red, green, and blue components.
Each component is a value between 0 and 255, where:
- 0 represents no intensity
- 255 represents full intensity
§Examples
use tinterm::Color;
// Create a red color
let red = Color::new(255, 0, 0);
// Use predefined colors
let blue = Color::BLUE;
// Create from hex string
let orange = Color::from_hex("#FF8000").unwrap();Fields§
§r: u8Red component (0-255)
g: u8Green component (0-255)
b: u8Blue component (0-255)
Implementations§
Source§impl Color
impl Color
Sourcepub fn new(r: u8, g: u8, b: u8) -> Self
pub fn new(r: u8, g: u8, b: u8) -> Self
Creates a new Color with the specified RGB values.
§Arguments
r- Red component (0-255)g- Green component (0-255)b- Blue component (0-255)
§Examples
use tinterm::Color;
let purple = Color::new(128, 0, 128);Examples found in repository?
examples/art_and_logos.rs (line 211)
190fn display_fire_effect() {
191 println!("\nFire Effect:");
192
193 let flames = vec![
194 " ░░░",
195 " ░░▒▒░",
196 " ░▒▒▓▓▒░",
197 " ░▒▓▓██▓▒░",
198 " ░▒▓██████▓▒░",
199 " ░▒▓████████▓▒░",
200 " ░▒▓▓██████████▓▒░",
201 " ░▒▓▓████████████▓▓▒░",
202 " ░▒▓▓██████████████▓▓▒░",
203 " ░▒▓▓████████████████▓▓▒░░",
204 ];
205
206 for (i, flame) in flames.iter().enumerate() {
207 let intensity = (flames.len() - i) as f32 / flames.len() as f32;
208 let red_component = (255.0 * intensity) as u8;
209 let yellow_component = (255.0 * intensity * 0.8) as u8;
210
211 let fire_color = Color::new(red_component, yellow_component, 0);
212 println!(" {}", flame.color(fire_color));
213 }
214}More examples
examples/comprehensive_demo.rs (line 11)
3fn main() {
4 println!("🎨 Tinterm Comprehensive Demo 🎨\n");
5
6 // Section 1: Basic Colors
7 println!("=== 1. BASIC COLORS ===");
8 println!("{}", "Red Text".color(Color::RED));
9 println!("{}", "Green Background".bg(Color::GREEN));
10 println!("{}", "Blue on Yellow".fg(Color::BLUE).bg(Color::YELLOW));
11 println!("{}", "Custom RGB Color".color(Color::new(255, 165, 0))); // Orange
12 println!("{}", "Hex Color".color(Color::from_hex("#FF69B4").unwrap())); // Hot Pink
13 println!();
14
15 // Section 2: Text Styling
16 println!("=== 2. TEXT STYLING ===");
17 println!("{}", "Bold Text".bold());
18 println!("{}", "Italic Text".italic());
19 println!("{}", "Underlined Text".underline());
20 println!("{}", "Strikethrough Text".strikethrough());
21 println!("{}", "Dim Text".dim());
22 println!("{}", "Bright Text".bright());
23 println!("{}", "Reversed Text".reverse());
24 println!("{}", "Blinking Text".blink());
25 println!();
26
27 // Section 3: Method Chaining
28 println!("=== 3. METHOD CHAINING ===");
29 println!(
30 "{}",
31 "Bold Red on Blue".bold().color(Color::RED).bg(Color::BLUE)
32 );
33 println!(
34 "{}",
35 "Italic Underlined Green"
36 .italic()
37 .underline()
38 .color(Color::GREEN)
39 );
40 println!(
41 "{}",
42 "Bright Magenta with Cyan BG"
43 .bright()
44 .color(Color::MAGENTA)
45 .bg(Color::CYAN)
46 );
47 println!();
48
49 // Section 4: Gradients
50 println!("=== 4. GRADIENTS ===");
51 println!("Foreground Gradients:");
52 println!(
53 "{}",
54 "Red to Blue Gradient".gradient(Color::RED, Color::BLUE, None)
55 );
56 println!(
57 "{}",
58 "Green to Purple Gradient".gradient(Color::GREEN, Color::PURPLE, None)
59 );
60 println!(
61 "{}",
62 "Sunset Colors".gradient(Color::ORANGE, Color::DEEP_PINK, None)
63 );
64
65 println!("\nBackground Gradients:");
66 println!(
67 "{}",
68 "Ocean Waves".gradient_bg(Color::DEEP_SKY_BLUE, Color::TEAL, None)
69 );
70 println!(
71 "{}",
72 "Forest Floor".gradient_bg(Color::DARK_GREEN, Color::BROWN, None)
73 );
74
75 println!("\nMultiline Gradients:");
76 let multiline = "Line One\nLine Two\nLine Three";
77 println!("Block mode (each line separate):");
78 println!(
79 "{}",
80 multiline.gradient(Color::RED, Color::BLUE, Some(true))
81 );
82 println!("Continuous mode (across lines):");
83 println!(
84 "{}",
85 multiline.gradient(Color::CYAN, Color::MAGENTA, Some(false))
86 );
87 println!();
88
89 // Section 5: Shimmer Effects
90 println!("=== 5. SHIMMER EFFECTS ===");
91 println!("Static Shimmer Renders:");
92 println!(
93 "{}",
94 "✨ Golden Shimmer ✨"
95 .shimmer(Color::GOLD, None)
96 .static_render()
97 );
98 println!(
99 "{}",
100 "💎 Diamond Shine 💎".shine(Color::WHITE).static_render()
101 );
102 println!(
103 "{}",
104 "🌟 Stellar Glow 🌟"
105 .glow(Color::YELLOW, 200)
106 .static_render()
107 );
108 println!(
109 "{}",
110 "🌈 Rainbow Gradient 🌈"
111 .shimmer_gradient(Color::RED, Color::VIOLET, None)
112 .static_render()
113 );
114 println!();
115
116 // Section 6: Predefined Colors Showcase
117 println!("=== 6. PREDEFINED COLORS SHOWCASE ===");
118 let colors = vec![
119 ("Fire", Color::RED),
120 ("Ocean", Color::BLUE),
121 ("Forest", Color::GREEN),
122 ("Sun", Color::YELLOW),
123 ("Lavender", Color::LAVENDER),
124 ("Coral", Color::CORAL),
125 ("Gold", Color::GOLD),
126 ("Silver", Color::SILVER),
127 ("Rose", Color::HOT_PINK),
128 ("Emerald", Color::LIME_GREEN),
129 ];
130
131 for (name, color) in colors {
132 println!("{}", format!("● {}", name).color(color));
133 }
134 println!();
135
136 // Section 7: Creative Combinations
137 println!("=== 7. CREATIVE COMBINATIONS ===");
138
139 // Logo-style text
140 println!(
141 "{}",
142 "T".color(Color::RED).to_string()
143 + &"I".color(Color::ORANGE).to_string()
144 + &"N".color(Color::YELLOW).to_string()
145 + &"T".color(Color::GREEN).to_string()
146 + &"E".color(Color::BLUE).to_string()
147 + &"R".color(Color::INDIGO).to_string()
148 + &"M".color(Color::VIOLET)
149 );
150
151 // Progress bar simulation
152 let _progress_full = "████████████████████";
153 let _progress_empty = "░░░░░░░░░░░░░░░░░░░░";
154 println!(
155 "Progress: [{}{}] 75%",
156 "███████████████".bg(Color::GREEN),
157 "░░░░░".color(Color::DARK_GRAY)
158 );
159
160 // Status indicators
161 println!("Status: {} Ready", "●".color(Color::GREEN));
162 println!("Status: {} Warning", "●".color(Color::YELLOW));
163 println!("Status: {} Error", "●".color(Color::RED));
164
165 // Syntax highlighting simulation
166 println!("\nSyntax Highlighting Example:");
167 println!(
168 "{} {} {} {}{}{}",
169 "fn".color(Color::PURPLE),
170 "main".color(Color::BLUE),
171 "()".color(Color::YELLOW),
172 "{".color(Color::WHITE),
173 "\n println!".color(Color::CYAN),
174 "();".color(Color::WHITE)
175 );
176 println!("{}", "}".color(Color::WHITE));
177 println!();
178
179 // Section 8: Performance Test
180 println!("=== 8. PERFORMANCE TEST ===");
181 let start = std::time::Instant::now();
182 for i in 0..1000 {
183 let _colored = format!("Line {}", i).color(Color::BLUE);
184 }
185 let duration = start.elapsed();
186 println!("Rendered 1000 colored strings in: {:?}", duration);
187
188 // Final showcase
189 println!(
190 "\n{}",
191 "🎉 Tinterm Demo Complete! 🎉".gradient(Color::RED, Color::BLUE, None)
192 );
193 println!(
194 "{}",
195 "Thank you for using Tinterm!"
196 .shimmer(Color::GOLD, None)
197 .static_render()
198 );
199}Sourcepub fn rgb(r: u8, g: u8, b: u8) -> Self
pub fn rgb(r: u8, g: u8, b: u8) -> Self
Creates a new Color with the specified RGB values.
This is an alias for Color::new.
§Examples
use tinterm::Color;
let cyan = Color::rgb(0, 255, 255);Sourcepub fn from_hex(hex: &str) -> Result<Self, &'static str>
pub fn from_hex(hex: &str) -> Result<Self, &'static str>
Creates a new Color from a hexadecimal color string.
Supports both 6-digit (e.g., “#FF0000” or “FF0000”) and 3-digit (e.g., “#F00” or “F00”) formats. The ‘#’ prefix is optional.
§Arguments
hex- A hex color string
§Returns
Ok(Color)- If the hex string is validErr(&str)- If the hex string is invalid
§Examples
use tinterm::Color;
let red = Color::from_hex("#FF0000").unwrap();
let green = Color::from_hex("00FF00").unwrap();
let blue = Color::from_hex("#00F").unwrap();Examples found in repository?
examples/comprehensive_demo.rs (line 12)
3fn main() {
4 println!("🎨 Tinterm Comprehensive Demo 🎨\n");
5
6 // Section 1: Basic Colors
7 println!("=== 1. BASIC COLORS ===");
8 println!("{}", "Red Text".color(Color::RED));
9 println!("{}", "Green Background".bg(Color::GREEN));
10 println!("{}", "Blue on Yellow".fg(Color::BLUE).bg(Color::YELLOW));
11 println!("{}", "Custom RGB Color".color(Color::new(255, 165, 0))); // Orange
12 println!("{}", "Hex Color".color(Color::from_hex("#FF69B4").unwrap())); // Hot Pink
13 println!();
14
15 // Section 2: Text Styling
16 println!("=== 2. TEXT STYLING ===");
17 println!("{}", "Bold Text".bold());
18 println!("{}", "Italic Text".italic());
19 println!("{}", "Underlined Text".underline());
20 println!("{}", "Strikethrough Text".strikethrough());
21 println!("{}", "Dim Text".dim());
22 println!("{}", "Bright Text".bright());
23 println!("{}", "Reversed Text".reverse());
24 println!("{}", "Blinking Text".blink());
25 println!();
26
27 // Section 3: Method Chaining
28 println!("=== 3. METHOD CHAINING ===");
29 println!(
30 "{}",
31 "Bold Red on Blue".bold().color(Color::RED).bg(Color::BLUE)
32 );
33 println!(
34 "{}",
35 "Italic Underlined Green"
36 .italic()
37 .underline()
38 .color(Color::GREEN)
39 );
40 println!(
41 "{}",
42 "Bright Magenta with Cyan BG"
43 .bright()
44 .color(Color::MAGENTA)
45 .bg(Color::CYAN)
46 );
47 println!();
48
49 // Section 4: Gradients
50 println!("=== 4. GRADIENTS ===");
51 println!("Foreground Gradients:");
52 println!(
53 "{}",
54 "Red to Blue Gradient".gradient(Color::RED, Color::BLUE, None)
55 );
56 println!(
57 "{}",
58 "Green to Purple Gradient".gradient(Color::GREEN, Color::PURPLE, None)
59 );
60 println!(
61 "{}",
62 "Sunset Colors".gradient(Color::ORANGE, Color::DEEP_PINK, None)
63 );
64
65 println!("\nBackground Gradients:");
66 println!(
67 "{}",
68 "Ocean Waves".gradient_bg(Color::DEEP_SKY_BLUE, Color::TEAL, None)
69 );
70 println!(
71 "{}",
72 "Forest Floor".gradient_bg(Color::DARK_GREEN, Color::BROWN, None)
73 );
74
75 println!("\nMultiline Gradients:");
76 let multiline = "Line One\nLine Two\nLine Three";
77 println!("Block mode (each line separate):");
78 println!(
79 "{}",
80 multiline.gradient(Color::RED, Color::BLUE, Some(true))
81 );
82 println!("Continuous mode (across lines):");
83 println!(
84 "{}",
85 multiline.gradient(Color::CYAN, Color::MAGENTA, Some(false))
86 );
87 println!();
88
89 // Section 5: Shimmer Effects
90 println!("=== 5. SHIMMER EFFECTS ===");
91 println!("Static Shimmer Renders:");
92 println!(
93 "{}",
94 "✨ Golden Shimmer ✨"
95 .shimmer(Color::GOLD, None)
96 .static_render()
97 );
98 println!(
99 "{}",
100 "💎 Diamond Shine 💎".shine(Color::WHITE).static_render()
101 );
102 println!(
103 "{}",
104 "🌟 Stellar Glow 🌟"
105 .glow(Color::YELLOW, 200)
106 .static_render()
107 );
108 println!(
109 "{}",
110 "🌈 Rainbow Gradient 🌈"
111 .shimmer_gradient(Color::RED, Color::VIOLET, None)
112 .static_render()
113 );
114 println!();
115
116 // Section 6: Predefined Colors Showcase
117 println!("=== 6. PREDEFINED COLORS SHOWCASE ===");
118 let colors = vec![
119 ("Fire", Color::RED),
120 ("Ocean", Color::BLUE),
121 ("Forest", Color::GREEN),
122 ("Sun", Color::YELLOW),
123 ("Lavender", Color::LAVENDER),
124 ("Coral", Color::CORAL),
125 ("Gold", Color::GOLD),
126 ("Silver", Color::SILVER),
127 ("Rose", Color::HOT_PINK),
128 ("Emerald", Color::LIME_GREEN),
129 ];
130
131 for (name, color) in colors {
132 println!("{}", format!("● {}", name).color(color));
133 }
134 println!();
135
136 // Section 7: Creative Combinations
137 println!("=== 7. CREATIVE COMBINATIONS ===");
138
139 // Logo-style text
140 println!(
141 "{}",
142 "T".color(Color::RED).to_string()
143 + &"I".color(Color::ORANGE).to_string()
144 + &"N".color(Color::YELLOW).to_string()
145 + &"T".color(Color::GREEN).to_string()
146 + &"E".color(Color::BLUE).to_string()
147 + &"R".color(Color::INDIGO).to_string()
148 + &"M".color(Color::VIOLET)
149 );
150
151 // Progress bar simulation
152 let _progress_full = "████████████████████";
153 let _progress_empty = "░░░░░░░░░░░░░░░░░░░░";
154 println!(
155 "Progress: [{}{}] 75%",
156 "███████████████".bg(Color::GREEN),
157 "░░░░░".color(Color::DARK_GRAY)
158 );
159
160 // Status indicators
161 println!("Status: {} Ready", "●".color(Color::GREEN));
162 println!("Status: {} Warning", "●".color(Color::YELLOW));
163 println!("Status: {} Error", "●".color(Color::RED));
164
165 // Syntax highlighting simulation
166 println!("\nSyntax Highlighting Example:");
167 println!(
168 "{} {} {} {}{}{}",
169 "fn".color(Color::PURPLE),
170 "main".color(Color::BLUE),
171 "()".color(Color::YELLOW),
172 "{".color(Color::WHITE),
173 "\n println!".color(Color::CYAN),
174 "();".color(Color::WHITE)
175 );
176 println!("{}", "}".color(Color::WHITE));
177 println!();
178
179 // Section 8: Performance Test
180 println!("=== 8. PERFORMANCE TEST ===");
181 let start = std::time::Instant::now();
182 for i in 0..1000 {
183 let _colored = format!("Line {}", i).color(Color::BLUE);
184 }
185 let duration = start.elapsed();
186 println!("Rendered 1000 colored strings in: {:?}", duration);
187
188 // Final showcase
189 println!(
190 "\n{}",
191 "🎉 Tinterm Demo Complete! 🎉".gradient(Color::RED, Color::BLUE, None)
192 );
193 println!(
194 "{}",
195 "Thank you for using Tinterm!"
196 .shimmer(Color::GOLD, None)
197 .static_render()
198 );
199}Source§impl Color
Predefined colors for convenience
impl Color
Predefined colors for convenience
pub const RED: Color
pub const GREEN: Color
pub const BLUE: Color
pub const YELLOW: Color
pub const MAGENTA: Color
pub const CYAN: Color
pub const WHITE: Color
pub const BLACK: Color
pub const PINK: Color
pub const LIGHT_PINK: Color
pub const HOT_PINK: Color
pub const DEEP_PINK: Color
pub const PALE_VIOLET_RED: Color
pub const MEDIUM_VIOLET_RED: Color
pub const LIGHT_SALMON: Color
pub const SALMON: Color
pub const DARK_SALMON: Color
pub const LIGHT_CORAL: Color
pub const INDIAN_RED: Color
pub const CRIMSON: Color
pub const FIRE_BRICK: Color
pub const DARK_RED: Color
pub const ORANGE_RED: Color
pub const TOMATO: Color
pub const CORAL: Color
pub const DARK_ORANGE: Color
pub const ORANGE: Color
pub const LIGHT_YELLOW: Color
pub const LEMON_CHIFFON: Color
pub const LIGHT_GOLDENROD_YELLOW: Color
pub const PAPAYA_WHIP: Color
pub const MOCCASIN: Color
pub const PEACH_PUFF: Color
pub const PALE_GOLDENROD: Color
pub const KHAKI: Color
pub const DARK_KHAKI: Color
pub const GOLD: Color
pub const CORNSILK: Color
pub const BLANCHED_ALMOND: Color
pub const BISQUE: Color
pub const NAVAJO_WHITE: Color
pub const WHEAT: Color
pub const BURLYWOOD: Color
pub const TAN: Color
pub const ROSY_BROWN: Color
pub const SANDY_BROWN: Color
pub const GOLDENROD: Color
pub const DARK_GOLDENROD: Color
pub const PERU: Color
pub const CHOCOLATE: Color
pub const SADDLE_BROWN: Color
pub const SIENNA: Color
pub const BROWN: Color
pub const MAROON: Color
pub const GREEN_YELLOW: Color
pub const CHARTREUSE: Color
pub const LAWN_GREEN: Color
pub const LIME: Color
pub const LIME_GREEN: Color
pub const PALE_GREEN: Color
pub const LIGHT_GREEN: Color
pub const MEDIUM_SPRING_GREEN: Color
pub const SPRING_GREEN: Color
pub const MEDIUM_SEA_GREEN: Color
pub const SEA_GREEN: Color
pub const FOREST_GREEN: Color
pub const DARK_GREEN: Color
pub const YELLOW_GREEN: Color
pub const OLIVE_DRAB: Color
pub const OLIVE: Color
pub const DARK_OLIVE_GREEN: Color
pub const MEDIUM_AQUAMARINE: Color
pub const DARK_SEA_GREEN: Color
pub const LIGHT_SEA_GREEN: Color
pub const DARK_CYAN: Color
pub const TEAL: Color
pub const AQUA: Color
pub const LIGHT_CYAN: Color
pub const PALE_TURQUOISE: Color
pub const AQUAMARINE: Color
pub const TURQUOISE: Color
pub const MEDIUM_TURQUOISE: Color
pub const DARK_TURQUOISE: Color
pub const CADET_BLUE: Color
pub const STEEL_BLUE: Color
pub const LIGHT_STEEL_BLUE: Color
pub const POWDER_BLUE: Color
pub const LIGHT_BLUE: Color
pub const SKY_BLUE: Color
pub const LIGHT_SKY_BLUE: Color
pub const DEEP_SKY_BLUE: Color
pub const DODGER_BLUE: Color
pub const CORNFLOWER_BLUE: Color
pub const MEDIUM_SLATE_BLUE: Color
pub const ROYAL_BLUE: Color
pub const MEDIUM_BLUE: Color
pub const DARK_BLUE: Color
pub const NAVY: Color
pub const MIDNIGHT_BLUE: Color
pub const LAVENDER: Color
pub const THISTLE: Color
pub const PLUM: Color
pub const VIOLET: Color
pub const ORCHID: Color
pub const FUCHSIA: Color
pub const MEDIUM_ORCHID: Color
pub const MEDIUM_PURPLE: Color
pub const BLUE_VIOLET: Color
pub const DARK_VIOLET: Color
pub const DARK_ORCHID: Color
pub const DARK_MAGENTA: Color
pub const PURPLE: Color
pub const INDIGO: Color
pub const SLATE_BLUE: Color
pub const DARK_SLATE_BLUE: Color
pub const GAINSBORO: Color
pub const LIGHT_GRAY: Color
pub const SILVER: Color
pub const DARK_GRAY: Color
pub const GRAY: Color
pub const DIM_GRAY: Color
pub const LIGHT_SLATE_GRAY: Color
pub const SLATE_GRAY: Color
pub const DARK_SLATE_GRAY: Color
pub const ALICE_BLUE: Color
pub const GHOST_WHITE: Color
pub const HONEYDEW: Color
pub const IVORY: Color
pub const AZURE: Color
pub const SNOW: Color
pub const FLORAL_WHITE: Color
pub const WHITE_SMOKE: Color
pub const SEASHELL: Color
pub const BEIGE: Color
pub const OLD_LACE: Color
pub const MINT_CREAM: Color
pub const LAVENDER_BLUSH: Color
pub const MISTY_ROSE: Color
Trait Implementations§
impl Copy for Color
impl Eq for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more