Skip to content

Commit

Permalink
add --row option
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Feb 26, 2016
1 parent ce07ae9 commit 0c6d777
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/ambr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Options:
--bin-check-bytes <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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 ;
Expand Down
3 changes: 3 additions & 0 deletions src/ambs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Options:
--bin-check-bytes <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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 ;
Expand Down
11 changes: 9 additions & 2 deletions src/pipeline_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub errors : Vec<String>,
console : Console,
Expand All @@ -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(),
Expand All @@ -54,15 +56,20 @@ 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;
last_lf = pos;
}
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 );
Expand Down
13 changes: 10 additions & 3 deletions src/pipeline_replacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub errors : Vec<String>,
console : Console,
Expand All @@ -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(),
Expand Down Expand Up @@ -82,15 +84,20 @@ 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;
last_lf = pos;
}
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 );
Expand Down

0 comments on commit 0c6d777

Please sign in to comment.