-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy paththeme.rs
More file actions
63 lines (53 loc) · 1.85 KB
/
theme.rs
File metadata and controls
63 lines (53 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use color_eyre::{config::Theme, eyre::Report, Section};
use owo_colors::Style;
/// 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::new().blue())
.help_info_suggestion(Style::new().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/eyre-rs/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() {
std::env::set_var("RUST_LIB_BACKTRACE", "full");
#[cfg(feature = "capture-spantrace")]
{
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};
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(tracing_error::ErrorLayer::default())
.init();
}
color_eyre::config::HookBuilder::new()
.theme(theme())
.install()
.expect("Failed to install `color_eyre`");
}