Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when parsing some color commands #30

Open
Mforcen opened this issue Aug 21, 2024 · 2 comments
Open

Error when parsing some color commands #30

Mforcen opened this issue Aug 21, 2024 · 2 comments

Comments

@Mforcen
Copy link

Mforcen commented Aug 21, 2024

I am trying to colorize the output of some GitLab traces and it has coloring support. This coloring is done through the use of ANSI escape sequences, but I'm not able to convert them directly to html using this package.

The issue lies with the Select Graphic Rendition reset, which is rendered by GitLab with the stream "ESC [0;m". According to Wikipedia those commands do not contain the semicolon, but there are other commands, such as the foreground color set that in fact include the semicolon (such as ESC [38;5;128m).

I suggest to check if the character next to the semicolon is a parameter (which would be numeric) or if it is the terminator, instead of assuming that it is a number on the first place.

I'm willing to do the work, but if possible, it would be nice if this patch would be merged in the code.

Best regards!

@CosmicHorrorDev
Copy link
Collaborator

Here's a pretty minimal reproducer for the error

[package]
name = "repro"
version = "0.1.0"
edition = "2021"

[dependencies]
ansi-to-html = "0.2.1"
fn main() {
    ansi_to_html::convert("\x1b[31mRed\x1b[0;m Plain").unwrap();
}
$ cargo r -q
thread 'main' panicked at src/main.rs:2:56:
called `Result::unwrap()` on an `Err` value: ParseInt(ParseIntError { kind: Empty })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

And the same thing works fine in a terminal

image


I'm willing to do the work, but if possible, it would be nice if this patch would be merged in the code.

I'd be willing to review a PR for it if that's fine with @Aloso

@Mforcen
Copy link
Author

Mforcen commented Aug 22, 2024

Hey, thanks! I forgot to add a minimal reproducible example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants