on master help sign in
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.

commit7dc7133b3c82ab7034b16020a028f8b3bdab697e authorConnor Kuehl <cipkuehl@gmail.com> dateTue 8 May 2018, 12:20 (9 years ago) parente5e4771
2 files changed+5−6
src/main.rs+4−3 src/printer.rs+1−3
src/main.rs+4−3
@@ -582,14 +582,15 @@ fn run() -> Result<()> {
582582 print!("{:width$}{}", lang.name, separator, width = longest);
583583
584584 // Line-wrapping for the possible file extension overflow.
585− let desired_width = options.term_width - longest;
585+ let desired_width = options.term_width - longest - separator.len();
586586 // Number of characters on this line so far, wrap before `desired_width`
587587 let mut num_chars = 0;
588588
589+ let comma_separator = ", ";
589590 let mut extension = lang.file_extensions.iter().peekable();
590591 while let Some(word) = extension.next() {
591592 // If we can't fit this word in, then create a line break and align it in.
592− if word.len() + num_chars >= desired_width {
593+ if word.len() + num_chars + comma_separator.len() >= desired_width {
593594 num_chars = 0;
594595 print!("\n{:width$}{}", "", separator, width = longest);
595596 }
@@ -597,7 +598,7 @@ fn run() -> Result<()> {
597598 num_chars += word.len();
598599 print!("{}", word);
599600 if extension.peek().is_some() {
600− print!(", ");
601+ print!("{}", comma_separator);
601602 }
602603 }
603604 println!();
src/printer.rs+1−3
@@ -17,8 +17,6 @@ pub struct Printer<'a> {
1717
1818impl<'a> Printer<'a> {
1919 pub fn new(handle: &'a mut Write, options: &'a Options) -> Self {
20− let term_width = options.term_width;
21−
2220 let colors = if options.colored_output {
2321 Colors::colored()
2422 } else {
@@ -28,7 +26,7 @@ impl<'a> Printer<'a> {
2826 Printer {
2927 handle,
3028 colors,
31− term_width,
29+ term_width: options.term_width,
3230 options,
3331 line_changes: None,
3432 }