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