Skip to content

Commit

Permalink
Add --no-bold option. Fixes #6, closes #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkaufman committed Dec 8, 2014
1 parent 89c338c commit 0a27bea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Options:
foreground color. Very fast, ugly, displays all
changes
--line-numbers generate output with line numbers
--no-bold use non-bold colors; recommended for with solarized
--no-headers don't label the left and right sides with their file
names
--numlines=NUMLINES how many lines of context to print; can't be combined
Expand Down
47 changes: 34 additions & 13 deletions icdiff
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class ConsoleDiff(object):
Based on difflib.HtmlDiff
This class can be used to create a text-mode table showing a side
by side, line by line comparison of text with inter-line and
intra-line change highlights in ansi color escape sequences as
intra-line change highlights in ansi color escape sequences as
read by xterm. The table can be generated in either full or
contextual difference mode.
Expand All @@ -42,7 +44,8 @@ class ConsoleDiff(object):
charjunk=difflib.IS_CHARACTER_JUNK, cols=80,
line_numbers=False,
show_all_spaces=False,
highlight=False):
highlight=False,
no_bold=False):
"""ConsoleDiff instance initializer
Arguments:
Expand All @@ -58,7 +61,8 @@ class ConsoleDiff(object):
self.line_numbers = line_numbers
self.cols = cols
self.show_all_spaces = show_all_spaces
self.highlight=highlight
self.highlight = highlight
self.no_bold = no_bold

if wrapcolumn is None:
if not line_numbers:
Expand Down Expand Up @@ -374,18 +378,30 @@ class ConsoleDiff(object):
return color.replace("\033[1;", "\033[7;")

codes = {
"red": '\033[1;31m',
"green": '\033[1;32m',
"yellow": '\033[1;33m',
"blue": '\033[1;34m',
"magenta": '\033[1;35m',
"cyan": '\033[1;36m',
"red": '\033[0;31m',
"green": '\033[0;32m',
"yellow": '\033[0;33m',
"blue": '\033[0;34m',
"magenta": '\033[0;35m',
"cyan": '\033[0;36m',
"none": '\033[m',
"red_bold": '\033[1;31m',
"green_bold": '\033[1;32m',
"yellow_bold": '\033[1;33m',
"blue_bold": '\033[1;34m',
"magenta_bold": '\033[1;35m',
"cyan_bold": '\033[1;36m',
"none": '\033[m',
}

C_ADD = codes["green"]
C_SUB = codes["red"]
C_CHG = codes["yellow"]
if self.no_bold:
C_ADD = codes["green"]
C_SUB = codes["red"]
C_CHG = codes["yellow"]
else:
C_ADD = codes["green_bold"]
C_SUB = codes["red_bold"]
C_CHG = codes["yellow_bold"]

if self.highlight:
C_ADD, C_SUB, C_CHG = background(C_ADD), background(C_SUB), background(C_CHG)
Expand All @@ -402,7 +418,8 @@ class ConsoleDiff(object):
return s

if not self.show_all_spaces:
return re.sub("\033\\[1;3([123])m(\\s+)(\033\\[)", "\033[7;3\\1m\\2\\3", s)
# If there's a change consisting entirely of whitespace, don't color it.
return re.sub("\033\\[[01];3([123])m(\\s+)(\033\\[)", "\033[7;3\\1m\\2\\3", s)

def will_see_coloredspace(i, s):
while i < len(s) and s[i].isspace():
Expand Down Expand Up @@ -450,6 +467,9 @@ if __name__ == "__main__":
parser.add_option("--line-numbers", default=False,
action="store_true",
help="generate output with line numbers")
parser.add_option("--no-bold", default=False,
action="store_true",
help="use non-bold colors; recommended for with solarized")
parser.add_option("--no-headers", default=False,
action="store_true",
help="don't label the left and right sides with their file names")
Expand All @@ -468,7 +488,7 @@ if __name__ == "__main__":
(options, args) = parser.parse_args()

if options.version:
print("icdiff version 1.0.0")
print("icdiff version 1.1.0")
sys.exit()

if len(args) != 2:
Expand Down Expand Up @@ -506,5 +526,6 @@ if __name__ == "__main__":
print(ConsoleDiff(cols=int(options.cols),
show_all_spaces=options.show_all_spaces,
highlight=options.highlight,
no_bold=options.no_bold,
line_numbers=options.line_numbers).make_table(
lines_a, lines_b, headers[0], headers[1], context=(not options.whole_file), numlines=int(options.numlines)))

0 comments on commit 0a27bea

Please sign in to comment.