Add revisions for line-wrapping and terminal width.

* Adds separator.length() to calculation for desired width.
* Replaces use of term_width with options.term_width.
* Adds the comma and space separator to calculation for line-wrapping.
pull/86/head
Connor Kuehl 6 years ago committed by David Peter
parent e5e47716b0
commit 7dc7133b3c

@ -582,14 +582,15 @@ fn run() -> Result<()> {
print!("{:width$}{}", lang.name, separator, width = longest);
// Line-wrapping for the possible file extension overflow.
let desired_width = options.term_width - longest;
let desired_width = options.term_width - longest - separator.len();
// Number of characters on this line so far, wrap before `desired_width`
let mut num_chars = 0;
let comma_separator = ", ";
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 {
if word.len() + num_chars + comma_separator.len() >= desired_width {
num_chars = 0;
print!("\n{:width$}{}", "", separator, width = longest);
}
@ -597,7 +598,7 @@ fn run() -> Result<()> {
num_chars += word.len();
print!("{}", word);
if extension.peek().is_some() {
print!(", ");
print!("{}", comma_separator);
}
}
println!();

@ -17,8 +17,6 @@ pub struct Printer<'a> {
impl<'a> Printer<'a> {
pub fn new(handle: &'a mut Write, options: &'a Options) -> Self {
let term_width = options.term_width;
let colors = if options.colored_output {
Colors::colored()
} else {
@ -28,7 +26,7 @@ impl<'a> Printer<'a> {
Printer {
handle,
colors,
term_width,
term_width: options.term_width,
options,
line_changes: None,
}

Loading…
Cancel
Save