diff --git a/src/main.rs b/src/main.rs index a790ce679..e1a8429f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -346,7 +346,7 @@ fn run_default(opt: &mut Opt, config: &Config) -> Result<(), Error> { lap(&mut time, "Info: View::new"); } - view.filter(opt, config); + view.filter(opt, config, 1); if opt.debug { lap(&mut time, "Info: view.filter"); diff --git a/src/view.rs b/src/view.rs index 72e854916..62d10e287 100644 --- a/src/view.rs +++ b/src/view.rs @@ -210,7 +210,7 @@ impl View { }) } - pub fn filter(&mut self, opt: &Opt, config: &Config) { + pub fn filter(&mut self, opt: &Opt, config: &Config, header_lines: usize) { let mut cols_nonnumeric = Vec::new(); let mut cols_numeric = Vec::new(); for c in &self.columns { @@ -321,7 +321,8 @@ impl View { visible_pids.push(*pid); } - if opt.watch_mode && visible_pids.len() >= self.term_info.height - 5 { + let reserved_rows = 4 + header_lines; + if opt.watch_mode && visible_pids.len() >= self.term_info.height - reserved_rows { break; } } diff --git a/src/watcher.rs b/src/watcher.rs index d3b57f890..7b57cc22b 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -67,7 +67,7 @@ impl Watcher { }); } - fn display_header(term_info: &TermInfo, opt: &Opt, interval: u64) -> Result<(), Error> { + fn display_header(term_info: &TermInfo, opt: &Opt, interval: u64) -> Result { let header = if opt.tree { format!( " Interval: {}ms, Last Updated: {} ( Quit: q or Ctrl-C )", @@ -81,13 +81,14 @@ impl Watcher { Local::now().format("%Y/%m/%d %H:%M:%S"), ) }; + let result = header.len(); term_info.write_line(&format!( "{}", console::style(header).white().bold().underlined() ))?; term_info.write_line("")?; - Ok(()) + Ok(result.div_ceil(term_info.width)) } pub fn start(opt: &mut Opt, config: &Config, interval: u64) -> Result<(), Error> { @@ -116,18 +117,18 @@ impl Watcher { view.sort_info.order = sort_order.clone().unwrap_or(view.sort_info.order); } - view.filter(opt, config); - view.adjust(config, &min_widths); - for (i, c) in view.columns.iter().enumerate() { - min_widths.insert(i, c.column.get_width()); - } - let resized = prev_term_width != view.term_info.width || prev_term_height != view.term_info.height; if resized { term_info.clear_screen()?; } - Watcher::display_header(&view.term_info, opt, interval)?; + let header_lines = Watcher::display_header(&view.term_info, opt, interval)?; + + view.filter(opt, config, header_lines); + view.adjust(config, &min_widths); + for (i, c) in view.columns.iter().enumerate() { + min_widths.insert(i, c.column.get_width()); + } view.display(opt, config, &theme)?;