pub trait AnsiCut {
    fn cut<R>(&self, range: R) -> String
    where
        R: RangeBounds<usize>
; }
Expand description

AnsiCut a trait to cut a string while keeping information about its color defined as ANSI control sequences.

Required methods

Cut string from the beginning of the range to the end. Preserving its colors.

Range is defined in terms of bytes of the string not containing ANSI control sequences.

Exceeding an upper bound does not panic.

Panics

Panics if a start or end indexes are not on a UTF-8 code point boundary.

Examples
use owo_colors::{OwoColorize, colors::*};
use ansi_cut::AnsiCut;
let colored_text = format!("{} {} {}", "A".fg::<Black>(), "Colored".fg::<Red>(), "Text".fg::<Blue>()).bg::<Yellow>().to_string();
let cut_text = colored_text.cut(5..);
println!("{}", cut_text);

Implementations on Foreign Types

Implementors