Skip to content

Commit

Permalink
Merge pull request #695 from v1rtualr3ality/line-wrapping
Browse files Browse the repository at this point in the history
Line wrapping
  • Loading branch information
dalance authored Oct 21, 2024
2 parents 196fe1a + 4f18abb commit 7df5bbc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 3 additions & 2 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize, Error> {
let header = if opt.tree {
format!(
" Interval: {}ms, Last Updated: {} ( Quit: q or Ctrl-C )",
Expand All @@ -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> {
Expand Down Expand Up @@ -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)?;

Expand Down

0 comments on commit 7df5bbc

Please sign in to comment.