From 0c6d777fe672f5ae1741f568f8a77a9e6d528b1e Mon Sep 17 00:00:00 2001 From: dalance Date: Fri, 26 Feb 2016 14:48:26 +0900 Subject: [PATCH] add --row option --- src/ambr.rs | 3 +++ src/ambs.rs | 3 +++ src/pipeline_printer.rs | 11 +++++++++-- src/pipeline_replacer.rs | 13 ++++++++++--- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/ambr.rs b/src/ambr.rs index 1a7723816..edda664a5 100644 --- a/src/ambr.rs +++ b/src/ambr.rs @@ -39,6 +39,7 @@ Options: --bin-check-bytes Read size by byte for checking binary [default: 256] --regex Enable regular expression search --column Enable column output + --row Enable row output --binary Enable binary file search --statistics Enable statistics output --skipped Enable skipped file output @@ -78,6 +79,7 @@ struct Args { flag_mmap_bytes : u64, flag_regex : bool, flag_column : bool, + flag_row : bool, flag_binary : bool, flag_statistics : bool, flag_skipped : bool, @@ -194,6 +196,7 @@ fn main() { replacer.is_interactive = !args.flag_no_interactive; replacer.print_file = !args.flag_no_file; replacer.print_column = args.flag_column; + replacer.print_row = args.flag_row; let use_regex = args.flag_regex ; let use_tbm = args.flag_tbm ; diff --git a/src/ambs.rs b/src/ambs.rs index cf7ba03c8..7f64edc78 100644 --- a/src/ambs.rs +++ b/src/ambs.rs @@ -38,6 +38,7 @@ Options: --bin-check-bytes Read size by byte for checking binary [default: 256] --regex Enable regular expression search --column Enable column output + --row Enable row output --binary Enable binary file search --statistics Enable statistics output --skipped Enable skipped file output @@ -74,6 +75,7 @@ struct Args { flag_mmap_bytes : u64, flag_regex : bool, flag_column : bool, + flag_row : bool, flag_binary : bool, flag_statistics : bool, flag_skipped : bool, @@ -175,6 +177,7 @@ fn main() { printer.is_color = !args.flag_no_color; printer.print_file = !args.flag_no_file; printer.print_column = args.flag_column; + printer.print_row = args.flag_row; let use_regex = args.flag_regex ; let use_tbm = args.flag_tbm ; diff --git a/src/pipeline_printer.rs b/src/pipeline_printer.rs index 57ad1b24b..2367dc635 100644 --- a/src/pipeline_printer.rs +++ b/src/pipeline_printer.rs @@ -15,6 +15,7 @@ pub struct PipelinePrinter { pub is_color : bool, pub print_file : bool, pub print_column: bool, + pub print_row : bool, pub infos : Vec, pub errors : Vec, console : Console, @@ -29,6 +30,7 @@ impl PipelinePrinter { is_color : true, print_file : true, print_column: false, + print_row : false, infos : Vec::new(), errors : Vec::new(), console : Console::new(), @@ -54,7 +56,7 @@ impl PipelinePrinter { self.console.write( ConsoleTextKind::Filename, pm.path.to_str().unwrap() ); self.console.write( ConsoleTextKind::Filename, ":" ); } - if self.print_column { + if self.print_column | self.print_row { while pos < m.beg { if src[pos] == 0x0a { column += 1; @@ -62,7 +64,12 @@ impl PipelinePrinter { } pos += 1; } - self.console.write( ConsoleTextKind::Other, &format!( "{}:{}:", column + 1, m.beg - last_lf ) ); + if self.print_column { + self.console.write( ConsoleTextKind::Other, &format!( "{}:", column + 1 ) ); + } + if self.print_row { + self.console.write( ConsoleTextKind::Other, &format!( "{}:", m.beg - last_lf ) ); + } } self.console.write_match_line( src, m ); diff --git a/src/pipeline_replacer.rs b/src/pipeline_replacer.rs index e630c01dd..d6d9c94c6 100644 --- a/src/pipeline_replacer.rs +++ b/src/pipeline_replacer.rs @@ -21,6 +21,7 @@ pub struct PipelineReplacer { pub is_interactive: bool, pub print_file : bool, pub print_column : bool, + pub print_row : bool, pub infos : Vec, pub errors : Vec, console : Console, @@ -37,7 +38,8 @@ impl PipelineReplacer { is_color : true, is_interactive: true, print_file : true, - print_column : true, + print_column : false, + print_row : false, infos : Vec::new(), errors : Vec::new(), console : Console::new(), @@ -82,7 +84,7 @@ impl PipelineReplacer { self.console.write( ConsoleTextKind::Filename, pm.path.to_str().unwrap() ); self.console.write( ConsoleTextKind::Other, ": " ); } - if self.print_column { + if self.print_column | self.print_row { while pos < m.beg { if src[pos] == 0x0a { column += 1; @@ -90,7 +92,12 @@ impl PipelineReplacer { } pos += 1; } - self.console.write( ConsoleTextKind::Other, &format!( "{}:{}:", column + 1, m.beg - last_lf ) ); + if self.print_column { + self.console.write( ConsoleTextKind::Other, &format!( "{}:", column + 1 ) ); + } + if self.print_row { + self.console.write( ConsoleTextKind::Other, &format!( "{}:", m.beg - last_lf ) ); + } } self.console.write_match_line( src, m );