diff options
author | Nakul Chaudhari <chaudhari@navvis.com> | 2018-05-03 22:21:45 +0200 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2018-05-03 22:49:37 +0200 |
commit | 9dca3126b330c654c3958f6d9af1b53cf6ef99f2 (patch) | |
tree | 056092db7106169ca9f0a9a10e0891ca936145ae | |
parent | 7df9a5fe82ddae93190530709c888bfe2367bc75 (diff) |
Hide everything but content for plain option style
fix #5
-rw-r--r-- | src/main.rs | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/src/main.rs b/src/main.rs index ae70cf2c..2cf24ea6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,17 +118,24 @@ fn print_file<P: AsRef<Path>>( let (_, term_width) = term.size(); let term_width = term_width as usize; - print_horizontal_line(&mut handle, '┬', term_width)?; - - writeln!( - handle, - "{}{} File {}", - " ".repeat(PANEL_WIDTH), - Fixed(GRID_COLOR).paint("│"), - White.bold().paint(filename.as_ref().to_string_lossy()) - )?; + // Show file name and bars for all but plain style + match options.style { + OptionsStyle::LineNumbers | OptionsStyle::Full => { + print_horizontal_line(&mut handle, '┬', term_width)?; + + writeln!( + handle, + "{}{} File {}", + " ".repeat(PANEL_WIDTH), + Fixed(GRID_COLOR).paint("│"), + White.bold().paint(filename.as_ref().to_string_lossy()) + )?; + + print_horizontal_line(&mut handle, '┼', term_width)?; + } + OptionsStyle::Plain => {} + }; - print_horizontal_line(&mut handle, '┼', term_width)?; for (idx, maybe_line) in reader.lines().enumerate() { let line_nr = idx + 1; @@ -147,23 +154,34 @@ fn print_file<P: AsRef<Path>>( Style::default().paint(" ") }; - writeln!( - handle, - "{} {} {} {}", - Fixed(244).paint(match options.style { - OptionsStyle::Plain => " ".to_owned(), - _ => format!("{:4}", line_nr), - }), - match options.style { - OptionsStyle::Full => line_change, - _ => Style::default().paint(" "), - }, - Fixed(GRID_COLOR).paint("│"), - as_terminal_escaped(®ions, options.true_color) - )?; + + match options.style { + // Show only content for plain style + OptionsStyle::Plain => writeln!( + handle, + "{}", as_terminal_escaped(®ions, options.true_color))?, + _ => + writeln!( + handle, + "{} {} {} {}", + Fixed(244).paint(format!("{:4}", line_nr)), + // Show git modificiation markers only for full style + match options.style { + OptionsStyle::Full => line_change, + _ => Style::default().paint(" "), + }, + Fixed(GRID_COLOR).paint("│"), + as_terminal_escaped(®ions, options.true_color) + )? + } } - print_horizontal_line(&mut handle, '┴', term_width)?; + // Show bars for all but plain style + match options.style { + OptionsStyle::LineNumbers | OptionsStyle::Full => + print_horizontal_line(&mut handle, '┴', term_width)?, + OptionsStyle::Plain => {} + }; Ok(()) } |