Gradient

Trait Gradient 

Source
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§

Source

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 gradient
  • end_color - The ending color of the gradient
  • block - Controls multi-line behavior:
    • None or Some(false): Gradient continues across line breaks
    • Some(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);
Source

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 gradient
  • end_color - The ending color of the gradient
  • block - Controls multi-line behavior (same as gradient)
§Examples
use tinterm::{Gradient, Color};

let text = "Gradient background";
let bg_gradient = text.gradient_bg(Color::GREEN, Color::PURPLE, None);

Implementations on Foreign Types§

Source§

impl Gradient for str

Source§

fn gradient( &self, start_color: Color, end_color: Color, block: Option<bool>, ) -> String

Source§

fn gradient_bg( &self, start_color: Color, end_color: Color, block: Option<bool>, ) -> String

Implementors§