mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-23 14:08:58 +01:00
make bat -L use pager
This commit is contained in:
parent
cc7b89faf8
commit
cffacad306
@ -2,6 +2,7 @@
|
||||
|
||||
|
||||
## Features
|
||||
- make `bat -L` use built-in pager
|
||||
|
||||
## Bugfixes
|
||||
|
||||
|
@ -78,7 +78,9 @@ fn get_syntax_mapping_to_paths<'a>(
|
||||
map
|
||||
}
|
||||
|
||||
pub fn list_languages(config: &Config) -> Result<()> {
|
||||
pub fn get_languages(config: &Config) -> Result<String> {
|
||||
let mut result: String = String::new();
|
||||
|
||||
let assets = assets_from_cache_or_binary()?;
|
||||
let mut languages = assets
|
||||
.syntaxes()
|
||||
@ -119,12 +121,9 @@ pub fn list_languages(config: &Config) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
let stdout = io::stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
|
||||
if config.loop_through {
|
||||
for lang in languages {
|
||||
writeln!(stdout, "{}:{}", lang.name, lang.file_extensions.join(","))?;
|
||||
result += &format!("{}:{}\n", lang.name, lang.file_extensions.join(","));
|
||||
}
|
||||
} else {
|
||||
let longest = languages
|
||||
@ -145,7 +144,7 @@ pub fn list_languages(config: &Config) -> Result<()> {
|
||||
};
|
||||
|
||||
for lang in languages {
|
||||
write!(stdout, "{:width$}{}", lang.name, separator, width = longest)?;
|
||||
result += &format!("{:width$}{}", lang.name, separator, width = longest);
|
||||
|
||||
// Number of characters on this line so far, wrap before `desired_width`
|
||||
let mut num_chars = 0;
|
||||
@ -156,20 +155,20 @@ pub fn list_languages(config: &Config) -> Result<()> {
|
||||
let new_chars = word.len() + comma_separator.len();
|
||||
if num_chars + new_chars >= desired_width {
|
||||
num_chars = 0;
|
||||
write!(stdout, "\n{:width$}{}", "", separator, width = longest)?;
|
||||
result += &format!("\n{:width$}{}", "", separator, width = longest);
|
||||
}
|
||||
|
||||
num_chars += new_chars;
|
||||
write!(stdout, "{}", style.paint(&word[..]))?;
|
||||
result += &format!("{}", style.paint(&word[..]));
|
||||
if extension.peek().is_some() {
|
||||
write!(stdout, "{}", comma_separator)?;
|
||||
result += &format!("{}", comma_separator);
|
||||
}
|
||||
}
|
||||
writeln!(stdout)?;
|
||||
result += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn theme_preview_file<'a>() -> Input<'a> {
|
||||
@ -248,8 +247,10 @@ fn run() -> Result<bool> {
|
||||
let config = app.config(&inputs)?;
|
||||
|
||||
if app.matches.is_present("list-languages") {
|
||||
list_languages(&config)?;
|
||||
Ok(true)
|
||||
let languages: String = get_languages(&config)?;
|
||||
let inputs: Vec<Input> = vec!(Input::from_reader(Box::new(languages.as_bytes())));
|
||||
let config = app.config(&inputs)?;
|
||||
run_controller(inputs, &config)
|
||||
} else if app.matches.is_present("list-themes") {
|
||||
list_themes(&config)?;
|
||||
Ok(true)
|
||||
|
Loading…
Reference in New Issue
Block a user