mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-22 13:38:48 +01:00
parent
f711fb5006
commit
22c8978fca
13
src/app.rs
13
src/app.rs
@ -85,6 +85,17 @@ impl App {
|
||||
.long("list-languages")
|
||||
.help("Displays supported languages"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("theme")
|
||||
.long("theme")
|
||||
.takes_value(true)
|
||||
.help("Set the theme for highlighting"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("list-themes")
|
||||
.long("list-themes")
|
||||
.help("Displays supported themes"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("cache")
|
||||
.about("Modify the syntax-definition and theme cache")
|
||||
@ -143,6 +154,7 @@ impl App {
|
||||
},
|
||||
term_width: Term::stdout().size().1 as usize,
|
||||
files,
|
||||
theme: self.matches.value_of("theme"),
|
||||
})
|
||||
}
|
||||
|
||||
@ -185,6 +197,7 @@ pub struct Config<'a> {
|
||||
pub paging: bool,
|
||||
pub term_width: usize,
|
||||
pub files: Vec<Option<&'a str>>,
|
||||
pub theme: Option<&'a str>,
|
||||
}
|
||||
|
||||
fn is_truecolor_terminal() -> bool {
|
||||
|
@ -126,11 +126,13 @@ impl HighlightingAssets {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn default_theme(&self) -> Result<&Theme> {
|
||||
Ok(self.theme_set
|
||||
.themes
|
||||
.get("Default")
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Could not find 'Default' theme"))?)
|
||||
pub fn get_theme(&self, theme: &str) -> Result<&Theme> {
|
||||
Ok(self.theme_set.themes.get(theme).ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Could not find '{}' theme", theme),
|
||||
)
|
||||
})?)
|
||||
}
|
||||
}
|
||||
|
||||
|
10
src/main.rs
10
src/main.rs
@ -223,7 +223,7 @@ fn run() -> Result<()> {
|
||||
let config = app.config()?;
|
||||
|
||||
let assets = HighlightingAssets::new();
|
||||
let theme = assets.default_theme()?;
|
||||
let theme = assets.get_theme(config.theme.unwrap_or("Default"))?;
|
||||
|
||||
if app.matches.is_present("list-languages") {
|
||||
let languages = assets.syntax_set.syntaxes();
|
||||
@ -269,6 +269,14 @@ fn run() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if app.matches.is_present("list-themes") {
|
||||
let themes = &assets.theme_set.themes;
|
||||
for (theme, _) in themes.iter() {
|
||||
println!("{}", theme);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut output_type = get_output_type(config.paging);
|
||||
let handle = output_type.handle()?;
|
||||
let mut printer = Printer::new(handle, &config);
|
||||
|
Loading…
Reference in New Issue
Block a user