mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-27 13:01:29 +00:00
fix color intensity (#23)
* fix color intensity * update test expected strings * bump version for new release
This commit is contained in:
parent
5b6507d455
commit
3384c06584
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "color-eyre"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
authors = ["Jane Lusby <jlusby@yaah.dev>"]
|
||||
edition = "2018"
|
||||
license = "MIT OR Apache-2.0"
|
||||
@ -22,7 +22,7 @@ color-backtrace = "0.4.0"
|
||||
backtrace = "0.3.48"
|
||||
indenter = "0.3.0"
|
||||
ansi_term = "0.12.1"
|
||||
color-spantrace = { version = "0.1.1", optional = true }
|
||||
color-spantrace = { version = "0.1.2", optional = true }
|
||||
once_cell = "1.4.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
36
src/lib.rs
36
src/lib.rs
@ -202,7 +202,7 @@
|
||||
//! [`examples/custom_filter.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/custom_filter.rs
|
||||
//! [`examples/custom_section.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/custom_section.rs
|
||||
//! [`examples/multiple_errors.rs`]: https://github.com/yaahc/color-eyre/blob/master/examples/multiple_errors.rs
|
||||
#![doc(html_root_url = "https://docs.rs/color-eyre/0.3.2")]
|
||||
#![doc(html_root_url = "https://docs.rs/color-eyre/0.3.3")]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
@ -420,7 +420,7 @@ impl EyreHandler for Handler {
|
||||
buf.clear();
|
||||
write!(&mut buf, "{}", error).unwrap();
|
||||
writeln!(f)?;
|
||||
write!(indented(f).ind(n), "{}", Red.paint(&buf))?;
|
||||
write!(indented(f).ind(n), "{}", Red.make_intense().paint(&buf))?;
|
||||
}
|
||||
|
||||
let separated = &mut HeaderWriter {
|
||||
@ -640,3 +640,35 @@ pub type Report = eyre::Report<Handler>;
|
||||
/// }
|
||||
/// ```
|
||||
pub type Result<T, E = Report> = core::result::Result<T, E>;
|
||||
|
||||
// TODO: remove when / if ansi_term merges these changes upstream
|
||||
trait ColorExt {
|
||||
fn make_intense(self) -> Self;
|
||||
}
|
||||
|
||||
impl ColorExt for ansi_term::Color {
|
||||
fn make_intense(self) -> Self {
|
||||
use ansi_term::Color::*;
|
||||
|
||||
match self {
|
||||
Black => Fixed(8),
|
||||
Red => Fixed(9),
|
||||
Green => Fixed(10),
|
||||
Yellow => Fixed(11),
|
||||
Blue => Fixed(12),
|
||||
Purple => Fixed(13),
|
||||
Cyan => Fixed(14),
|
||||
White => Fixed(15),
|
||||
Fixed(color) if color < 8 => Fixed(color + 8),
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ColorExt for ansi_term::Style {
|
||||
fn make_intense(mut self) -> Self {
|
||||
if let Some(color) = self.foreground {
|
||||
self.foreground = Some(color.make_intense());
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
//! Provides an extension trait for attaching `Section`s to error reports.
|
||||
//! Provides an extension trait for attaching `Section` to error reports.
|
||||
use crate::ColorExt;
|
||||
use crate::{Report, Result};
|
||||
use ansi_term::Color::*;
|
||||
use indenter::indented;
|
||||
@ -351,23 +352,30 @@ pub(crate) enum HelpInfo {
|
||||
impl Display for HelpInfo {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
HelpInfo::Note(n) => write!(f, "{}: {}", Cyan.paint("Note"), n),
|
||||
HelpInfo::Warning(w) => write!(f, "{}: {}", Yellow.paint("Warning"), w),
|
||||
HelpInfo::Suggestion(s) => write!(f, "{}: {}", Cyan.paint("Suggestion"), s),
|
||||
HelpInfo::Custom(c) => write!(f, "{}", c),
|
||||
HelpInfo::Error(e) => {
|
||||
HelpInfo::Note(note) => write!(f, "{}: {}", Cyan.make_intense().paint("Note"), note),
|
||||
HelpInfo::Warning(warning) => {
|
||||
write!(f, "{}: {}", Yellow.make_intense().paint("Warning"), warning)
|
||||
}
|
||||
HelpInfo::Suggestion(suggestion) => write!(
|
||||
f,
|
||||
"{}: {}",
|
||||
Cyan.make_intense().paint("Suggestion"),
|
||||
suggestion
|
||||
),
|
||||
HelpInfo::Custom(section) => write!(f, "{}", section),
|
||||
HelpInfo::Error(error) => {
|
||||
// a lot here
|
||||
let errors = std::iter::successors(
|
||||
Some(e.as_ref() as &(dyn std::error::Error + 'static)),
|
||||
Some(error.as_ref() as &(dyn std::error::Error + 'static)),
|
||||
|e| e.source(),
|
||||
);
|
||||
|
||||
write!(f, "Error:")?;
|
||||
let mut buf = String::new();
|
||||
for (n, e) in errors.enumerate() {
|
||||
for (n, error) in errors.enumerate() {
|
||||
writeln!(f)?;
|
||||
buf.clear();
|
||||
write!(&mut buf, "{}", e).unwrap();
|
||||
write!(&mut buf, "{}", error).unwrap();
|
||||
write!(indented(f).ind(n), "{}", Red.paint(&buf))?;
|
||||
}
|
||||
|
||||
|
@ -53,22 +53,7 @@ fn read_config() -> Result<(), Report> {
|
||||
|
||||
// Define at the bottom to prevent it from changing line numbers
|
||||
#[cfg(feature = "capture-spantrace")]
|
||||
static EXPECTED: &str = "Error:
|
||||
0: \u{1b}[31mUnable to read config\u{1b}[0m
|
||||
1: \u{1b}[31mNo such file or directory (os error 2)\u{1b}[0m
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
0: \u{1b}[31mminimal\u{1b}[0m\u{1b}[31m::\u{1b}[0m\u{1b}[31mread_file\u{1b}[0m with \u{1b}[36mpath=\"fake_file\"\u{1b}[0m
|
||||
at tests/minimal.rs:41
|
||||
1: \u{1b}[31mminimal\u{1b}[0m\u{1b}[31m::\u{1b}[0m\u{1b}[31mread_config\u{1b}[0m
|
||||
at tests/minimal.rs:47
|
||||
|
||||
\u{1b}[36mSuggestion\u{1b}[0m: try using a file that exists next time";
|
||||
static EXPECTED: &str = "Error: \n 0: \u{1b}[38;5;9mUnable to read config\u{1b}[0m\n 1: \u{1b}[38;5;9mNo such file or directory (os error 2)\u{1b}[0m\n\n ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n \n 0: \u{1b}[38;5;9mminimal\u{1b}[0m\u{1b}[38;5;9m::\u{1b}[0m\u{1b}[38;5;9mread_file\u{1b}[0m with \u{1b}[38;5;14mpath=\"fake_file\"\u{1b}[0m\n at tests/minimal.rs:41\n 1: \u{1b}[38;5;9mminimal\u{1b}[0m\u{1b}[38;5;9m::\u{1b}[0m\u{1b}[38;5;9mread_config\u{1b}[0m\n at tests/minimal.rs:47\n\n\u{1b}[38;5;14mSuggestion\u{1b}[0m: try using a file that exists next time";
|
||||
|
||||
#[cfg(not(feature = "capture-spantrace"))]
|
||||
static EXPECTED: &str = "Error:
|
||||
0: \u{1b}[31mUnable to read config\u{1b}[0m
|
||||
1: \u{1b}[31mNo such file or directory (os error 2)\u{1b}[0m
|
||||
|
||||
\u{1b}[36mSuggestion\u{1b}[0m: try using a file that exists next time";
|
||||
static EXPECTED: &str = "Error: \n 0: \u{1b}[38;5;9mUnable to read config\u{1b}[0m\n 1: \u{1b}[38;5;9mNo such file or directory (os error 2)\u{1b}[0m\n\n\u{1b}[38;5;14mSuggestion\u{1b}[0m: try using a file that exists next time";
|
||||
|
Loading…
x
Reference in New Issue
Block a user