ansi-cut

Crates.ioansi-cut
lib.rsansi-cut
version0.2.0
sourcesrc
created_at2021-06-23 12:20:50.609991
updated_at2022-01-22 20:23:19.130354
descriptionA library for cutting a string while preserving colors.
homepagehttps://github.com/zhiburt/ansi-cut
repositoryhttps://github.com/zhiburt/ansi-cut
max_upload_size
id413900
size36,547
Maxim Zhiburt (zhiburt)

documentation

https://docs.rs/ansi_cut

README

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?

Commit count: 29

cargo fmt