Giter VIP home page Giter VIP logo

cansi's People

Contributors

kurtlawrence avatar videah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cansi's Issues

Panic occurs with this character `ᆴ`

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?

A `String` in `categorise_text`

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.

Malformed escapes cause panic

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.