summaryrefslogtreecommitdiffstats
path: root/src/subcommands
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 /src/subcommands
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
Diffstat (limited to 'src/subcommands')
-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
3 files changed, 15 insertions, 25 deletions
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)
{