Skip to content

Commit 9dbfbb9

Browse files
committed
Add --show-no-spaces. Fixes #173
1 parent 3b0f7be commit 9dbfbb9

File tree

7 files changed

+69
-1
lines changed

7 files changed

+69
-1
lines changed

icdiff

+18-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class ConsoleDiff(object):
9999
cols=80,
100100
line_numbers=False,
101101
show_all_spaces=False,
102+
show_no_spaces=False,
102103
highlight=False,
103104
truncate=False,
104105
strip_trailing_cr=False,
@@ -118,6 +119,7 @@ class ConsoleDiff(object):
118119
self.line_numbers = line_numbers
119120
self.cols = cols
120121
self.show_all_spaces = show_all_spaces
122+
self.show_no_spaces = show_no_spaces
121123
self.highlight = highlight
122124
self.strip_trailing_cr = strip_trailing_cr
123125
self.truncate = truncate
@@ -469,7 +471,15 @@ class ConsoleDiff(object):
469471
if self.highlight:
470472
return s
471473

472-
if not self.show_all_spaces:
474+
if self.show_no_spaces:
475+
# Don't show whitespace even if it's a whitespace-only line.
476+
return re.sub(
477+
"\033\\[[01];3([01234567])m(\\s+)(\033\\[)",
478+
"\033[0;3\\1m\\2\\3",
479+
s,
480+
)
481+
482+
elif not self.show_all_spaces:
473483
# If there's a change consisting entirely of whitespace,
474484
# don't color it.
475485
return re.sub(
@@ -643,6 +653,12 @@ def create_option_parser():
643653
"that which is not needed for drawing the eye to "
644654
"changes. Slow, ugly, displays all changes",
645655
)
656+
parser.add_option(
657+
"--show-no-spaces",
658+
default=False,
659+
action="store_true",
660+
help="don't color whitespace-only changes"
661+
)
646662
parser.add_option("--tabsize", default=8, help="tab stop spacing")
647663
parser.add_option(
648664
"-t",
@@ -990,6 +1006,7 @@ def diff_files(options, a, b):
9901006
cd = ConsoleDiff(
9911007
cols=int(options.cols),
9921008
show_all_spaces=options.show_all_spaces,
1009+
show_no_spaces=options.show_no_spaces,
9931010
highlight=options.highlight,
9941011
line_numbers=options.line_numbers,
9951012
tabsize=int(options.tabsize),

test.sh

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ check_gold 1 gold-45-h.txt tests/input-{4,5}.txt --cols=80 --highligh
128128
check_gold 1 gold-45-nb.txt tests/input-{4,5}.txt --cols=80 --no-bold
129129
check_gold 1 gold-45-sas-h.txt tests/input-{4,5}.txt --cols=80 --show-all-spaces --highlight
130130
check_gold 1 gold-45-sas-h-nb.txt tests/input-{4,5}.txt --cols=80 --show-all-spaces --highlight --no-bold
131+
check_gold 1 gold-sas.txt tests/input-{10,11}.txt --cols=80 --show-all-spaces
132+
check_gold 1 gold-sns.txt tests/input-{10,11}.txt --cols=80 --show-no-spaces
133+
check_gold 1 gold-show-spaces.txt tests/input-{10,11}.txt --cols=80
131134
check_gold 1 gold-45-h-nb.txt tests/input-{4,5}.txt --cols=80 --highlight --no-bold
132135
check_gold 1 gold-45-ln.txt tests/input-{4,5}.txt --cols=80 --line-numbers
133136
check_gold 1 gold-45-ln-color.txt tests/input-{4,5}.txt --cols=80 --line-numbers --color-map='line-numbers:cyan'

tests/gold-sas.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/input-10.txt tests/input-11.txt
2+
void main () void main ()
3+
{ {
4+
int x; int x;
5+
int y; int y;
6+
} }
7+
 
8+
void foo ()
9+
{
10+
 
11+
}

tests/gold-show-spaces.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/input-10.txt tests/input-11.txt
2+
void main () void main ()
3+
{ {
4+
int x; int x;
5+
int y; int y;
6+
} }
7+
 
8+
void foo ()
9+
{
10+
 
11+
}

tests/gold-sns.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/input-10.txt tests/input-11.txt
2+
void main () void main ()
3+
{ {
4+
int x; int x;
5+
int y; int y;
6+
} }
7+
 
8+
void foo ()
9+
{
10+
 
11+
}

tests/input-10.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
void main ()
2+
{
3+
int x;
4+
int y;
5+
}

tests/input-11.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
void main ()
2+
{
3+
int x;
4+
int y;
5+
}
6+
7+
void foo ()
8+
{
9+
10+
}

0 commit comments

Comments
 (0)