mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-13 22:28:26 +00:00
[breaking] Remove special handling for theme previews
This commit is contained in:
parent
2f823d59b0
commit
0319149b4d
@ -51,6 +51,9 @@
|
||||
- `PrettyPrinter::vcs_modification_markers` has been marked deprecated when building without the `git` feature, see #997 and #1020 (@eth-p, @sharkdp)
|
||||
- Add APIs to provide `Input` descriptions with `InputDescription` (@eth-p)
|
||||
- Add function to directly provide `Input`s to `PrettyPrinter` (@eth-p)
|
||||
- <font color="red">`Input::theme_preview_file` is no longer available.</font> (@eth-p)
|
||||
|
||||
Changes colored <font color="red">red</font> are breaking changes.
|
||||
|
||||
## Packaging
|
||||
|
||||
|
@ -193,11 +193,7 @@ impl HighlightingAssets {
|
||||
input: &mut OpenedInput,
|
||||
mapping: &SyntaxMapping,
|
||||
) -> Result<&SyntaxReference> {
|
||||
if input.kind.is_theme_preview_file() {
|
||||
self.syntax_set
|
||||
.find_syntax_by_name("Rust")
|
||||
.ok_or_else(|| ErrorKind::UnknownSyntax("Rust".to_owned()).into())
|
||||
} else if let Some(language) = language {
|
||||
if let Some(language) = language {
|
||||
self.syntax_set
|
||||
.find_syntax_by_token(language)
|
||||
.ok_or_else(|| ErrorKind::UnknownSyntax(language.to_owned()).into())
|
||||
|
@ -10,7 +10,7 @@ mod directories;
|
||||
use std::collections::HashSet;
|
||||
use std::ffi::OsStr;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::io::{BufReader, Write};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
@ -25,6 +25,7 @@ use assets::{assets_from_cache_or_binary, cache_dir, clear_assets, config_dir};
|
||||
use clap::crate_version;
|
||||
use directories::PROJECT_DIRS;
|
||||
|
||||
use bat::input::InputDescription;
|
||||
use bat::{
|
||||
assets::HighlightingAssets,
|
||||
config::Config,
|
||||
@ -34,6 +35,8 @@ use bat::{
|
||||
style::{StyleComponent, StyleComponents},
|
||||
};
|
||||
|
||||
const THEME_PREVIEW_DATA: &[u8] = include_bytes!("../../../assets/theme_preview.rs");
|
||||
|
||||
fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
|
||||
if matches.is_present("build") {
|
||||
let source_dir = matches
|
||||
@ -118,6 +121,12 @@ pub fn list_languages(config: &Config) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn theme_preview_file<'a>() -> Input<'a> {
|
||||
Input::from_reader(Box::new(BufReader::new(THEME_PREVIEW_DATA)))
|
||||
.with_name(Some("theme.rs".as_ref()))
|
||||
.with_description(Some(InputDescription::new("")))
|
||||
}
|
||||
|
||||
pub fn list_themes(cfg: &Config) -> Result<()> {
|
||||
let assets = assets_from_cache_or_binary()?;
|
||||
let mut config = cfg.clone();
|
||||
@ -137,7 +146,7 @@ pub fn list_themes(cfg: &Config) -> Result<()> {
|
||||
)?;
|
||||
config.theme = theme.to_string();
|
||||
Controller::new(&config, &assets)
|
||||
.run(vec![Input::theme_preview_file()])
|
||||
.run(vec![theme_preview_file()])
|
||||
.ok();
|
||||
writeln!(stdout)?;
|
||||
}
|
||||
|
28
src/input.rs
28
src/input.rs
@ -6,8 +6,6 @@ use content_inspector::{self, ContentType};
|
||||
|
||||
use crate::error::*;
|
||||
|
||||
const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs");
|
||||
|
||||
/// A description of an Input source.
|
||||
/// This tells bat how to refer to the input.
|
||||
#[derive(Clone)]
|
||||
@ -62,7 +60,6 @@ impl InputDescription {
|
||||
pub(crate) enum InputKind<'a> {
|
||||
OrdinaryFile(OsString),
|
||||
StdIn,
|
||||
ThemePreviewFile,
|
||||
CustomReader(Box<dyn Read + 'a>),
|
||||
}
|
||||
|
||||
@ -73,7 +70,6 @@ impl<'a> InputKind<'a> {
|
||||
InputDescription::new(path.to_string_lossy()).with_kind(Some("File"))
|
||||
}
|
||||
InputKind::StdIn => InputDescription::new("STDIN"),
|
||||
InputKind::ThemePreviewFile => InputDescription::new(""),
|
||||
InputKind::CustomReader(_) => InputDescription::new("READER"),
|
||||
}
|
||||
}
|
||||
@ -93,19 +89,9 @@ pub struct Input<'a> {
|
||||
pub(crate) enum OpenedInputKind {
|
||||
OrdinaryFile(OsString),
|
||||
StdIn,
|
||||
ThemePreviewFile,
|
||||
CustomReader,
|
||||
}
|
||||
|
||||
impl OpenedInputKind {
|
||||
pub(crate) fn is_theme_preview_file(&self) -> bool {
|
||||
match self {
|
||||
OpenedInputKind::ThemePreviewFile => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct OpenedInput<'a> {
|
||||
pub(crate) kind: OpenedInputKind,
|
||||
pub(crate) metadata: InputMetadata,
|
||||
@ -130,14 +116,6 @@ impl<'a> Input<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn theme_preview_file() -> Self {
|
||||
Input {
|
||||
kind: InputKind::ThemePreviewFile,
|
||||
metadata: InputMetadata::default(),
|
||||
description: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_reader(reader: Box<dyn Read + 'a>) -> Self {
|
||||
Input {
|
||||
kind: InputKind::CustomReader(reader),
|
||||
@ -196,12 +174,6 @@ impl<'a> Input<'a> {
|
||||
InputReader::new(BufReader::new(file))
|
||||
},
|
||||
}),
|
||||
InputKind::ThemePreviewFile => Ok(OpenedInput {
|
||||
kind: OpenedInputKind::ThemePreviewFile,
|
||||
description,
|
||||
metadata: self.metadata,
|
||||
reader: InputReader::new(THEME_PREVIEW_FILE),
|
||||
}),
|
||||
InputKind::CustomReader(reader) => Ok(OpenedInput {
|
||||
description,
|
||||
kind: OpenedInputKind::CustomReader,
|
||||
|
Loading…
x
Reference in New Issue
Block a user