Skip to content

Commit

Permalink
output: remove --line-number-width flag
Browse files Browse the repository at this point in the history
This commit does what no software project has ever done before: we've
outright removed a flag with no possible way to recapture its
functionality.

This flag presents numerous problems in that it never really worked well
in the first place, and completely falls over when ripgrep uses the
--no-heading output format. Well meaning users want ripgrep to fix this
by getting into the alignment business by buffering all output, but that
is a line that I refuse to cross.

Fixes #795
  • Loading branch information
BurntSushi committed Apr 23, 2018
1 parent ed05955 commit ae6f871
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 65 deletions.
1 change: 0 additions & 1 deletion complete/_rg
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ _rg() {
'--ignore-file=[specify additional ignore file]:file:_files'
'(-v --invert-match)'{-v,--invert-match}'[invert matching]'
'(-n -N --line-number --no-line-number)'{-n,--line-number}'[show line numbers]'
'(-N --no-line-number)--line-number-width=[specify width of displayed line number]:number of columns'
'(-w -x --line-regexp --word-regexp)'{-x,--line-regexp}'[only show matches surrounded by line boundaries]'
'(-M --max-columns)'{-M+,--max-columns=}'[specify max length of lines to print]:number of bytes'
'(-m --max-count)'{-m+,--max-count=}'[specify max number of matches per file]:number of matches'
Expand Down
30 changes: 0 additions & 30 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,23 +475,6 @@ impl RGArg {
});
self
}

/// Indicate that any value given to this argument should be a valid
/// line number width. A valid line number width cannot start with `0`
/// to maintain compatibility with future improvements that add support
/// for padding character specifies.
fn line_number_width(mut self) -> RGArg {
self.claparg = self.claparg.validator(|val| {
if val.starts_with("0") {
Err(String::from(
"Custom padding characters are currently not supported. \
Please enter only a numeric value."))
} else {
val.parse::<usize>().map(|_| ()).map_err(|err| err.to_string())
}
});
self
}
}

// We add an extra space to long descriptions so that a black line is inserted
Expand Down Expand Up @@ -535,7 +518,6 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
flag_ignore_file(&mut args);
flag_invert_match(&mut args);
flag_line_number(&mut args);
flag_line_number_width(&mut args);
flag_line_regexp(&mut args);
flag_max_columns(&mut args);
flag_max_count(&mut args);
Expand Down Expand Up @@ -1100,18 +1082,6 @@ terminal.
args.push(arg);
}

fn flag_line_number_width(args: &mut Vec<RGArg>) {
const SHORT: &str = "Left pad line numbers up to NUM width.";
const LONG: &str = long!("\
Left pad line numbers up to NUM width. Space is used as the default padding
character. This has no effect if --no-line-number is enabled.
");
let arg = RGArg::flag("line-number-width", "NUM")
.help(SHORT).long_help(LONG)
.line_number_width();
args.push(arg);
}

fn flag_line_regexp(args: &mut Vec<RGArg>) {
const SHORT: &str = "Only show matches surrounded by line boundaries.";
const LONG: &str = long!("\
Expand Down
5 changes: 1 addition & 4 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub struct Args {
invert_match: bool,
line_number: bool,
line_per_match: bool,
line_number_width: Option<usize>,
max_columns: Option<usize>,
max_count: Option<u64>,
max_filesize: Option<u64>,
Expand Down Expand Up @@ -191,8 +190,7 @@ impl Args {
.only_matching(self.only_matching)
.path_separator(self.path_separator)
.with_filename(self.with_filename)
.max_columns(self.max_columns)
.line_number_width(self.line_number_width);
.max_columns(self.max_columns);
if let Some(ref rep) = self.replace {
p = p.replace(rep.clone());
}
Expand Down Expand Up @@ -401,7 +399,6 @@ impl<'a> ArgMatches<'a> {
ignore_files: self.ignore_files(),
invert_match: self.is_present("invert-match"),
line_number: line_number,
line_number_width: try!(self.usize_of("line-number-width")),
line_per_match: self.is_present("vimgrep"),
max_columns: self.usize_of_nonzero("max-columns")?,
max_count: self.usize_of("max-count")?.map(|n| n as u64),
Expand Down
14 changes: 0 additions & 14 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ pub struct Printer<W> {
path_separator: Option<u8>,
/// Restrict lines to this many columns.
max_columns: Option<usize>,
/// Width of line number displayed. If the number of digits in the
/// line number is less than this, it is left padded with
/// spaces.
line_number_width: Option<usize>
}

impl<W: WriteColor> Printer<W> {
Expand All @@ -124,7 +120,6 @@ impl<W: WriteColor> Printer<W> {
colors: ColorSpecs::default(),
path_separator: None,
max_columns: None,
line_number_width: None
}
}

Expand Down Expand Up @@ -213,12 +208,6 @@ impl<W: WriteColor> Printer<W> {
self
}

/// Configure the width of the displayed line number
pub fn line_number_width(mut self, line_number_width: Option<usize>) -> Printer<W> {
self.line_number_width = line_number_width;
self
}

/// Returns true if and only if something has been printed.
pub fn has_printed(&self) -> bool {
self.has_printed
Expand Down Expand Up @@ -484,9 +473,6 @@ impl<W: WriteColor> Printer<W> {

fn line_number(&mut self, n: u64, sep: u8) {
let mut line_number = n.to_string();
if let Some(width) = self.line_number_width {
line_number = format!("{:>width$}", line_number, width = width);
}
self.write_colored(line_number.as_bytes(), |colors| colors.line());
self.separator(&[sep]);
}
Expand Down
16 changes: 0 additions & 16 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,6 @@ sherlock!(line_numbers, |wd: WorkDir, mut cmd: Command| {
assert_eq!(lines, expected);
});

sherlock!(line_number_width, |wd: WorkDir, mut cmd: Command| {
cmd.arg("-n");
cmd.arg("--line-number-width").arg("2");
let lines: String = wd.stdout(&mut cmd);
let expected = " 1:For the Doctor Watsons of this world, as opposed to the Sherlock
3:be, to a very large extent, the result of luck. Sherlock Holmes
";
assert_eq!(lines, expected);
});

sherlock!(line_number_width_padding_character_error, |wd: WorkDir, mut cmd: Command| {
cmd.arg("-n");
cmd.arg("--line-number-width").arg("02");
wd.assert_non_empty_stderr(&mut cmd);
});

sherlock!(columns, |wd: WorkDir, mut cmd: Command| {
cmd.arg("--column");
let lines: String = wd.stdout(&mut cmd);
Expand Down

0 comments on commit ae6f871

Please sign in to comment.