mirror of
https://github.com/sharkdp/bat
synced 2024-11-16 00:47:58 +00:00
Add simple line-wrapping for file extensions.
This commit is contained in:
parent
ac32dd17c9
commit
4c60ab12cc
1 changed files with 23 additions and 2 deletions
25
src/main.rs
25
src/main.rs
|
@ -572,9 +572,30 @@ fn run() -> Result<()> {
|
|||
.max()
|
||||
.unwrap_or(32); // Fallback width if they have no language definitions.
|
||||
|
||||
let separator = " | ";
|
||||
for lang in languages {
|
||||
print!("{:width$} | ", lang.name, width = longest);
|
||||
println!("{}", lang.file_extensions.join(", "));
|
||||
print!("{:width$}{}", lang.name, separator, width = longest);
|
||||
|
||||
// Line-wrapping for the possible file extension overflow.
|
||||
let desired_width = 48;
|
||||
// Number of characters on this line so far, wrap before `desired_width`
|
||||
let mut num_chars = 0;
|
||||
|
||||
let mut extension = lang.file_extensions.iter().peekable();
|
||||
while let Some(word) = extension.next() {
|
||||
// If we can't fit this word in, then create a line break and align it in.
|
||||
if word.len() + num_chars >= desired_width {
|
||||
num_chars = 0;
|
||||
print!("\n{:width$}{}", "", separator, width = longest);
|
||||
}
|
||||
|
||||
num_chars += word.len();
|
||||
print!("{}", word);
|
||||
if extension.peek().is_some() {
|
||||
print!(", ");
|
||||
}
|
||||
}
|
||||
println!();
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
|
|
Loading…
Reference in a new issue