dunh

Crates.iodunh
lib.rsdunh
version
sourcesrc
created_at2024-11-02 10:33:15.457128
updated_at2024-12-19 02:19:30.389638
descriptionHighlights code for printing
homepage
repositoryhttps://github.com/yazaldefilimone/dunh
max_upload_size
id1432732
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Yazalde Filimone (yazaldefilimone)

documentation

README

Rust util that highlights an error.

  • code_highlighter lets you highlight errors in your code and show extra lines around the error for better context.

Example

The code below:

let code = "functon is_zero (x) {
  if (x == 0) [
    return true;
  ] else {
    return false;
  }
}";
println!("Error:");
println!("{}", code_highlighter::highlight_error(38, 64, &code));
println!("");

println!("Warning:");
println!("{}", code_highlighter::highlight_warning(38, 64, &code));
println!("");

println!("Custom color:");
println!("{}", code_highlighter::highlight(38, 64, &code, "\x1b[4m\x1b[32m"));
println!("");

let code = "(Foo x) = 7[0 ]\n";
println!("Error:");
println!("{}", code_highlighter::highlight_error(16, 17, &code));
println!("");

Will output:

example

Usage

  1. Install using cargo
cargo add code_highlighter

  1. main.rs
use code_highlighter::highlight_error_with_context;

fn main() {
  // set the number of lines of context you want to show
  let context = 2; // Adds two lines above and below the error

  // assuming `range` has the error position and `source.raw` is your code
  let code = highlight_error_with_context(range.start, range.end, &source.raw, context);

  // print the highlighted code
  println!("{}", code);
}
Commit count: 25

cargo fmt