on master help sign in
Hide everything but content for plain option style

fix #5

commit9dca3126b330c654c3958f6d9af1b53cf6ef99f2 authorNakul Chaudhari <chaudhari@navvis.com> dateThu 3 May 2018, 22:21 (9 years ago) parent7df9a5f
1 file changed+43−25
src/main.rs+43−25
src/main.rs+43−25
@@ -118,17 +118,24 @@ fn print_file<P: AsRef<Path>>(
118118 let (_, term_width) = term.size();
119119 let term_width = term_width as usize;
120120
121− print_horizontal_line(&mut handle, '┬', term_width)?;
122−
123− writeln!(
124− handle,
125− "{}{} File {}",
126− " ".repeat(PANEL_WIDTH),
127− Fixed(GRID_COLOR).paint("│"),
128− White.bold().paint(filename.as_ref().to_string_lossy())
129− )?;
121+ // Show file name and bars for all but plain style
122+ match options.style {
123+ OptionsStyle::LineNumbers | OptionsStyle::Full => {
124+ print_horizontal_line(&mut handle, '┬', term_width)?;
125+
126+ writeln!(
127+ handle,
128+ "{}{} File {}",
129+ " ".repeat(PANEL_WIDTH),
130+ Fixed(GRID_COLOR).paint("│"),
131+ White.bold().paint(filename.as_ref().to_string_lossy())
132+ )?;
133+
134+ print_horizontal_line(&mut handle, '┼', term_width)?;
135+ }
136+ OptionsStyle::Plain => {}
137+ };
130138
131− print_horizontal_line(&mut handle, '┼', term_width)?;
132139
133140 for (idx, maybe_line) in reader.lines().enumerate() {
134141 let line_nr = idx + 1;
@@ -147,23 +154,34 @@ fn print_file<P: AsRef<Path>>(
147154 Style::default().paint(" ")
148155 };
149156
150− writeln!(
151− handle,
152− "{} {} {} {}",
153− Fixed(244).paint(match options.style {
154− OptionsStyle::Plain => " ".to_owned(),
155− _ => format!("{:4}", line_nr),
156− }),
157− match options.style {
158− OptionsStyle::Full => line_change,
159− _ => Style::default().paint(" "),
160− },
161− Fixed(GRID_COLOR).paint("│"),
162− as_terminal_escaped(&regions, options.true_color)
163− )?;
157+
158+ match options.style {
159+ // Show only content for plain style
160+ OptionsStyle::Plain => writeln!(
161+ handle,
162+ "{}", as_terminal_escaped(&regions, options.true_color))?,
163+ _ =>
164+ writeln!(
165+ handle,
166+ "{} {} {} {}",
167+ Fixed(244).paint(format!("{:4}", line_nr)),
168+ // Show git modificiation markers only for full style
169+ match options.style {
170+ OptionsStyle::Full => line_change,
171+ _ => Style::default().paint(" "),
172+ },
173+ Fixed(GRID_COLOR).paint("│"),
174+ as_terminal_escaped(&regions, options.true_color)
175+ )?
176+ }
164177 }
165178
166− print_horizontal_line(&mut handle, '┴', term_width)?;
179+ // Show bars for all but plain style
180+ match options.style {
181+ OptionsStyle::LineNumbers | OptionsStyle::Full =>
182+ print_horizontal_line(&mut handle, '┴', term_width)?,
183+ OptionsStyle::Plain => {}
184+ };
167185
168186 Ok(())
169187}