colored-rs / cansi Goto Github PK
View Code? Open in Web Editor NEWCatergorise ANSI - ANSI escape code parser and categoriser
Catergorise ANSI - ANSI escape code parser and categoriser
Here is my MRE:
fn main() {
let some_string = "ᆴ";
let categorized_result = categorise_text(&some_string);
let text_without_code = construct_text_no_codes(&categorized_result);
println!("{}", text_without_code);
}
And here is what happens:
C:\Users\rsheink\home\repos\bla>cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target\debug\bla.exe`
thread 'main' panicked at 'byte index 2 is not a char boundary; it is inside 'ᆴ' (bytes 0..3) of `ᆴ`', C:\Users\rsheink\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src
/rust\src\libcore\str\mod.rs:1920:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\bla.exe` (exit code: 101)
C:\Users\rsheink\home\repos\bla>
Can you please check it out?
Please consider the following:
fn some_function() -> CategorisedSlices {
let text_with_codes : String = ....
categorise_text(&text_with_codes)
}
The above produces the following error:
error[E0515]: cannot return value referencing local variable `text_with_codes`
--> src/model/git_commander/git_commander.rs:28:9
|
28 | categorise_text(&text_with_codes)
| ^^^^^^^^^^^^^^^^----------------^
| | |
| | `text_with_codes` is borrowed here
| returns a value referencing data owned by the current function
I am not really sure its a bug in cansi
. If categorise_text
would accept String
instead of &str
, this error would not happen.
Please advise :-) I really need to return CategorisedSlices
from my functions.
What would be the best way to derive the escape code by size of a give CategorizedSlice? Having this information would be extremely useful for tasks like text wrapping.
Malformed escape codes (e.g. just ESC[
) cause a panic. Here is a minimal example:
use cansi::v3::categorise_text;
fn main() {
let x = categorise_text("oops\x1b[\n");
println!("{}", x[0].text);
}
I believe at least from Oxker's perspective it'd make the most sense for cansi to ignore these and remove them from the resultant slice (ignoring them seems to be what most terminal emulators do).
I understand if you are not interested in fixing this, but for context I'm here from this issue: mrjackwills/oxker#17
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.