summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2022-02-27 12:08:23 -0500
committerGitHub <noreply@github.com>2022-02-27 12:08:23 -0500
commit1403fe2b8ef26c84cd625bb6f550755f82f47576 (patch)
tree88e070c3d504742af532729c5eb9cd7c3c65c71d
parente44435c8f8646d18f12d26e37c3ebe9b83d7f0a3 (diff)
Use assets API from bat library instead of vendored code (#903)
Use assets API from bat library Fixes #895 Ref https://github.com/sharkdp/bat/issues/2026 Thanks @Enselic
-rw-r--r--Cargo.lock324
-rw-r--r--Cargo.toml1
-rw-r--r--etc/assets/syntaxes.binbin701812 -> 0 bytes
-rw-r--r--etc/assets/themes.binbin21378 -> 0 bytes
-rw-r--r--src/cli.rs5
-rw-r--r--src/main.rs4
-rw-r--r--src/options/set.rs2
-rw-r--r--src/options/theme.rs39
-rw-r--r--src/subcommands/list_syntax_themes.rs18
-rw-r--r--src/subcommands/show_colors.rs5
-rw-r--r--src/subcommands/show_syntax_themes.rs17
-rw-r--r--src/utils/bat/assets.rs81
12 files changed, 357 insertions, 139 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7a460881..f5652d7f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -19,11 +19,11 @@ dependencies = [
[[package]]
name = "ansi_colours"
-version = "1.0.4"
+version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "60e2fb6138a49ad9f1cb3c6d8f8ccbdd5e62b4dab317c1b435a47ecd7da1d28f"
+checksum = "32678233b67f9056b0c144b39d46dc3218637e8d84ad6038ded339e08b19620d"
dependencies = [
- "cc",
+ "rgb",
]
[[package]]
@@ -74,6 +74,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
+name = "bat"
+version = "0.20.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f59cdca60e52d7c8ea28dd2b627ab0478e4d4a2df7cc30a13322aadb21035217"
+dependencies = [
+ "ansi_colours",
+ "ansi_term",
+ "atty",
+ "bincode",
+ "bugreport",
+ "bytesize",
+ "clap 2.34.0",
+ "clircle",
+ "console",
+ "content_inspector",
+ "dirs-next",
+ "encoding",
+ "flate2",
+ "git2",
+ "globset",
+ "grep-cli",
+ "once_cell",
+ "path_abs",
+ "regex",
+ "semver",
+ "serde",
+ "serde_yaml",
+ "shell-words",
+ "syntect",
+ "thiserror",
+ "unicode-width",
+ "walkdir",
+ "wild",
+]
+
+[[package]]
name = "bincode"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -107,18 +143,41 @@ dependencies = [
]
[[package]]
+name = "bugreport"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0014b4b2b4f63bfe69c3838470121290cc437fdc79785d408a761a21e8b2404c"
+dependencies = [
+ "git-version",
+ "shell-escape",
+ "sys-info",
+]
+
+[[package]]
name = "bytelines"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "791e4e40d13e1463dee537b254225c12c46ec7328f1817c6264873bc166f615f"
[[package]]
+name = "bytemuck"
+version = "1.7.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "439989e6b8c38d1b6570a384ef1e49c8848128f5a97f3914baef02920842712f"
+
+[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
+name = "bytesize"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70"
+
+[[package]]
name = "cc"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -163,6 +222,22 @@ dependencies = [
[[package]]
name = "clap"
+version = "2.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
+dependencies = [
+ "ansi_term",
+ "atty",
+ "bitflags",
+ "strsim 0.8.0",
+ "term_size",
+ "textwrap 0.11.0",
+ "unicode-width",
+ "vec_map",
+]
+
+[[package]]
+name = "clap"
version = "3.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12e8611f9ae4e068fa3e56931fded356ff745e70987ff76924a6e0ab1c8ef2e3"
@@ -173,9 +248,9 @@ dependencies = [
"indexmap",
"lazy_static",
"os_str_bytes",
- "strsim",
+ "strsim 0.10.0",
"termcolor",
- "textwrap",
+ "textwrap 0.14.2",
]
[[package]]
@@ -192,6 +267,18 @@ dependencies = [
]
[[package]]
+name = "clircle"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e68bbd985a63de680ab4d1ad77b6306611a8f961b282c8b5ab513e6de934e396"
+dependencies = [
+ "cfg-if 1.0.0",
+ "libc",
+ "serde",
+ "winapi",
+]
+
+[[package]]
name = "console"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -207,6 +294,15 @@ dependencies = [
]
[[package]]
+name = "content_inspector"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7bda66e858c683005a53a9a60c69a4aca7eeaa45d124526e389f7aec8e62f38"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
name = "core-foundation-sys"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -285,6 +381,70 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
+name = "encoding"
+version = "0.2.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
+dependencies = [
+ "encoding-index-japanese",
+ "encoding-index-korean",
+ "encoding-index-simpchinese",
+ "encoding-index-singlebyte",
+ "encoding-index-tradchinese",
+]
+
+[[package]]
+name = "encoding-index-japanese"
+version = "1.20141219.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91"
+dependencies = [
+ "encoding_index_tests",
+]
+
+[[package]]
+name = "encoding-index-korean"
+version = "1.20141219.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81"
+dependencies = [
+ "encoding_index_tests",
+]
+
+[[package]]
+name = "encoding-index-simpchinese"
+version = "1.20141219.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7"
+dependencies = [
+ "encoding_index_tests",
+]
+
+[[package]]
+name = "encoding-index-singlebyte"
+version = "1.20141219.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
+dependencies = [
+ "encoding_index_tests",
+]
+
+[[package]]
+name = "encoding-index-tradchinese"
+version = "1.20141219.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
+dependencies = [
+ "encoding_index_tests",
+]
+
+[[package]]
+name = "encoding_index_tests"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
+
+[[package]]
name = "error-chain"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -359,12 +519,13 @@ dependencies = [
"ansi_colours",
"ansi_term",
"atty",
+ "bat",
"bitflags",
"box_drawing",
"bytelines",
"chrono",
"chrono-humanize",
- "clap",
+ "clap 3.0.7",
"console",
"ctrlc",
"dirs-next",
@@ -389,6 +550,28 @@ dependencies = [
]
[[package]]
+name = "git-version"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6b0decc02f4636b9ccad390dcbe77b722a77efedfa393caf8379a51d5c61899"
+dependencies = [
+ "git-version-macro",
+ "proc-macro-hack",
+]
+
+[[package]]
+name = "git-version-macro"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fe69f1cbdb6e28af2bac214e943b99ce8a0a06b447d15d3e61161b0423139f3f"
+dependencies = [
+ "proc-macro-hack",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "git2"
version = "0.13.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -402,6 +585,12 @@ dependencies = [
]
[[package]]
+name = "glob"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
+
+[[package]]
name = "globset"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -640,9 +829,9 @@ dependencies = [
[[package]]
name = "once_cell"
-version = "1.8.0"
+version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
+checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]]
name = "onig"
@@ -700,6 +889,15 @@ dependencies = [
]
[[package]]
+name = "path_abs"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05ef02f6342ac01d8a93b65f96db53fe68a92a15f41144f97fb00a9e669633c3"
+dependencies = [
+ "std_prelude",
+]
+
+[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -928,6 +1126,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581"
[[package]]
+name = "rgb"
+version = "0.8.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a374af9a0e5fdcdd98c1c7b64f05004f9ea2555b6c75f211daa81268a3c50f1"
+dependencies = [
+ "bytemuck",
+]
+
+[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -949,6 +1156,12 @@ dependencies = [
]
[[package]]
+name = "semver"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4a3381e03edd24287172047536f20cabde766e2cd3e65e6b00fb3af51c4f38d"
+
+[[package]]
name = "serde"
version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -980,6 +1193,24 @@ dependencies = [
]
[[package]]
+name = "serde_yaml"
+version = "0.8.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4a521f2940385c165a24ee286aa8599633d162077a54bdcae2a6fd5a7bfa7a0"
+dependencies = [
+ "indexmap",
+ "ryu",
+ "serde",
+ "yaml-rust",
+]
+
+[[package]]
+name = "shell-escape"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f"
+
+[[package]]
name = "shell-words"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1001,6 +1232,18 @@ dependencies = [
]
[[package]]
+name = "std_prelude"
+version = "0.2.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8207e78455ffdf55661170876f88daf85356e4edd54e0a3dbc79586ca1e50cbe"
+
+[[package]]
+name = "strsim"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+
+[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1040,6 +1283,16 @@ dependencies = [
]
[[package]]
+name = "sys-info"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c"
+dependencies = [
+ "cc",
+ "libc",
+]
+
+[[package]]
name = "sysinfo"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1054,6 +1307,16 @@ dependencies = [
]
[[package]]
+name = "term_size"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9"
+dependencies = [
+ "libc",
+ "winapi",
+]
+
+[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1074,11 +1337,41 @@ dependencies = [
[[package]]
name = "textwrap"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
+dependencies = [
+ "term_size",
+ "unicode-width",
+]
+
+[[package]]
+name = "textwrap"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
[[package]]
+name = "thiserror"
+version = "1.0.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1174,6 +1467,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb"
[[package]]
+name = "vec_map"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
+
+[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1224,6 +1523,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
+name = "wild"
+version = "2.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "035793abb854745033f01a07647a79831eba29ec0be377205f2a25b0aa830020"
+dependencies = [
+ "glob",
+]
+
+[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 9201f41e..9d89bedf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,6 +15,7 @@ name = "delta"
path = "src/main.rs"
[dependencies]
+bat = "0.20.0"
chrono = "0.4.19"
chrono-humanize = "0.2.1"
ansi_colours = "1.0.4"
diff --git a/etc/assets/syntaxes.bin b/etc/assets/syntaxes.bin
deleted file mode 100644
index 9bd09ea9..00000000
--- a/etc/assets/syntaxes.bin
+++ /dev/null
Binary files differ
diff --git a/etc/assets/themes.bin b/etc/assets/themes.bin
deleted file mode 100644
index 9c31eb7d..00000000
--- a/etc/assets/themes.bin
+++ /dev/null
Binary files differ
diff --git a/src/cli.rs b/src/cli.rs
index f9ea3300..15efd15e 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet};
use std::ffi::OsString;
use std::path::PathBuf;
+use bat::assets::HighlightingAssets;
use clap::{AppSettings, ColorChoice, FromArgMatches, IntoApp, Parser};
use lazy_static::lazy_static;
use syntect::highlighting::Theme as SyntaxTheme;
@@ -10,7 +11,7 @@ use syntect::parsing::SyntaxSet;
use crate::config::delta_unreachable;
use crate::git_config::{GitConfig, GitConfigEntry};
use crate::options;
-use crate::utils::bat::assets::HighlightingAssets;
+use crate::utils;
use crate::utils::bat::output::PagingMode;
#[derive(Parser)]
@@ -1130,7 +1131,7 @@ impl Opt {
I: IntoIterator,
I::Item: Into<OsString> + Clone,
{
- let assets = HighlightingAssets::new();
+ let assets = utils::bat::assets::load_highlighting_assets();
Self::from_clap_and_git_config(Self::into_app().get_matches_from(iter), git_config, assets)
}
diff --git a/src/main.rs b/src/main.rs
index 1de9375b..980502fb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -35,7 +35,7 @@ use std::process;
use bytelines::ByteLinesReader;
use crate::delta::delta;
-use crate::utils::bat::assets::{list_languages, HighlightingAssets};
+use crate::utils::bat::assets::list_languages;
use crate::utils::bat::output::OutputType;
pub fn fatal<T>(errmsg: T) -> !
@@ -85,7 +85,7 @@ fn main() -> std::io::Result<()> {
// report that two files differ when delta is called with two positional
// arguments and without standard input; 2 is used to report a real problem.
fn run_app() -> std::io::Result<i32> {
- let assets = HighlightingAssets::new();
+ let assets = utils::bat::assets::load_highlighting_assets();
let opt = cli::Opt::from_args_and_git_config(git_config::GitConfig::try_create(), assets);
let subcommand_result = if opt.list_languages {
diff --git a/src/options/set.rs b/src/options/set.rs
index 95b83dca..57d95b27 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -3,6 +3,7 @@ use std::convert::TryInto;
use std::result::Result;
use std::str::FromStr;
+use bat::assets::HighlightingAssets;
use console::Term;
use crate::cli;
@@ -14,7 +15,6 @@ use crate::features;
use crate::git_config::{GitConfig, GitConfigEntry};
use crate::options::option_value::{OptionValue, ProvenancedOptionValue};
use crate::options::theme;
-use crate::utils::bat::assets::HighlightingAssets;
use crate::utils::bat::output::PagingMode;
macro_rules! set_options {
diff --git a/src/options/theme.rs b/src/options/theme.rs
index 55260eb6..642699c2 100644
--- a/src/options/theme.rs
+++ b/src/options/theme.rs
@@ -6,11 +6,11 @@
/// by the user, it is determined by the classification of the syntax theme into light-background
/// vs dark-background syntax themes. If the user didn't choose a syntax theme, a dark-background
/// default is selected.
-use syntect::highlighting::ThemeSet;
+use bat;
+use bat::assets::HighlightingAssets;
use crate::cli;
use crate::env;
-use crate::utils::bat::assets::HighlightingAssets;
#[allow(non_snake_case)]
pub fn set__is_light_mode__syntax_theme__syntax_set(
@@ -22,16 +22,15 @@ pub fn set__is_light_mode__syntax_theme__syntax_set(
opt.syntax_theme.as_ref(),
syntax_theme_name_from_bat_theme.as_ref(),
opt.light,
- &assets.theme_set,
);
opt.computed.is_light_mode = is_light_mode;
opt.computed.syntax_theme = if is_no_syntax_highlighting_syntax_theme_name(&syntax_theme_name) {
None
} else {
- Some(assets.theme_set.themes[&syntax_theme_name].clone())
+ Some(assets.get_theme(&syntax_theme_name).clone())
};
- opt.computed.syntax_set = assets.syntax_set;
+ opt.computed.syntax_set = assets.get_syntax_set().unwrap().clone();
}
pub fn is_light_syntax_theme(theme: &str) -> bool {
@@ -86,34 +85,16 @@ fn get_is_light_mode_and_syntax_theme_name(
theme_arg: Option<&String>,
bat_theme_env_var: Option<&String>,
light_mode_arg: bool,
- theme_set: &ThemeSet,
) -> (bool, String) {
- let theme_arg = valid_syntax_theme_name_or_none(theme_arg, theme_set);
- let bat_theme_env_var = valid_syntax_theme_name_or_none(bat_theme_env_var, theme_set);
match (theme_arg, bat_theme_env_var, light_mode_arg) {
(None, None, false) => (false, DEFAULT_DARK_SYNTAX_THEME.to_string()),
- (Some(theme_name), _, false) => (is_light_syntax_theme(&theme_name), theme_name),
- (None, Some(theme_name), false) => (is_light_syntax_theme(&theme_name), theme_name),
- (None, None, true) => (true, DEFAULT_LIGHT_SYNTAX_THEME.to_string()),
- (Some(theme_name), _, is_light_mode) => (is_light_mode, theme_name),
- (None, Some(theme_name), is_light_mode) => (is_light_mode, theme_name),
- }
-}
-
-// At this stage the theme name is considered valid if it is either a real theme name or the special
-// no-syntax-highlighting name.
-fn valid_syntax_theme_name_or_none(
- theme_name: Option<&String>,
- theme_set: &ThemeSet,
-) -> Option<String> {
- match theme_name {
- Some(name)
- if is_no_syntax_highlighting_syntax_theme_name(name)
- || theme_set.themes.contains_key(name) =>
- {
- Some(name.to_string())
+ (Some(theme_name), _, false) => (is_light_syntax_theme(theme_name), theme_name.to_string()),
+ (None, Some(theme_name), false) => {
+ (is_light_syntax_theme(theme_name), theme_name.to_string())
}
- _ => None,
+ (None, None, true) => (true, DEFAULT_LIGHT_SYNTAX_THEME.to_string()),
+ (Some(theme_name), _, is_light_mode) => (is_light_mode, theme_name.to_string()),
+ (None, Some(theme_name), is_light_mode) => (is_light_mode, theme_name.to_string()),
}
}
diff --git a/src/subcommands/list_syntax_themes.rs b/src/subcommands/list_syntax_themes.rs
index 789c619b..34a7b0b4 100644
--- a/src/subcommands/list_syntax_themes.rs
+++ b/src/subcommands/list_syntax_themes.rs
@@ -2,8 +2,7 @@ use std::io::{self, Write};
use itertools::Itertools;
-use crate::options::theme::is_light_syntax_theme;
-use crate::utils::bat::assets::HighlightingAssets;
+use crate::{options::theme::is_light_syntax_theme, utils};
#[cfg(not(tarpaulin_include))]
pub fn list_syntax_themes() -> std::io::Result<()> {
@@ -17,15 +16,14 @@ pub fn list_syntax_themes() -> std::io::Result<()> {
}
pub fn _list_syntax_themes_for_humans(writer: &mut dyn Write) -> std::io::Result<()> {
- let assets = HighlightingAssets::new();
- let themes = &assets.theme_set.themes;
+ let assets = utils::bat::assets::load_highlighting_assets();
writeln!(writer, "Light syntax themes:")?;
- for (theme, _) in themes.iter().filter(|(t, _)| is_light_syntax_theme(*t)) {
+ for theme in assets.themes().filter(|t| is_light_syntax_theme(*t)) {
writeln!(writer, " {}", theme)?;
}
writeln!(writer, "\nDark syntax themes:")?;
- for (theme, _) in themes.iter().filter(|(t, _)| !is_light_syntax_theme(*t)) {
+ for theme in assets.themes().filter(|t| !is_light_syntax_theme(*t)) {
writeln!(writer, " {}", theme)?;
}
writeln!(
@@ -36,12 +34,8 @@ pub fn _list_syntax_themes_for_humans(writer: &mut dyn Write) -> std::io::Result
}
pub fn _list_syntax_themes_for_machines(writer: &mut dyn Write) -> std::io::Result<()> {
- let assets = HighlightingAssets::new();
- let themes = &assets.theme_set.themes;
- for (theme, _) in themes
- .iter()
- .sorted_by_key(|(t, _)| is_light_syntax_theme(*t))
- {
+ let assets = utils::bat::assets::load_highlighting_assets();
+ for theme in assets.themes().sorted_by_key(|t| is_light_syntax_theme(*t)) {
writeln!(
writer,
"{}\t{}",
diff --git a/src/subcommands/show_colors.rs b/src/subcommands/show_colors.rs
index 1c939700..09a8f19b 100644
--- a/src/subcommands/show_colors.rs
+++ b/src/subcommands/show_colors.rs
@@ -7,16 +7,15 @@ use crate::git_config;
use crate::paint;
use crate::paint::BgShouldFill;
use crate::style;
-use crate::utils::bat::assets::HighlightingAssets;
use crate::utils::bat::output::{OutputType, PagingMode};
#[cfg(not(tarpaulin_include))]
pub fn show_colors() -> std::io::Result<()> {
use itertools::Itertools;
- use crate::delta::DiffType;
+ use crate::{delta::DiffType, utils};
- let assets = HighlightingAssets::new();
+ let assets = utils::bat::assets::load_highlighting_assets();
let opt = cli::Opt::from_args_and_git_config(git_config::GitConfig::try_create(), assets);
let config = config::Config::from(opt);
diff --git a/src/subcommands/show_syntax_themes.rs b/src/subcommands/show_syntax_themes.rs
index ff018d3f..be7478a4 100644
--- a/src/subcommands/show_syntax_themes.rs
+++ b/src/subcommands/show_syntax_themes.rs
@@ -2,14 +2,14 @@ use crate::cli;
use crate::config;
use crate::delta;
use crate::options::theme::is_light_syntax_theme;
-use crate::utils::bat::assets::HighlightingAssets;
+use crate::utils;
use crate::utils::bat::output::{OutputType, PagingMode};
use clap::Parser;
use std::io::{self, ErrorKind, Read, Write};
#[cfg(not(tarpaulin_include))]
pub fn show_syntax_themes() -> std::io::Result<()> {
- let assets = HighlightingAssets::new();
+ let assets = utils::bat::assets::load_highlighting_assets();
let mut output_type = OutputType::from_mode(
PagingMode::QuitIfOneScreen,
None,
@@ -32,7 +32,7 @@ pub fn show_syntax_themes() -> std::io::Result<()> {
let make_opt = || {
let mut opt = cli::Opt::parse();
- opt.computed.syntax_set = assets.syntax_set.clone();
+ opt.computed.syntax_set = assets.get_syntax_set().unwrap().clone();
opt
};
let opt = make_opt();
@@ -80,21 +80,18 @@ index f38589a..0f1bb83 100644
opt.computed.is_light_mode = is_light_mode;
let mut config = config::Config::from(opt);
let title_style = ansi_term::Style::new().bold();
- let assets = HighlightingAssets::new();
+ let assets = utils::bat::assets::load_highlighting_assets();
for syntax_theme in assets
- .theme_set
- .themes
- .iter()
- .filter(|(t, _)| is_light_syntax_theme(t) == is_light_mode)
- .map(|(t, _)| t)
+ .themes()
+ .filter(|t| is_light_syntax_theme(t) == is_light_mode)
{
writeln!(
writer,
"\n\nSyntax theme: {}\n",
title_style.paint(syntax_theme)
)?;
- config.syntax_theme = Some(assets.theme_set.themes[syntax_theme.as_str()].clone());
+ config.syntax_theme = Some(assets.get_theme(syntax_theme).clone());
if let Err(error) =
delta::delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config)
{
diff --git a/src/utils/bat/assets.rs b/src/utils/bat/assets.rs
index cfe0f5bd..0eb3049b 100644
--- a/src/utils/bat/assets.rs
+++ b/src/utils/bat/assets.rs
@@ -1,87 +1,24 @@
// Based on code from https://github.com/sharkdp/bat a1b9334a44a2c652f52dddaa83dbacba57372468
// See src/utils/bat/LICENSE
-use std::fs::File;
-use std::io::{self, BufReader, Write};
-use std::path::PathBuf;
+use std::io::{self, Write};
use ansi_term::Colour::Green;
use ansi_term::Style;
-use syntect::dumps::{from_binary, from_reader};
-use syntect::highlighting::ThemeSet;
-use syntect::parsing::SyntaxSet;
+use bat;
-use crate::errors::*;
-use crate::utils::bat::dirs::PROJECT_DIRS;
+use crate::utils;
-pub struct HighlightingAssets {
- pub syntax_set: SyntaxSet,
- pub theme_set: ThemeSet,
-}
-
-impl HighlightingAssets {
- pub fn new() -> Self {
- Self::from_cache().unwrap_or_else(|_| Self::from_binary())
- }
-
- fn get_integrated_syntaxset() -> SyntaxSet {
- from_binary(include_bytes!("../../../etc/assets/syntaxes.bin"))
- }
-
- fn get_integrated_themeset() -> ThemeSet {
- from_binary(include_bytes!("../../../etc/assets/themes.bin"))
- }
-
- fn from_cache() -> Result<Self> {
- let theme_set_path = theme_set_path();
- let syntax_set_file = File::open(&syntax_set_path()).chain_err(|| {
- format!(
- "Could not load cached syntax set '{}'",
- syntax_set_path().to_string_lossy()
- )
- })?;
- let syntax_s