console-rs / console-rs/console

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

Open
#166 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.2k
Forks
144
Avg merge
8h 24m
Merged PRs (30d)
4

Description

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
    });
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided AnsiCodeIterator example and trace how ANSI control-code elements are represented. Define what style information must be recovered from the parsed codes and what the resulting API should return; done means the red, blue-background, and bold attributes in the example can be represented reliably.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.