Skip to content

I need to parse the corresponding character style from a piece of ansi string #166

Open
@BppleMan

Description

@BppleMan

I get the ansi string from another process and display it in my rich text box, so I need to parse the ansi control codes.
Now I use AnsiCodeIterator to get each element, is there a way to parse it to get what kind of style it is?

fn main() {
    let ansi_str = style("Hello world!").force_styling(true).red().on_blue().bold().to_string();
    println!("{:?}", ansi_str);
    AnsiCodeIterator::new(&ansi_str).for_each(|ansi_code| {
        println!("{:?}", ansi_code.0);
        // how to convert ansi code to style?
        // such as let style = Style::from_ansi_code(ansi_code.0);
        // but this method is not implemented
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions