mirror of https://github.com/sharkdp/bat.git
Compare commits
2 Commits
027e827bd7
...
9a39a3e1e6
Author | SHA1 | Date |
---|---|---|
Tau Gärtli | 9a39a3e1e6 | |
Tau Gärtli | 8bbaf1f4a3 |
|
@ -1323,9 +1323,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "terminal-colorsaurus"
|
||||
version = "0.3.3"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a11d4fd698c3b697b6f712fa75f62f7b15119f41b0bb660741dd02297f534d78"
|
||||
checksum = "fc3b74af7c844e628c5dafa421ec59283e9f0bed5cb49956439316ec6d8728f1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"memchr",
|
||||
|
|
|
@ -68,7 +68,7 @@ bytesize = { version = "1.3.0" }
|
|||
encoding_rs = "0.8.33"
|
||||
os_str_bytes = { version = "~7.0", optional = true }
|
||||
run_script = { version = "^0.10.1", optional = true}
|
||||
terminal-colorsaurus = { version = "0.3.3" }
|
||||
terminal-colorsaurus = { version = "0.4.0" }
|
||||
|
||||
[dependencies.git2]
|
||||
version = "0.18"
|
||||
|
|
18
src/theme.rs
18
src/theme.rs
|
@ -92,6 +92,15 @@ pub enum ColorScheme {
|
|||
Light,
|
||||
}
|
||||
|
||||
impl From<terminal_colorsaurus::ColorScheme> for ColorScheme {
|
||||
fn from(scheme: terminal_colorsaurus::ColorScheme) -> Self {
|
||||
match scheme {
|
||||
terminal_colorsaurus::ColorScheme::Dark => ColorScheme::Dark,
|
||||
terminal_colorsaurus::ColorScheme::Light => ColorScheme::Light,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn theme_from_detector(options: ThemeOptions, detector: &dyn ColorSchemeDetector) -> String {
|
||||
// Implementation note: This function is mostly pure (i.e. it has no side effects) for the sake of testing.
|
||||
// All the side effects (e.g. querying the terminal for its colors) are performed in the detector.
|
||||
|
@ -145,12 +154,9 @@ impl ColorSchemeDetector for TerminalColorSchemeDetector {
|
|||
|
||||
fn detect(&self) -> Option<ColorScheme> {
|
||||
use terminal_colorsaurus::{color_scheme, QueryOptions};
|
||||
let colors = color_scheme(QueryOptions::default()).ok()?;
|
||||
if colors.is_light_on_dark() {
|
||||
Some(ColorScheme::Dark)
|
||||
} else {
|
||||
Some(ColorScheme::Light)
|
||||
}
|
||||
color_scheme(QueryOptions::default())
|
||||
.map(ColorScheme::from)
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue