Skip to content

Commit

Permalink
added --column, but the test still fails
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Apr 23, 2009
1 parent f0eb1d3 commit 02a2b65
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Ack.pm
Expand Up @@ -196,6 +196,7 @@ sub get_command_line_options {
'color|colour!' => \$opt{color},
'color-match=s' => \$ENV{ACK_COLOR_MATCH},
'color-filename=s' => \$ENV{ACK_COLOR_FILENAME},
'column!' => \$opt{column},
count => \$opt{count},
'env!' => sub { }, # ignore this option, it is handled beforehand
f => \$opt{f},
Expand Down Expand Up @@ -703,6 +704,7 @@ Search output:
-H, --with-filename Print the filename for each match
-h, --no-filename Suppress the prefixing filename on output
-c, --count Show number of lines matching per file
--column Show the column number of the first match
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching
Expand Down Expand Up @@ -943,6 +945,7 @@ sub print_blank_line { App::Ack::print( "\n" ) }
sub print_separator { App::Ack::print( "--\n" ) }
sub print_filename { App::Ack::print( $_[0], $_[1] ) }
sub print_line_no { App::Ack::print( $_[0], $_[1] ) }
sub print_column_no { App::Ack::print( $_[0], $_[1] ) }
sub print_count {
my $filename = shift;
my $nmatches = shift;
Expand Down Expand Up @@ -1100,6 +1103,7 @@ sub print_match_or_context {
my $color = $opt->{color};
my $heading = $opt->{heading};
my $show_filename = $opt->{show_filename};
my $show_column = $opt->{with_column};

if ( $show_filename ) {
if ( not defined $display_filename ) {
Expand Down Expand Up @@ -1137,6 +1141,8 @@ sub print_match_or_context {
}
}
else {
my $col = $-[0] + 1;

if ( $color && $is_match && $regex &&
s/$regex/Term::ANSIColor::colored( substr($_, $-[0], $+[0] - $-[0]), $ENV{ACK_COLOR_MATCH} )/eg ) {
# At the end of the line reset the color and remove newline
Expand All @@ -1146,6 +1152,9 @@ sub print_match_or_context {
# remove any kind of newline at the end of the line
s/[\r\n]*\z//;
}
if ( $show_column ) {
App::Ack::print_column_no( $col, $sep );
}
App::Ack::print($_ . "\n");
}
$any_output = 1;
Expand Down
6 changes: 5 additions & 1 deletion Changes
Expand Up @@ -13,8 +13,12 @@ NEXT
let you define ACK_COLOR_MATCH and ACK_COLOR_FILENAME from the
command line.

Added new switch --column to display the column of the first
hit on the row. Thanks to Eric Van Dewoestine.

[FIXES]
More tweaks to get the detection of input and output pipes working.
More tweaks to get the detection of input and output pipes
working.

Fixed an amazingly bad call to cmp_ok() in t/ack-passthru.t.

Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -24,6 +24,7 @@ t/ack-a.t
t/ack-binary.t
t/ack-c.t
t/ack-color.t
t/ack-column.t
t/ack-env.t
t/ack-g.t
t/ack-group.t
Expand Down
15 changes: 15 additions & 0 deletions ack
Expand Up @@ -221,6 +221,11 @@ Sets the color to be used for filenames.
Sets the color to be used for matches.
=item B<--column>
Show the column number of the first match. This is helpful for editors
that can place your cursor at a given position.
=item B<--env>, B<--noenv>
B<--noenv> disables all environment processing. No F<.ackrc> is read
Expand Down Expand Up @@ -791,6 +796,7 @@ L<http://ack.googlecode.com/svn/>
How appropriate to have I<ack>nowledgements!
Thanks to everyone who has contributed to ack in any way, including
Eric Van Dewoestine.
Sitaram Chamarty,
Adam James,
Richard Carlsson,
Expand Down Expand Up @@ -1197,6 +1203,7 @@ sub get_command_line_options {
'color|colour!' => \$opt{color},
'color-match=s' => \$ENV{ACK_COLOR_MATCH},
'color-filename=s' => \$ENV{ACK_COLOR_FILENAME},
'column!' => \$opt{column},
count => \$opt{count},
'env!' => sub { }, # ignore this option, it is handled beforehand
f => \$opt{f},
Expand Down Expand Up @@ -1621,6 +1628,7 @@ Search output:
-H, --with-filename Print the filename for each match
-h, --no-filename Suppress the prefixing filename on output
-c, --count Show number of lines matching per file
--column Show the column number of the first match
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching
Expand Down Expand Up @@ -1831,6 +1839,7 @@ sub print_blank_line { App::Ack::print( "\n" ) }
sub print_separator { App::Ack::print( "--\n" ) }
sub print_filename { App::Ack::print( $_[0], $_[1] ) }
sub print_line_no { App::Ack::print( $_[0], $_[1] ) }
sub print_column_no { App::Ack::print( $_[0], $_[1] ) }
sub print_count {
my $filename = shift;
my $nmatches = shift;
Expand Down Expand Up @@ -1976,6 +1985,7 @@ sub print_match_or_context {
my $color = $opt->{color};
my $heading = $opt->{heading};
my $show_filename = $opt->{show_filename};
my $show_column = $opt->{with_column};

if ( $show_filename ) {
if ( not defined $display_filename ) {
Expand Down Expand Up @@ -2013,6 +2023,8 @@ sub print_match_or_context {
}
}
else {
my $col = $-[0] + 1;

if ( $color && $is_match && $regex &&
s/$regex/Term::ANSIColor::colored( substr($_, $-[0], $+[0] - $-[0]), $ENV{ACK_COLOR_MATCH} )/eg ) {
# At the end of the line reset the color and remove newline
Expand All @@ -2022,6 +2034,9 @@ sub print_match_or_context {
# remove any kind of newline at the end of the line
s/[\r\n]*\z//;
}
if ( $show_column ) {
App::Ack::print_column_no( $col, $sep );
}
App::Ack::print($_ . "\n");
}
$any_output = 1;
Expand Down
6 changes: 6 additions & 0 deletions ack-base
Expand Up @@ -213,6 +213,11 @@ Sets the color to be used for filenames.
Sets the color to be used for matches.
=item B<--column>
Show the column number of the first match. This is helpful for editors
that can place your cursor at a given position.
=item B<--env>, B<--noenv>
B<--noenv> disables all environment processing. No F<.ackrc> is read
Expand Down Expand Up @@ -783,6 +788,7 @@ L<http://ack.googlecode.com/svn/>
How appropriate to have I<ack>nowledgements!
Thanks to everyone who has contributed to ack in any way, including
Eric Van Dewoestine.
Sitaram Chamarty,
Adam James,
Richard Carlsson,
Expand Down
1 change: 1 addition & 0 deletions ack-help.txt
Expand Up @@ -37,6 +37,7 @@ Search output:
-H, --with-filename Print the filename for each match
-h, --no-filename Suppress the prefixing filename on output
-c, --count Show number of lines matching per file
--column Show the column number of the first match

-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching
Expand Down
67 changes: 67 additions & 0 deletions t/ack-column.t
@@ -0,0 +1,67 @@
#!perl

use warnings;
use strict;

use Test::More tests => 4;

use File::Next ();

use lib 't';
use Util;

prep_environment();

my $weasel = File::Next::reslash( 't/text/science-of-myth.txt' );

WITH_COLUMNS: {
my @expected = split( /\n/, <<'HERE' );
3:4:In the case of Christianity and Judaism there exists the belief
6:1:The Buddhists believe that the functional aspects override the myth
7:8:While other religions use the literal core to build foundations with
8:11:See, half the world sees the myth as fact, and it's seen as a lie by the other half
9:5:And the simple truth is that it's none of that 'cause
10:24:Somehow no matter what the world keeps turning
14:43:In fact, for better understanding we take the facts of science and apply them
15:35:And if both factors keep evolving then we continue getting information
16:17:But closing off the possibilities makes it hard to see the bigger picture
18:10:Consider the case of the woman whose faith helped her make it through
22:18:And if it works, then it gets the job done
23:24:Somehow no matter what the world keeps turning
26:9: -- "The Science Of Myth", Screeching Weasel
HERE
@expected = map { "${weasel}:$_" } @expected;

my @files = ( $weasel );
my @args = qw( the -w --with-filename --column );
my @results = run_ack( @args, @files );

sets_match( \@results, \@expected, 'Checking column numbers' );
}


WITHOUT_COLUMNS: {
my @expected = split( /\n/, <<'HERE' );
3:In the case of Christianity and Judaism there exists the belief
6:The Buddhists believe that the functional aspects override the myth
7:While other religions use the literal core to build foundations with
8:See, half the world sees the myth as fact, and it's seen as a lie by the other half
9:And the simple truth is that it's none of that 'cause
10:Somehow no matter what the world keeps turning
14:In fact, for better understanding we take the facts of science and apply them
15:And if both factors keep evolving then we continue getting information
16:But closing off the possibilities makes it hard to see the bigger picture
18:Consider the case of the woman whose faith helped her make it through
22:And if it works, then it gets the job done
23:Somehow no matter what the world keeps turning
26: -- "The Science Of Myth", Screeching Weasel
HERE
@expected = map { "${weasel}:$_" } @expected;

my @files = ( $weasel );
my @args = qw( the -w --with-filename --no-column );
my @results = run_ack( @args, @files );

sets_match( \@results, \@expected, 'Checking without column numbers' );
}

0 comments on commit 02a2b65

Please sign in to comment.