pub trait Gradient {
// Required methods
fn gradient(
&self,
start_color: Color,
end_color: Color,
block: Option<bool>,
) -> String;
fn gradient_bg(
&self,
start_color: Color,
end_color: Color,
block: Option<bool>,
) -> String;
}Expand description
Trait for applying color gradients to text.
This trait provides methods to create smooth color transitions across text, both for foreground and background colors. Gradients can be applied to single lines or multi-line text with different behaviors.
§Examples
use tinterm::{Gradient, Color};
// Simple gradient from red to blue
let gradient_text = "Hello World".gradient(Color::RED, Color::BLUE, None);
// Background gradient
let bg_gradient = "Background".gradient_bg(Color::GREEN, Color::YELLOW, None);
// Multi-line gradient with block mode
let multiline = "Line 1\nLine 2".gradient(Color::CYAN, Color::MAGENTA, Some(true));Required Methods§
Sourcefn gradient(
&self,
start_color: Color,
end_color: Color,
block: Option<bool>,
) -> String
fn gradient( &self, start_color: Color, end_color: Color, block: Option<bool>, ) -> String
Creates a foreground color gradient across the text.
§Arguments
start_color- The starting color of the gradientend_color- The ending color of the gradientblock- Controls multi-line behavior:NoneorSome(false): Gradient continues across line breaksSome(true): Each line gets its own complete gradient
§Examples
use tinterm::{Gradient, Color};
let text = "Rainbow text";
let gradient = text.gradient(Color::RED, Color::BLUE, None);Sourcefn gradient_bg(
&self,
start_color: Color,
end_color: Color,
block: Option<bool>,
) -> String
fn gradient_bg( &self, start_color: Color, end_color: Color, block: Option<bool>, ) -> String
Creates a background color gradient across the text.
§Arguments
start_color- The starting color of the gradientend_color- The ending color of the gradientblock- Controls multi-line behavior (same asgradient)
§Examples
use tinterm::{Gradient, Color};
let text = "Gradient background";
let bg_gradient = text.gradient_bg(Color::GREEN, Color::PURPLE, None);