Module gradient

Module gradient 

Source
Expand description

Gradient rendering utilities for progress bars and color transitions.

§Gradient Utilities

This module provides high-performance utilities for rendering gradient-colored text in terminal applications, specifically designed for progress bars and other UI elements in the Bubble Tea TUI framework.

The module focuses on performance by manually generating ANSI escape sequences rather than using higher-level styling libraries, making it suitable for real-time rendering of animated progress bars and other dynamic UI elements.

§Features

  • Fast RGB color interpolation for smooth gradients
  • Optimized ANSI escape sequence generation
  • Buffer reuse support for high-frequency rendering
  • Charm Bubble Tea compatible default gradient colors

§Example

use bubbletea_rs::gradient::{gradient_filled_segment, charm_default_gradient, lerp_rgb};

// Create a gradient progress bar
let progress_bar = gradient_filled_segment(20, '█');
println!("{}", progress_bar);

// Get the default Charm gradient colors
let (start, end) = charm_default_gradient();
println!("Start: RGB({}, {}, {})", start.0, start.1, start.2);

// Interpolate between colors
let mid_color = lerp_rgb(start, end, 0.5);
println!("Mid-point: RGB({}, {}, {})", mid_color.0, mid_color.1, mid_color.2);

Functions§

charm_default_gradient
Returns the default gradient color endpoints used by Charm’s Bubble Tea framework.
gradient_filled_segment
Creates a gradient-colored text segment for terminal display.
gradient_filled_segment_with_buffer
Creates a gradient-colored text segment using a reusable buffer for optimal performance.
lerp_rgb
Performs linear interpolation between two RGB colors.