Skip to content

Commit c9f0c9c

Browse files
committed
[color] fixed bug in ANSI color output, revised test file
1 parent 00a25f5 commit c9f0c9c

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

lib/fdiff/color.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
ansicolors = {
24
"BLACK": "\033[30m",
35
"RED": "\033[31m",
@@ -22,8 +24,16 @@ def color_unified_diff_line(line):
2224
on the unified diff line type."""
2325
if line[0:2] == "+ ":
2426
return f"{green_start}{line}{reset}"
27+
elif line == f"+{os.linesep}":
28+
# some lines are formatted as hyphen only with no other characters
29+
# this indicates an added empty line
30+
return f"{green_start}{line}{reset}"
2531
elif line[0:2] == "- ":
2632
return f"{red_start}{line}{reset}"
33+
elif line == f"-{os.linesep}":
34+
# some lines are formatted as hyphen only with no other characters
35+
# this indicates a deleted empty line
36+
return f"{red_start}{line}{reset}"
2737
elif line[0:3] == "@@ ":
2838
return f"{cyan_start}{line}{reset}"
2939
elif line[0:4] == "--- ":

tests/testfiles/roboto_udiff_color_expected.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@
112112
 </contour>
113113
<instructions/>
114114
</TTGlyph>
115-
-
116-
- <TTGlyph name=".null"/><!-- contains no outline data -->
115+
-
116+
- <TTGlyph name=".null"/><!-- contains no outline data -->
117117

118118
<TTGlyph name="dollar" xMin="110" yMin="-208" xMax="1042" yMax="1692">
119119
<contour>
@@ -145,14 +145,14 @@
145145
+ </contour>
146146
+ <instructions/>
147147
+ </TTGlyph>
148-
+
149-
+ <TTGlyph name="glyph00001"/><!-- contains no outline data -->
150-
+
151-
+ <TTGlyph name="glyph00002"/><!-- contains no outline data -->
152-
+
153-
+ <TTGlyph name="glyph00003"/><!-- contains no outline data -->
154-
+
155-
+ <TTGlyph name="glyph00010" xMin="68" yMin="-237" xMax="990" yMax="1395">
148+
+
149+
+ <TTGlyph name="glyph00001"/><!-- contains no outline data -->
150+
+
151+
+ <TTGlyph name="glyph00002"/><!-- contains no outline data -->
152+
+
153+
+ <TTGlyph name="glyph00003"/><!-- contains no outline data -->
154+
+
155+
+ <TTGlyph name="glyph00010" xMin="68" yMin="-237" xMax="990" yMax="1395">
156156
 <contour>
157157
<pt x="990" y="300" on="1"/>
158158
<pt x="990" y="168" on="0"/>
@@ -183,27 +183,27 @@
183183
- </contour>
184184
- <instructions/>
185185
- </TTGlyph>
186-
-
187-
<TTGlyph name="numbersign" xMin="119" yMin="0" xMax="1235" yMax="1456">
186+
-
187+
 <TTGlyph name="numbersign" xMin="119" yMin="0" xMax="1235" yMax="1456">
188188
<contour>
189189
<pt x="686" y="0" on="1"/>
190190
@@ -478,10 +482,6 @@
191191

192192
<TTGlyph name="space"/><!-- contains no outline data -->
193193

194194
- <TTGlyph name="uni0002"/><!-- contains no outline data -->
195-
-
196-
- <TTGlyph name="uni0009"/><!-- contains no outline data -->
197-
-
198-
</glyf>
195+
-
196+
- <TTGlyph name="uni0009"/><!-- contains no outline data -->
197+
-
198+
 </glyf>
199199

200200
<name>
201201
@@ -528,33 +528,6 @@
202202
 http://www.apache.org/licenses/LICENSE-2.0
203203
</namerecord>
204204
</name>
205-
-
206-
- <post>
205+
-
206+
- <post>
207207
- <formatType value="2.0"/>
208208
- <italicAngle value="0.0"/>
209209
- <underlinePosition value="-150"/>

0 commit comments

Comments
 (0)