mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-31 02:01:05 +00:00
Add syntaxes and themes method
This commit is contained in:
parent
cba9df746e
commit
53a973e9dd
@ -1,5 +1,5 @@
|
|||||||
/// A program that prints its own source code using the bat library
|
/// A program that prints its own source code using the bat library
|
||||||
use bat::{LineRange, PrettyPrinter, WrappingMode, PagingMode};
|
use bat::{LineRange, PagingMode, PrettyPrinter, WrappingMode};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
PrettyPrinter::new()
|
PrettyPrinter::new()
|
||||||
|
18
examples/list_syntaxes_and_themes.rs
Normal file
18
examples/list_syntaxes_and_themes.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/// A simple program that prints its own source code using the bat library
|
||||||
|
use bat::PrettyPrinter;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let printer = PrettyPrinter::new();
|
||||||
|
|
||||||
|
println!("Syntaxes:");
|
||||||
|
for syntax in printer.syntaxes() {
|
||||||
|
println!("- {} ({})", syntax.name, syntax.file_extensions.join(", "));
|
||||||
|
}
|
||||||
|
|
||||||
|
println!();
|
||||||
|
|
||||||
|
println!("Themes:");
|
||||||
|
for theme in printer.themes() {
|
||||||
|
println!("- {}", theme);
|
||||||
|
}
|
||||||
|
}
|
@ -164,8 +164,8 @@ impl HighlightingAssets {
|
|||||||
self.syntax_set.syntaxes()
|
self.syntax_set.syntaxes()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn themes(&self) -> impl Iterator<Item = &String> {
|
pub fn themes(&self) -> impl Iterator<Item = &str> {
|
||||||
self.theme_set.themes.keys()
|
self.theme_set.themes.keys().map(|s| s.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_theme(&self, theme: &str) -> &Theme {
|
pub(crate) fn get_theme(&self, theme: &str) -> &Theme {
|
||||||
|
@ -2,6 +2,7 @@ use std::ffi::OsStr;
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use console::Term;
|
use console::Term;
|
||||||
|
use syntect::parsing::SyntaxReference;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assets::HighlightingAssets,
|
assets::HighlightingAssets,
|
||||||
@ -201,6 +202,14 @@ impl<'a> PrettyPrinter<'a> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn themes(&self) -> impl Iterator<Item = &str> {
|
||||||
|
self.assets.themes()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn syntaxes(&self) -> impl Iterator<Item = &SyntaxReference> {
|
||||||
|
self.assets.syntaxes().iter()
|
||||||
|
}
|
||||||
|
|
||||||
/// Pretty-print all specified inputs. This method will "use" all stored inputs.
|
/// Pretty-print all specified inputs. This method will "use" all stored inputs.
|
||||||
/// If you want to call 'print' multiple times, you have to call the appropriate
|
/// If you want to call 'print' multiple times, you have to call the appropriate
|
||||||
/// input_* methods again.
|
/// input_* methods again.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user