diff --git a/Readme.org b/Readme.org index 3c4a045..7325aec 100644 --- a/Readme.org +++ b/Readme.org @@ -361,3 +361,7 @@ EvenMoreData: values size is bigger than what is left of that data chunk #+end_src However, it is also possible to use the ~--nojump~ argument instead. This makes mview print to stdout like it does to files. + +* Printing chunks 'on top of each other' +Normally mview resets the cursor position for every chunk. It therefore print chunks 'on top of each other', so to speak. This behavior is hard to implement because different terminal emulators have different features and react differently to the same control messages. +Therefore it can happen, that mview deletes to many or to few lines, or it does not delete the lines at all. For this mview can also clear the terminal instead with the ~--clear~ flag. With this flag an output always starts at top of the terminal and the terminal is cleared before a chunk is printed. diff --git a/src/args.rs b/src/args.rs index 024a294..b2d3837 100644 --- a/src/args.rs +++ b/src/args.rs @@ -18,6 +18,7 @@ pub struct Args { pub print_statistics: bool, pub print_bitpos: bool, pub cursor_jump: bool, + pub clear: bool, pub filter_newlines: bool, } @@ -140,6 +141,12 @@ impl Args { .long("--nojump") .takes_value(false) .help("Print to stdout like printing to a file with option --outfile"), + .arg( + Arg::with_name("clear") + .long("--clear") + .takes_value(false) + .help("Clear the terminal before each chunk is printed") + .long_help("Clear the terminal before each chunk is printed. Counting lines then deleting them can be tricky and if it works depends on the terminal. Clearing the terminal almost always works."), ) .arg( Arg::with_name("filter newlines") @@ -180,6 +187,7 @@ impl Args { let print_statistics = matches.is_present("print statistics"); let print_bitpos = matches.is_present("print bitposition"); let cursor_jump = !matches.is_present("no cursor jumping"); + let clear = matches.is_present("clear"); let filter_newlines = matches.is_present("filter newlines"); Self { infile, @@ -199,6 +207,7 @@ impl Args { print_statistics, print_bitpos, cursor_jump, + clear, filter_newlines, } } diff --git a/src/lib.rs b/src/lib.rs index 307103d..b20aee1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -532,6 +532,7 @@ Field14(uarb4):uarb:4"; // should sum up to 135 bits print_statistics: false, print_bitpos: false, cursor_jump: false, + clear: false, filter_newlines: false, }; let stats = Stats { @@ -569,6 +570,7 @@ Field14(uarb4):uarb:4"; // should sum up to 135 bits print_statistics: false, print_bitpos: false, cursor_jump: false, + clear: false, filter_newlines: false, }; let stats = Stats { @@ -606,6 +608,7 @@ Field14(uarb4):uarb:4"; // should sum up to 135 bits print_statistics: false, print_bitpos: false, cursor_jump: false, + clear: false, filter_newlines: false, }; let stats = Stats { @@ -642,6 +645,7 @@ Field14(uarb4):uarb:4"; // should sum up to 135 bits print_statistics: false, print_bitpos: true, cursor_jump: false, + clear: false, filter_newlines: false, }; let stats = Stats { @@ -678,6 +682,7 @@ Field14(uarb4):uarb:4"; // should sum up to 135 bits print_statistics: true, print_bitpos: false, cursor_jump: false, + clear: false, filter_newlines: false, }; let stats = Stats { @@ -714,6 +719,7 @@ Field14(uarb4):uarb:4"; // should sum up to 135 bits print_statistics: false, print_bitpos: false, cursor_jump: false, + clear: false, filter_newlines: false, }; let stats = Stats { @@ -836,6 +842,7 @@ Field14(uarb4):uarb:4"; // should sum up to 135 bits print_statistics: false, print_bitpos: false, cursor_jump: false, + clear: false, filter_newlines: false, }; let pcapheader: PcapMsgHeader = Default::default(); diff --git a/src/write.rs b/src/write.rs index 4a1a0d2..4e08077 100644 --- a/src/write.rs +++ b/src/write.rs @@ -11,10 +11,7 @@ use bitvec::{ use core::time; use crossbeam::channel::Receiver; use crossterm::style::{self, Color, Stylize}; -use crossterm::{ - cursor, execute, - terminal::{Clear, ClearType}, -}; +use crossterm::{cursor, execute, terminal}; use std::sync::{Arc, Mutex}; use std::{ fs::File, @@ -98,8 +95,17 @@ this means that some fields in the config will not be considered in the output b stats.chunk_count += 1; // in case we write to stdout, move the cursor back to the start - if is_stdout && !first_run && args.cursor_jump { - move_cursor(args, config_lines.len(), &stats)?; + if is_stdout { + if !first_run && args.cursor_jump && !args.clear { + move_cursor(args, config_lines.len(), &stats)?; + } + if args.clear { + execute!( + io::stdout(), + cursor::MoveTo(0, 0), + terminal::Clear(terminal::ClearType::All) + )?; + } } print_additional( @@ -148,7 +154,7 @@ pub fn move_cursor(args: &Args, n_conf_lines: usize, stats: &Stats) -> Result<() cursor::MoveToColumn(0), // the following is necessary because writing in the terminal with a newline? cursor::MoveDown(1), - Clear(ClearType::FromCursorDown), + terminal::Clear(terminal::ClearType::FromCursorDown), cursor::MoveUp(1), )?; Ok(()) @@ -440,6 +446,7 @@ mod tests { print_statistics: false, print_bitpos: false, cursor_jump: false, + clear: false, filter_newlines: false, } }