mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-21 12:28:30 +00:00
Support a hidden arg --no-custom-assets that skips loading assets from the cache
This commit is contained in:
parent
a81009607a
commit
b040efff79
1
assets/completions/bat.zsh.in
vendored
1
assets/completions/bat.zsh.in
vendored
@ -45,6 +45,7 @@ _{{PROJECT_EXECUTABLE}}_main() {
|
|||||||
'(-r --line-range)'{-r+,--line-range=}'[Only print the lines from N to M]:<N\:M>...'
|
'(-r --line-range)'{-r+,--line-range=}'[Only print the lines from N to M]:<N\:M>...'
|
||||||
'(: --list-themes --list-languages -L)'{-L,--list-languages}'[Display all supported languages]'
|
'(: --list-themes --list-languages -L)'{-L,--list-languages}'[Display all supported languages]'
|
||||||
'(: --no-config)'--no-config'[Do not use the configuration file]'
|
'(: --no-config)'--no-config'[Do not use the configuration file]'
|
||||||
|
'(: --no-custom-assets)'--no-custom-assets'[Do not load custom assets]'
|
||||||
'(: --config-dir)'--config-dir'[Show bat'"'"'s configuration directory]'
|
'(: --config-dir)'--config-dir'[Show bat'"'"'s configuration directory]'
|
||||||
'(: --config-file)'--config-file'[Show path to the configuration file]'
|
'(: --config-file)'--config-file'[Show path to the configuration file]'
|
||||||
'(: --generate-config-file)'--generate-config-file'[Generates a default configuration file]'
|
'(: --generate-config-file)'--generate-config-file'[Generates a default configuration file]'
|
||||||
|
@ -234,6 +234,7 @@ impl App {
|
|||||||
.map(LineRanges::from)
|
.map(LineRanges::from)
|
||||||
.map(HighlightedLineRanges)
|
.map(HighlightedLineRanges)
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
|
use_custom_assets: !self.matches.is_present("no-custom-assets"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ pub fn clear_assets() {
|
|||||||
clear_asset("metadata.yaml", "metadata file");
|
clear_asset("metadata.yaml", "metadata file");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn assets_from_cache_or_binary() -> Result<HighlightingAssets> {
|
pub fn assets_from_cache_or_binary(use_custom_assets: bool) -> Result<HighlightingAssets> {
|
||||||
let cache_dir = PROJECT_DIRS.cache_dir();
|
let cache_dir = PROJECT_DIRS.cache_dir();
|
||||||
if let Some(metadata) = AssetsMetadata::load_from_folder(&cache_dir)? {
|
if let Some(metadata) = AssetsMetadata::load_from_folder(&cache_dir)? {
|
||||||
if !metadata.is_compatible_with(crate_version!()) {
|
if !metadata.is_compatible_with(crate_version!()) {
|
||||||
@ -41,8 +41,12 @@ pub fn assets_from_cache_or_binary() -> Result<HighlightingAssets> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(HighlightingAssets::from_cache(&cache_dir)
|
let custom_assets = if use_custom_assets {
|
||||||
.unwrap_or_else(|_| HighlightingAssets::from_binary()))
|
HighlightingAssets::from_cache(&cache_dir).ok()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
Ok(custom_assets.unwrap_or_else(HighlightingAssets::from_binary))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_asset(filename: &str, description: &str) {
|
fn clear_asset(filename: &str, description: &str) {
|
||||||
|
@ -450,6 +450,12 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
|
|||||||
.hidden(true)
|
.hidden(true)
|
||||||
.help("Do not use the configuration file"),
|
.help("Do not use the configuration file"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("no-custom-assets")
|
||||||
|
.long("no-custom-assets")
|
||||||
|
.hidden(true)
|
||||||
|
.help("Do not load custom assets"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("config-file")
|
Arg::with_name("config-file")
|
||||||
.long("config-file")
|
.long("config-file")
|
||||||
|
@ -80,7 +80,7 @@ fn get_syntax_mapping_to_paths<'a>(
|
|||||||
pub fn get_languages(config: &Config) -> Result<String> {
|
pub fn get_languages(config: &Config) -> Result<String> {
|
||||||
let mut result: String = String::new();
|
let mut result: String = String::new();
|
||||||
|
|
||||||
let assets = assets_from_cache_or_binary()?;
|
let assets = assets_from_cache_or_binary(config.use_custom_assets)?;
|
||||||
let mut languages = assets
|
let mut languages = assets
|
||||||
.get_syntaxes()?
|
.get_syntaxes()?
|
||||||
.iter()
|
.iter()
|
||||||
@ -178,7 +178,7 @@ fn theme_preview_file<'a>() -> Input<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_themes(cfg: &Config) -> Result<()> {
|
pub fn list_themes(cfg: &Config) -> Result<()> {
|
||||||
let assets = assets_from_cache_or_binary()?;
|
let assets = assets_from_cache_or_binary(cfg.use_custom_assets)?;
|
||||||
let mut config = cfg.clone();
|
let mut config = cfg.clone();
|
||||||
let mut style = HashSet::new();
|
let mut style = HashSet::new();
|
||||||
style.insert(StyleComponent::Plain);
|
style.insert(StyleComponent::Plain);
|
||||||
@ -219,7 +219,7 @@ pub fn list_themes(cfg: &Config) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_controller(inputs: Vec<Input>, config: &Config) -> Result<bool> {
|
fn run_controller(inputs: Vec<Input>, config: &Config) -> Result<bool> {
|
||||||
let assets = assets_from_cache_or_binary()?;
|
let assets = assets_from_cache_or_binary(config.use_custom_assets)?;
|
||||||
let controller = Controller::new(&config, &assets);
|
let controller = Controller::new(&config, &assets);
|
||||||
controller.run(inputs)
|
controller.run(inputs)
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,10 @@ pub struct Config<'a> {
|
|||||||
|
|
||||||
/// Ranges of lines which should be highlighted with a special background color
|
/// Ranges of lines which should be highlighted with a special background color
|
||||||
pub highlighted_lines: HighlightedLineRanges,
|
pub highlighted_lines: HighlightedLineRanges,
|
||||||
|
|
||||||
|
/// Whether or not to allow custom assets. If this is false or if custom assets (a.k.a.
|
||||||
|
/// cached assets) are not available, assets from the binary will be used instead.
|
||||||
|
pub use_custom_assets: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "application", feature = "paging"))]
|
#[cfg(all(feature = "application", feature = "paging"))]
|
||||||
|
@ -795,6 +795,17 @@ fn does_not_print_unwanted_file_named_cache() {
|
|||||||
bat_with_config().arg("cach").assert().failure();
|
bat_with_config().arg("cach").assert().failure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn accepts_no_custom_assets_arg() {
|
||||||
|
// Just make sure --no-custom-assets is considered a valid arg
|
||||||
|
// Don't bother to actually verify that it works
|
||||||
|
bat()
|
||||||
|
.arg("--no-custom-assets")
|
||||||
|
.arg("test.txt")
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unicode_wrap() {
|
fn unicode_wrap() {
|
||||||
bat_with_config()
|
bat_with_config()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user