#ansi-colors #color #ansi #string #preserving #cut #cutting

ansi-cut

A library for cutting a string while preserving colors

3 unstable releases

0.2.0 Jan 22, 2022
0.1.1 Sep 9, 2021
0.1.0 Jun 23, 2021

#1426 in Text processing

Download history 23/week @ 2024-03-11 13/week @ 2024-03-18 29/week @ 2024-03-25 66/week @ 2024-04-01 15/week @ 2024-04-08 8/week @ 2024-04-15 21/week @ 2024-04-22 1/week @ 2024-04-29 7/week @ 2024-05-06 9/week @ 2024-05-13 16/week @ 2024-05-20 16/week @ 2024-05-27 28/week @ 2024-06-03 27/week @ 2024-06-10 16/week @ 2024-06-17 23/week @ 2024-06-24

96 downloads per month

MIT license

29KB
690 lines

ansi-cut Build Status codecov Crate docs.rs license

A library for cutting a string while preserving its colors.

Usage

use ansi_cut::AnsiCut;
use owo_colors::{colors::*, OwoColorize};

pub fn main() {
    let colored_text = "When the night has come"
        .fg::<Black>()
        .bg::<White>()
        .to_string();
    let cutted_text = colored_text.cut(5..);

    println!("{}", cutted_text);
}

Chunks

There's a handy function wich splits a string to a set of chunks. It works with chars not bytes so things like emojies and hieroglyph are are handled with no panic.

use owo_colors::{colors::*, OwoColorize};

pub fn main() {
    let colored_text = "When the night has come"
        .fg::<Black>()
        .bg::<White>()
        .to_string();

    let chunks = ansi_cut::chunks(colored_text, 5);
}

Question

Are any other usefull ansi sequense that would be usefull to keep in mind?

Dependencies

~1.5MB
~35K SLoC