Add new -M/--max-columns option.

This permits setting the maximum line width with respect to the number
of bytes in a line. Omitted lines (whether part of a match, replacement
or context) are replaced with a message stating that the line was
elided.

Fixes #129
This commit is contained in:
Ralf Jung
2017-02-02 15:29:50 +01:00
committed by Andrew Gallant
parent 23aec58669
commit d352b79294
5 changed files with 122 additions and 17 deletions

View File

@@ -56,6 +56,7 @@ pub struct Args {
invert_match: bool,
line_number: bool,
line_per_match: bool,
max_columns: Option<usize>,
max_count: Option<u64>,
max_filesize: Option<u64>,
maxdepth: Option<usize>,
@@ -156,7 +157,8 @@ impl Args {
.line_per_match(self.line_per_match)
.null(self.null)
.path_separator(self.path_separator)
.with_filename(self.with_filename);
.with_filename(self.with_filename)
.max_columns(self.max_columns);
if let Some(ref rep) = self.replace {
p = p.replace(rep.clone());
}
@@ -348,6 +350,7 @@ impl<'a> ArgMatches<'a> {
invert_match: self.is_present("invert-match"),
line_number: line_number,
line_per_match: self.is_present("vimgrep"),
max_columns: try!(self.usize_of("max-columns")),
max_count: try!(self.usize_of("max-count")).map(|max| max as u64),
max_filesize: try!(self.max_filesize()),
maxdepth: try!(self.usize_of("maxdepth")),