mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 18:02:04 +03:00
cli: force utf-8 console output on windows to stop compare crashing
This commit is contained in:
parent
4e4956ceeb
commit
3bf021e1f1
2 changed files with 11 additions and 1 deletions
|
|
@ -33,6 +33,16 @@ from netcheck.probes.latency import ping_fanout, tcp_connect_rtt
|
||||||
from netcheck.probes.traceroute import traceroute
|
from netcheck.probes.traceroute import traceroute
|
||||||
from netcheck.speed import NDT7_CONSENT_NOTICE
|
from netcheck.speed import NDT7_CONSENT_NOTICE
|
||||||
|
|
||||||
|
if sys.platform == "win32":
|
||||||
|
# A legacy console codepage (e.g. cp1251) cannot encode the emoji badges and
|
||||||
|
# Unicode punctuation this CLI prints; forcing UTF-8 here avoids a hard crash
|
||||||
|
# in rich's Windows renderer on every non-ASCII character.
|
||||||
|
for _stream in (sys.stdout, sys.stderr):
|
||||||
|
try:
|
||||||
|
_stream.reconfigure(encoding="utf-8", errors="replace")
|
||||||
|
except (AttributeError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
app = typer.Typer(add_completion=False, help="Deep network diagnostics.")
|
app = typer.Typer(add_completion=False, help="Deep network diagnostics.")
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ def _block(title: str, changes: list[Change]) -> list[str]:
|
||||||
if not changes:
|
if not changes:
|
||||||
return [f"### {title}", "", "No change.", ""]
|
return [f"### {title}", "", "No change.", ""]
|
||||||
return (
|
return (
|
||||||
[f"### {title}", "", "| Field | Before | After | Δ |", "|---|---|---|---|"]
|
[f"### {title}", "", "| Field | Before | After | Delta |", "|---|---|---|---|"]
|
||||||
+ [f"| {c.label} | {_fmt(c.before)} | {_fmt(c.after)} | {_fmt(c.delta)} |" for c in changes]
|
+ [f"| {c.label} | {_fmt(c.before)} | {_fmt(c.after)} | {_fmt(c.delta)} |" for c in changes]
|
||||||
+ [""]
|
+ [""]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue