Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom styles #69

Merged
merged 30 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
378abda
Add color scheme backwards compatibility test
Sep 30, 2020
1468f5d
Rewrote test case for color schemes
Oct 2, 2020
9a51449
implementation
Oct 10, 2020
0370927
Add missing test data
Oct 10, 2020
95f38de
merge main into styles PR
yaahc Oct 12, 2020
5b5d021
Update src/config.rs
d4h0 Oct 19, 2020
1463939
Update src/config.rs
d4h0 Oct 19, 2020
62b00f6
Update src/config.rs
d4h0 Oct 19, 2020
51c2a95
Implement suggestions
Oct 19, 2020
148792a
bump versions and update control copy of test output
yaahc Dec 2, 2020
2c9b25b
Merge branch 'master' into pr/d4h0/69
yaahc Dec 2, 2020
45ead2d
move THEME setting into core method
yaahc Dec 2, 2020
36d99d1
update theme install and propagation to avoid a once-cell
yaahc Dec 2, 2020
9ddfc09
disable spantrace theme-ing with feature
yaahc Dec 2, 2020
a89e76e
fix panic theme test to include a spantrace in the panic itself
yaahc Dec 2, 2020
b28ace6
fix inconsistent theme propagation
yaahc Dec 2, 2020
cf22ae9
disable panic test for different feature configs
yaahc Dec 2, 2020
98e3436
cleanup logs
yaahc Dec 2, 2020
b5ee9ba
Merge branch 'master' into pr/d4h0/69
yaahc Dec 2, 2020
3a1e076
try copying control from raw github test logs
yaahc Dec 2, 2020
f48feeb
add rust-src for test consistency
yaahc Dec 2, 2020
39c34ae
update test outputs
yaahc Dec 2, 2020
edf444e
just dont bother testing source resolution
yaahc Dec 2, 2020
ebbccce
format unknown files consistently with known ones
yaahc Dec 2, 2020
7b70bc2
test format for multiple feature combinations
yaahc Dec 2, 2020
5a14a8a
store data for alternate theme configurations
yaahc Dec 2, 2020
2eb720c
fix dependency coloration when missing hash suffix
yaahc Dec 2, 2020
0fb566b
update changelog
yaahc Dec 2, 2020
227eb5c
depend on as of yet unreleased owo-colors version
yaahc Dec 2, 2020
ec9e164
(cargo-release) version 0.5.10
yaahc Dec 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ eyre = "0.6.1"
tracing-error = { version = "0.1.2", optional = true }
backtrace = { version = "0.3.48", features = ["gimli-symbolize"] }
indenter = "0.3.0"
owo-colors = "1.0.3"
color-spantrace = { version = "0.1.4", optional = true }
owo-colors = "1.2.0"
color-spantrace = { version = "0.1.5", optional = true }
once_cell = "1.4.0"
url = { version = "2.1.1", optional = true }

Expand All @@ -32,6 +32,7 @@ tracing-subscriber = "0.2.5"
tracing = "0.1.13"
pretty_assertions = "0.6.1"
thiserror = "1.0.19"
ansi-parser = "0.6.5" # used for testing color schemes

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.15"
Expand Down Expand Up @@ -75,4 +76,4 @@ exactly=1
file="CHANGELOG.md"
search="<!-- next-url -->"
replace="<!-- next-url -->\n[Unreleased]: https://github.com/yaahc/{{crate_name}}/compare/{{tag_name}}...HEAD"
exactly=1
exactly=1
59 changes: 59 additions & 0 deletions examples/theme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use color_eyre::{config::Theme, eyre::Report, owo_colors::style, Section};

/// To experiment with theme values, edit `theme()` below and execute `cargo run --example theme`
fn theme() -> Theme {
Theme::dark()
// ^ use `new` to derive from a blank theme, or `light` to derive from a light theme.
// Now configure your theme (see the docs for all options):
.line_number(style().blue())
.help_info_suggestion(style().red())
}

#[derive(Debug, thiserror::Error)]
#[error("{0}")]
struct TestError(&'static str);

#[tracing::instrument]
fn get_error(msg: &'static str) -> Report {
fn create_report(msg: &'static str) -> Report {
Report::msg(msg)
.note("note")
.warning("warning")
.suggestion("suggestion")
.error(TestError("error"))
}

// Using `Option` to add dependency code. See https://github.com/yaahc/color-eyre/blob/4ddaeb2126ed8b14e4e6aa03d7eef49eb8561cf0/src/config.rs#L56
None::<Option<()>>
.ok_or_else(|| create_report(msg))
.unwrap_err()
}

fn main() {
setup();
println!("{:?}", get_error("test"));
}

fn setup() {
use tracing_error::ErrorLayer;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

std::env::set_var("RUST_LIB_BACKTRACE", "full");

let fmt_layer = fmt::layer().with_target(false);
let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
.unwrap();

tracing_subscriber::registry()
.with(filter_layer)
.with(fmt_layer)
.with(ErrorLayer::default())
.init();

color_eyre::config::HookBuilder::new()
.theme(theme())
.install()
.expect("Failed to install `color_eyre`");
}
56 changes: 56 additions & 0 deletions examples/theme_test_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! Nothing interesting here. This is just a small helper used in a test.

//! This needs to be an "example" until binaries can declare separate dependencies (see https://github.com/rust-lang/cargo/issues/1982)

//! See "tests/theme.rs" for more information.

use color_eyre::{eyre::Report, Section};
use tracing_error::ErrorLayer;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

#[rustfmt::skip]
#[derive(Debug, thiserror::Error)]
#[error("{0}")]
struct TestError(&'static str);

#[rustfmt::skip]
#[tracing::instrument]
fn get_error(msg: &'static str) -> Report {

#[rustfmt::skip]
#[inline(never)]
fn create_report(msg: &'static str) -> Report {
Report::msg(msg)
.note("note")
.warning("warning")
.suggestion("suggestion")
.error(TestError("error"))
}

// Getting regular `Report`. Using `Option` to trigger `is_dependency_code`. See https://github.com/yaahc/color-eyre/blob/4ddaeb2126ed8b14e4e6aa03d7eef49eb8561cf0/src/config.rs#L56
None::<Option<()>>.ok_or_else(|| create_report(msg)).unwrap_err()
}

fn main() {
setup();
let error = get_error("test");
panic!(error)
}

fn setup() {
std::env::set_var("RUST_LIB_BACKTRACE", "full");

let fmt_layer = fmt::layer().with_target(false);
let filter_layer = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new("info"))
.unwrap();

tracing_subscriber::registry()
.with(filter_layer)
.with(fmt_layer)
.with(ErrorLayer::default())
.init();

color_eyre::install().expect("Failed to install `color_eyre`");
}