Skip to content

Commit 6ae4344

Browse files
authored
fix: drop color printout for html & JSON (#135)
1 parent 2040baa commit 6ae4344

File tree

2 files changed

+18
-37
lines changed

2 files changed

+18
-37
lines changed

src/repo_review/__main__.py

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import rich_click as click
1717

1818
import rich.console
19-
import rich.json
2019
import rich.markdown
2120
import rich.syntax
2221
import rich.terminal_theme
@@ -187,37 +186,17 @@ def display_output(
187186
"checks": as_simple_dict(processed),
188187
}
189188
if header:
190-
d = {header: d}
191-
192-
if color and output.isatty():
193-
j = rich.json.JSON.from_data(d)
194-
console = rich.console.Console(stderr=stderr, color_system="auto")
195-
if header:
196-
# We strip off beginning and ending brackets
197-
console.print(j.__rich__()[2:-2], end="")
198-
else:
199-
console.print(j)
189+
print(json.dumps({header: d}, indent=2)[2:-2], end="", file=output)
200190
else:
201-
# Rich wraps json, which breaks it
202-
if header:
203-
print(json.dumps(d, indent=2)[2:-2])
204-
else:
205-
print(json.dumps(d, indent=2))
191+
print(json.dumps(d, indent=2), file=output)
192+
206193
case "html":
207194
html = to_html(families, processed, status)
208195
if header:
209196
failures = sum(r.result is False for r in processed)
210197
status_msg = f"({failures} failed)" if failures else "(all passed)"
211198
html = f"<details><summary><h2>{header}</h2>: {status_msg}</summary>\n{html}</details>\n"
212-
if color and output.isatty():
213-
# We check isatty even though Rich does too because Rich
214-
# injects a ton of ending whitespace even going to a file
215-
rich.print(
216-
rich.syntax.Syntax(html, lexer="html"),
217-
file=output,
218-
)
219-
else:
220-
print(html, file=output)
199+
print(html, file=output)
221200
case _:
222201
assert_never(format_opt)
223202

@@ -284,14 +263,10 @@ def main(
284263
"""
285264

286265
if len(packages) > 1:
287-
stdout = rich.console.Console(
288-
color_system="auto" if stderr_fmt is None else None
289-
)
290-
stderr = rich.console.Console(color_system="auto", stderr=True)
291266
if format_opt == "json":
292-
stdout.print("{")
267+
print("{")
293268
if stderr_fmt == "json":
294-
stderr.print("{")
269+
print("{", file=sys.stderr)
295270

296271
result = 0
297272
for n, package in enumerate(packages):
@@ -308,15 +283,15 @@ def main(
308283
if len(packages) > 1:
309284
is_before_end = n < len(packages) - 1
310285
if format_opt == "json":
311-
stdout.print("," if is_before_end else "")
286+
print("," if is_before_end else "")
312287
if stderr_fmt == "json":
313-
stderr.print("," if is_before_end else "")
288+
print("," if is_before_end else "", file=sys.stderr)
314289

315290
if len(packages) > 1:
316291
if format_opt == "json":
317-
stdout.print("}")
292+
print("}")
318293
if stderr_fmt == "json":
319-
stderr.print("}")
294+
print("}", file=sys.stderr)
320295

321296
if result:
322297
raise SystemExit(result)

src/repo_review/html.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def to_html(
4646
if family_results or family_description:
4747
print(f"<h3>{family_name}</h3>")
4848
if family_description:
49-
print(md.render(family_description))
49+
print(md.render(family_description).strip())
5050
if family_results:
5151
print("<table>")
5252
print("<tr><th>?</th><th>Name</th><th>Description</th></tr>")
@@ -58,7 +58,13 @@ def to_html(
5858
if result.result
5959
else "red"
6060
)
61-
icon = "⚠️" if result.result is None else "✅" if result.result else "❌"
61+
icon = (
62+
"&#9888;&#65039;"
63+
if result.result is None
64+
else "&#9989;"
65+
if result.result
66+
else "&#10060;"
67+
)
6268
result_txt = (
6369
"Skipped"
6470
if result.result is None

0 commit comments

Comments
 (0)