simple errors for lang-dev
fix width calculation of escapes
bendn 2023-09-17
parent bfdf46c · commit 77ed162
-rw-r--r--.github/example.pngbin20132 -> 18968 bytes
-rw-r--r--Cargo.toml4
-rw-r--r--src/lib.rs8
3 files changed, 7 insertions, 5 deletions
diff --git a/.github/example.png b/.github/example.png
index 9f574e3..c48594e 100644
--- a/.github/example.png
+++ b/.github/example.png
Binary files differ
diff --git a/Cargo.toml b/Cargo.toml
index b7aa980..bcc8650 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "lerr"
-version = "0.1.3"
+version = "0.1.4"
edition = "2021"
license = "MIT"
readme = "README.md"
@@ -14,6 +14,4 @@ keywords = ["error", "lang-dev", "diagnostics"]
[dependencies]
comat = "0.1.0"
unicode-width = "0.1.10"
-
-[dev-dependencies]
anstream = { version = "0.5.0", default-features = false }
diff --git a/src/lib.rs b/src/lib.rs
index de08629..95f7717 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,6 +7,7 @@
clippy::dbg_macro,
missing_docs
)]
+use anstream::adapter::strip_str;
use comat::{cwrite, cwriteln};
use config::Charset;
use std::{fmt::Write, ops::Range};
@@ -115,7 +116,7 @@ impl<'s> Error<'s> {
#[cfg(test)]
fn monochrome(&self) -> String {
- anstream::adapter::strip_str(&self.to_string()).to_string()
+ strip_str(&self.to_string()).to_string()
}
}
@@ -157,7 +158,10 @@ impl<'s> std::fmt::Display for Error<'s> {
point += 1;
}
// ^^^ [<this part length>]
- let msglen = UnicodeWidthStr::width(candidate.message.as_str());
+ let mut msglen = 0;
+ for chr in strip_str(candidate.message.as_str()) {
+ msglen += UnicodeWidthStr::width(chr);
+ }
found.push((candidate, msglen, point));
} else {
i += 1;