mirror of
https://github.com/sharkdp/bat
synced 2024-11-16 21:25:56 +00:00
Add simple line-wrapping for file extensions.
This commit is contained in:
parent
ac32dd17c9
commit
4c60ab12cc
25
src/main.rs
25
src/main.rs
@ -572,9 +572,30 @@ fn run() -> Result<()> {
|
|||||||
.max()
|
.max()
|
||||||
.unwrap_or(32); // Fallback width if they have no language definitions.
|
.unwrap_or(32); // Fallback width if they have no language definitions.
|
||||||
|
|
||||||
|
let separator = " | ";
|
||||||
for lang in languages {
|
for lang in languages {
|
||||||
print!("{:width$} | ", lang.name, width = longest);
|
print!("{:width$}{}", lang.name, separator, width = longest);
|
||||||
println!("{}", lang.file_extensions.join(", "));
|
|
||||||
|
// 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(());
|
return Ok(());
|
||||||
|
Loading…
Reference in New Issue
Block a user