on master help sign in
[breaking] Remove special handling for theme previews
commit0319149b4d05f1457658f842710b92f7b91b635c authorEthan P <eth-p+git@hidden.email> dateFri 15 May 2020, 16:19 (6 years ago) parent2f823d5
4 files changed+15−35
CHANGELOG.md+3 src/assets.rs+1−5 src/bin/bat/main.rs+11−2 src/input.rs−28
CHANGELOG.md+3
@@ -51,6 +51,9 @@
5151- `PrettyPrinter::vcs_modification_markers` has been marked deprecated when building without the `git` feature, see #997 and #1020 (@eth-p, @sharkdp)
5252- Add APIs to provide `Input` descriptions with `InputDescription` (@eth-p)
5353- Add function to directly provide `Input`s to `PrettyPrinter` (@eth-p)
54+- <font color="red">`Input::theme_preview_file` is no longer available.</font> (@eth-p)
55+
56+Changes colored <font color="red">red</font> are breaking changes.
5457
5558## Packaging
5659
src/assets.rs+1−5
@@ -193,11 +193,7 @@ impl HighlightingAssets {
193193 input: &mut OpenedInput,
194194 mapping: &SyntaxMapping,
195195 ) -> Result<&SyntaxReference> {
196− if input.kind.is_theme_preview_file() {
197− self.syntax_set
198− .find_syntax_by_name("Rust")
199− .ok_or_else(|| ErrorKind::UnknownSyntax("Rust".to_owned()).into())
200− } else if let Some(language) = language {
196+ if let Some(language) = language {
201197 self.syntax_set
202198 .find_syntax_by_token(language)
203199 .ok_or_else(|| ErrorKind::UnknownSyntax(language.to_owned()).into())
src/bin/bat/main.rs+11−2
@@ -10,7 +10,7 @@ mod directories;
1010use std::collections::HashSet;
1111use std::ffi::OsStr;
1212use std::io;
13−use std::io::Write;
13+use std::io::{BufReader, Write};
1414use std::path::Path;
1515use std::process;
1616
@@ -25,6 +25,7 @@ use assets::{assets_from_cache_or_binary, cache_dir, clear_assets, config_dir};
2525use clap::crate_version;
2626use directories::PROJECT_DIRS;
2727
28+use bat::input::InputDescription;
2829use bat::{
2930 assets::HighlightingAssets,
3031 config::Config,
@@ -34,6 +35,8 @@ use bat::{
3435 style::{StyleComponent, StyleComponents},
3536};
3637
38+const THEME_PREVIEW_DATA: &[u8] = include_bytes!("../../../assets/theme_preview.rs");
39+
3740fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
3841 if matches.is_present("build") {
3942 let source_dir = matches
@@ -118,6 +121,12 @@ pub fn list_languages(config: &Config) -> Result<()> {
118121 Ok(())
119122}
120123
124+fn theme_preview_file<'a>() -> Input<'a> {
125+ Input::from_reader(Box::new(BufReader::new(THEME_PREVIEW_DATA)))
126+ .with_name(Some("theme.rs".as_ref()))
127+ .with_description(Some(InputDescription::new("")))
128+}
129+
121130pub fn list_themes(cfg: &Config) -> Result<()> {
122131 let assets = assets_from_cache_or_binary()?;
123132 let mut config = cfg.clone();
@@ -137,7 +146,7 @@ pub fn list_themes(cfg: &Config) -> Result<()> {
137146 )?;
138147 config.theme = theme.to_string();
139148 Controller::new(&config, &assets)
140− .run(vec![Input::theme_preview_file()])
149+ .run(vec![theme_preview_file()])
141150 .ok();
142151 writeln!(stdout)?;
143152 }
src/input.rs−28
@@ -6,8 +6,6 @@ use content_inspector::{self, ContentType};
66
77use crate::error::*;
88
9−const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs");
10−
119/// A description of an Input source.
1210/// This tells bat how to refer to the input.
1311#[derive(Clone)]
@@ -62,7 +60,6 @@ impl InputDescription {
6260pub(crate) enum InputKind<'a> {
6361 OrdinaryFile(OsString),
6462 StdIn,
65− ThemePreviewFile,
6663 CustomReader(Box<dyn Read + 'a>),
6764}
6865
@@ -73,7 +70,6 @@ impl<'a> InputKind<'a> {
7370 InputDescription::new(path.to_string_lossy()).with_kind(Some("File"))
7471 }
7572 InputKind::StdIn => InputDescription::new("STDIN"),
76− InputKind::ThemePreviewFile => InputDescription::new(""),
7773 InputKind::CustomReader(_) => InputDescription::new("READER"),
7874 }
7975 }
@@ -93,19 +89,9 @@ pub struct Input<'a> {
9389pub(crate) enum OpenedInputKind {
9490 OrdinaryFile(OsString),
9591 StdIn,
96− ThemePreviewFile,
9792 CustomReader,
9893}
9994
100−impl OpenedInputKind {
101− pub(crate) fn is_theme_preview_file(&self) -> bool {
102− match self {
103− OpenedInputKind::ThemePreviewFile => true,
104− _ => false,
105− }
106− }
107−}
108−
10995pub(crate) struct OpenedInput<'a> {
11096 pub(crate) kind: OpenedInputKind,
11197 pub(crate) metadata: InputMetadata,
@@ -130,14 +116,6 @@ impl<'a> Input<'a> {
130116 }
131117 }
132118
133− pub fn theme_preview_file() -> Self {
134− Input {
135− kind: InputKind::ThemePreviewFile,
136− metadata: InputMetadata::default(),
137− description: None,
138− }
139− }
140−
141119 pub fn from_reader(reader: Box<dyn Read + 'a>) -> Self {
142120 Input {
143121 kind: InputKind::CustomReader(reader),
@@ -196,12 +174,6 @@ impl<'a> Input<'a> {
196174 InputReader::new(BufReader::new(file))
197175 },
198176 }),
199− InputKind::ThemePreviewFile => Ok(OpenedInput {
200− kind: OpenedInputKind::ThemePreviewFile,
201− description,
202− metadata: self.metadata,
203− reader: InputReader::new(THEME_PREVIEW_FILE),
204− }),
205177 InputKind::CustomReader(reader) => Ok(OpenedInput {
206178 description,
207179 kind: OpenedInputKind::CustomReader,