Skip to content

Commit

Permalink
new: now theme elements declare some hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Jul 18, 2021
1 parent f7b43ed commit 0e4290f
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 304 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.10.0-alpha.2"
version = "0.10.0-alpha.3"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
80 changes: 33 additions & 47 deletions benches/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ macro_rules! collection {
}};
}

// ---

#[global_allocator]
static GLOBAL: &StatsAlloc<System> = &INSTRUMENTED_SYSTEM;

// ---

fn benchmark(c: &mut Criterion) {
let mut c = c.benchmark_group("theme");
let theme = Theme::from(&themecfg::Theme {
Expand Down Expand Up @@ -59,43 +63,28 @@ fn benchmark(c: &mut Criterion) {
foreground: Some(Color::Palette(255)),
background: None,
},
Element::EqualSign => Style {
Element::Field => Style {
modes: Vec::default(),
foreground: Some(Color::Palette(8)),
background: None,
},
Element::Brace => Style {
Element::Object => Style {
modes: Vec::default(),
foreground: Some(Color::Palette(246)),
background: None,
},
Element::Quote => Style {
Element::Array => Style {
modes: Vec::default(),
foreground: Some(Color::Palette(246)),
background: None,
},
Element::Delimiter => Style {
modes: Vec::default(),
foreground: Some(Color::Palette(8)),
background: None,
},
Element::Comma => Style {
modes: Vec::default(),
foreground: Some(Color::Palette(8)),
background: None,
},
Element::AtSign => Style {
modes: vec![Mode::Italic],
foreground: Some(Color::Palette(8)),
background: None,
},
Element::Ellipsis => Style {
modes: Vec::default(),
foreground: Some(Color::Palette(8)),
background: None,
},
Element::FieldKey => Style {
modes: Vec::default(),
Element::Key => Style {
modes: vec![Mode::Underline],
foreground: Some(Color::Palette(117)),
background: None,
},
Expand All @@ -119,11 +108,6 @@ fn benchmark(c: &mut Criterion) {
foreground: Some(Color::Palette(36)),
background: None,
},
Element::Whitespace => Style {
modes: Vec::default(),
foreground: None,
background: None,
},
})
.into(),
levels: HashMap::new(),
Expand All @@ -150,17 +134,19 @@ fn benchmark(c: &mut Criterion) {
s.batch(|buf| buf.extend_from_slice(b"2020-01-01 00:00:00"))
});
s.batch(|buf| buf.push(b' '));
s.element(Element::Delimiter, |s| s.batch(|buf| buf.push(b'|')));
s.element(Element::Level, |s| {
s.batch(|buf| buf.extend_from_slice(b"INF"))
s.batch(|buf| buf.push(b'|'));
s.element(Element::LevelInner, |s| {
s.batch(|buf| buf.extend_from_slice(b"INF"))
});
s.batch(|buf| buf.push(b'|'))
});
s.element(Element::Delimiter, |s| s.batch(|buf| buf.push(b'|')));
s.batch(|buf| buf.push(b' '));
s.element(Element::Logger, |s| {
s.batch(|buf| {
buf.extend_from_slice(b"logger");
buf.push(b':');
})
s.element(Element::LoggerInner, |s| {
s.batch(|buf| buf.extend_from_slice(b"logger"))
});
s.batch(|buf| buf.push(b':'))
});
s.batch(|buf| buf.push(b' '));
s.element(Element::Message, |s| {
Expand All @@ -170,25 +156,23 @@ fn benchmark(c: &mut Criterion) {
});
for _ in 0..4 {
for (key, value) in &fields {
s.batch(|buf| buf.push(b' '));
s.element(Element::FieldKey, |s| {
s.batch(|buf| {
buf.extend_from_slice(&key[..]);
})
});
s.element(Element::EqualSign, |s| s.batch(|buf| buf.push(b'=')));
s.element(Element::String, |s| {
s.batch(|buf| {
buf.extend_from_slice(&value[..]);
})
s.element(Element::Field, |s| {
s.batch(|buf| buf.push(b' '));
s.element(Element::Key, |s| {
s.batch(|buf| buf.extend_from_slice(&key[..]))
});
s.batch(|buf| buf.push(b'='));
s.element(Element::String, |s| {
s.batch(|buf| buf.extend_from_slice(&value[..]))
});
});
}
}
s.element(Element::AtSign, |s| {
s.batch(|buf| buf.extend_from_slice(b" @ "))
});
s.element(Element::Caller, |s| {
s.batch(|buf| buf.extend_from_slice(b"caller"))
s.batch(|buf| buf.extend_from_slice(b" @ "));
s.element(Element::CallerInner, |s| {
s.batch(|buf| buf.extend_from_slice(b"caller"))
});
});
});
n1 += 1;
Expand All @@ -198,5 +182,7 @@ fn benchmark(c: &mut Criterion) {
println!("allocations at 1 ({:?} iterations): {:#?}", n1, c1);
}

// ---

criterion_group!(benches, benchmark);
criterion_main!(benches);
22 changes: 9 additions & 13 deletions etc/defaults/themes/classic-light.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,26 @@ default:
foreground: bright-black
level:
foreground: magenta
delimiter:
foreground: default
message:
foreground: black
field-key:
foreground: green
equal-sign:
field:
foreground: bright-black
key:
foreground: green
ellipsis:
foreground: bright-black
brace:
object:
foreground: default
quote:
array:
foreground: default
at-sign:
foreground: bright-black
string:
foreground: default
'null':
foreground: yellow
boolean:
foreground: yellow
number:
foreground: cyan
boolean:
foreground: yellow
'null':
foreground: yellow
levels:
debug:
level:
Expand Down
22 changes: 9 additions & 13 deletions etc/defaults/themes/classic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,26 @@ default:
foreground: bright-black
level:
foreground: magenta
delimiter:
foreground: default
message:
foreground: bright-white
field-key:
foreground: green
equal-sign:
field:
foreground: bright-black
key:
foreground: green
ellipsis:
foreground: bright-black
brace:
object:
foreground: default
quote:
array:
foreground: default
at-sign:
foreground: bright-black
string:
foreground: default
'null':
foreground: yellow
boolean:
foreground: yellow
number:
foreground: cyan
boolean:
foreground: yellow
'null':
foreground: yellow
levels:
debug:
level:
Expand Down
37 changes: 16 additions & 21 deletions etc/defaults/themes/dmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,42 @@ default:
foreground: 8
modes: [italic]
level:
foreground: 25
delimiter:
foreground: 8
message:
foreground: 255
field-key:
field:
foreground: 8
key:
foreground: 117
modes: [underline]
equal-sign:
foreground: 8
quote:
foreground: 246
brace:
foreground: 41
ellipsis:
foreground: 8
at-sign:
foreground: 8
modes: [italic]
'null':
foreground: 136
boolean:
foreground: 178
number:
object:
foreground: 41
array:
foreground: 41
string:
foreground: 36
number:
foreground: 41
boolean:
foreground: 178
'null':
foreground: 136
levels:
debug:
level:
level-inner:
foreground: 26
info:
level:
level-inner:
foreground: 32
warning:
time:
foreground: 192
level:
level-inner:
foreground: 192
error:
time:
foreground: 214
level:
level-inner:
foreground: 214
35 changes: 15 additions & 20 deletions etc/defaults/themes/lsd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,44 @@ default:
foreground: bright-black
modes: [italic]
level:
foreground: magenta
delimiter:
foreground: bright-black
message:
foreground: bright-white
field-key:
field:
foreground: default
key:
foreground: bright-blue
modes: [underline]
equal-sign:
foreground: default
quote:
foreground: green
brace:
foreground: blue
ellipsis:
foreground: bright-black
at-sign:
foreground: bright-black
modes: [italic]
'null':
object:
foreground: blue
array:
foreground: blue
string:
foreground: green
number:
foreground: yellow
boolean:
foreground: yellow
number:
'null':
foreground: yellow
string:
foreground: green
levels:
debug:
level:
level-inner:
foreground: magenta
info:
level:
level-inner:
foreground: cyan
warning:
time:
foreground: yellow
level:
level-inner:
foreground: bright-yellow
modes: [bold]
error:
time:
foreground: red
level:
level-inner:
foreground: bright-red
modes: [bold]
Loading

0 comments on commit 0e4290f

Please sign in to comment.