Files
binocle/src/color.rs
T
surv 0f1194aeca
CI / fmt (push) Has been cancelled
CI / clippy (push) Has been cancelled
CI / doc (push) Has been cancelled
CI / test macos-latest (push) Has been cancelled
CI / test windows-latest (push) Has been cancelled
First commit
2026-08-08 18:06:13 +02:00

20 lines
532 B
Rust

use ratatui::{style::Stylize, text::Line};
pub fn colorize<'a>(mut txt: &'a str, width: usize, out: &mut Line<'a>) {
let mut color = false;
if !txt.len().is_multiple_of(width) {
*out += txt[..txt.len() % width].red();
color = !color;
txt = &txt[txt.len() % width..];
}
for _ in 0..txt.len() / width {
if color {
*out += txt[0..width].cyan();
} else {
*out += txt[0..width].red();
}
txt = &txt[width..];
color = !color;
}
}