mirror of
https://github.com/sharkdp/bat.git
synced 2025-04-14 06:40:39 +01:00
Directly read preferences instead of using the defaults CLI
This commit is contained in:
parent
6122d43e79
commit
1004018941
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
- Various bash completion improvements, see #2310 (@scop)
|
- Various bash completion improvements, see #2310 (@scop)
|
||||||
- Disable completion of `cache` subcommand, see #2399 (@cyqsimon)
|
- Disable completion of `cache` subcommand, see #2399 (@cyqsimon)
|
||||||
|
- Signifigantly improve startup performance on macOS, see #2442 (@BlackHoleFox)
|
||||||
|
|
||||||
## Syntaxes
|
## Syntaxes
|
||||||
|
|
||||||
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -97,6 +97,7 @@ dependencies = [
|
|||||||
"nix",
|
"nix",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"path_abs",
|
"path_abs",
|
||||||
|
"plist",
|
||||||
"predicates",
|
"predicates",
|
||||||
"regex",
|
"regex",
|
||||||
"semver",
|
"semver",
|
||||||
|
@ -81,6 +81,10 @@ version = "4.0.2"
|
|||||||
optional = true
|
optional = true
|
||||||
features = ["wrap_help", "cargo"]
|
features = ["wrap_help", "cargo"]
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
|
dirs-next = "2.0.0"
|
||||||
|
plist = "1.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_cmd = "2.0.8"
|
assert_cmd = "2.0.8"
|
||||||
expect-test = "1.4.0"
|
expect-test = "1.4.0"
|
||||||
|
@ -401,11 +401,21 @@ fn asset_from_cache<T: serde::de::DeserializeOwned>(
|
|||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn macos_dark_mode_active() -> bool {
|
fn macos_dark_mode_active() -> bool {
|
||||||
let mut defaults_cmd = std::process::Command::new("defaults");
|
const PREFERENCES_FILE: &str = "Library/Preferences/.GlobalPreferences.plist";
|
||||||
defaults_cmd.args(&["read", "-globalDomain", "AppleInterfaceStyle"]);
|
const STYLE_KEY: &str = "AppleInterfaceStyle";
|
||||||
match defaults_cmd.output() {
|
|
||||||
Ok(output) => output.stdout == b"Dark\n",
|
let preferences_file = dirs_next::home_dir()
|
||||||
Err(_) => true,
|
.map(|home| home.join(PREFERENCES_FILE))
|
||||||
|
.expect("Could not get home directory");
|
||||||
|
|
||||||
|
match plist::Value::from_file(preferences_file).map(|file| file.into_dictionary()) {
|
||||||
|
Ok(Some(preferences)) => match preferences.get(STYLE_KEY).and_then(|val| val.as_string()) {
|
||||||
|
Some(value) => value == "Dark",
|
||||||
|
// If the key does not exist, then light theme is currently in use.
|
||||||
|
None => false,
|
||||||
|
},
|
||||||
|
// Unreachable, in theory. All macOS users have a home directory and preferences file setup.
|
||||||
|
Ok(None) | Err(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user