ogham / rust-ansi-term

Rust library for ANSI terminal colours and styles (bold, underline)

Home Page:https://crates.io/crates/ansi_term

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A method to strip ANSI codes

nikomatsakis opened this issue · comments

It'd be nice if there were a way to strip the color code after the fact (basically to uncover the plain text from an ANSIString or ANSIStrings). That way, you can construct colored text, but throw the colors away at the last minute if you find the renderer doesn't support them or what have you.

It's funny, this crate's purpose has gone from "add ANSI codes to a string" to "maintain a vector of coloured text, then add ANSI codes to it at the end". Maybe I shouldn't have emphasised the ANSI part of it so much!

Anyway, this seems like a missing feature I can add. Just to be clear, you're talking about getting str values out of an ANSIString that hasn't been displayed yet, rather than stripping the codes from a String?

I'm not sure actually how important this feature is -- it seems like there is a need for something like NSAttributedString 1 but maybe this library isn't the place to do it.

Just to be clear, you're talking about getting str values out of an ANSIString that hasn't been displayed yet

Yes.

I made it so you can Deref an ANSIString and get a &str out.