@@ -99,6 +99,7 @@ class ConsoleDiff(object):
99
99
cols = 80 ,
100
100
line_numbers = False ,
101
101
show_all_spaces = False ,
102
+ show_no_spaces = False ,
102
103
highlight = False ,
103
104
truncate = False ,
104
105
strip_trailing_cr = False ,
@@ -118,6 +119,7 @@ class ConsoleDiff(object):
118
119
self .line_numbers = line_numbers
119
120
self .cols = cols
120
121
self .show_all_spaces = show_all_spaces
122
+ self .show_no_spaces = show_no_spaces
121
123
self .highlight = highlight
122
124
self .strip_trailing_cr = strip_trailing_cr
123
125
self .truncate = truncate
@@ -469,7 +471,15 @@ class ConsoleDiff(object):
469
471
if self .highlight :
470
472
return s
471
473
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 :
473
483
# If there's a change consisting entirely of whitespace,
474
484
# don't color it.
475
485
return re .sub (
@@ -643,6 +653,12 @@ def create_option_parser():
643
653
"that which is not needed for drawing the eye to "
644
654
"changes. Slow, ugly, displays all changes" ,
645
655
)
656
+ parser .add_option (
657
+ "--show-no-spaces" ,
658
+ default = False ,
659
+ action = "store_true" ,
660
+ help = "don't color whitespace-only changes"
661
+ )
646
662
parser .add_option ("--tabsize" , default = 8 , help = "tab stop spacing" )
647
663
parser .add_option (
648
664
"-t" ,
@@ -990,6 +1006,7 @@ def diff_files(options, a, b):
990
1006
cd = ConsoleDiff (
991
1007
cols = int (options .cols ),
992
1008
show_all_spaces = options .show_all_spaces ,
1009
+ show_no_spaces = options .show_no_spaces ,
993
1010
highlight = options .highlight ,
994
1011
line_numbers = options .line_numbers ,
995
1012
tabsize = int (options .tabsize ),
0 commit comments