[BUG] Weird output from from_ansi
See original GitHub issueThe output from the method from_ansi
is not correctly rendered by console.Console
.
- This example forces colored output in a
subprocess
and then prints the output to the terminal - directly (no pipeing) โ๏ธ
- pipeing and then printing the output using
print()
โ๏ธ - pipeing and then printing the output using
Console.print()
โ
Test script
import atexit
import os
from pathlib import Path
from subprocess import PIPE, Popen
from tempfile import NamedTemporaryFile
from rich import console, text
console_out = console.Console()
console_err = console.Console(stderr=True)
with NamedTemporaryFile(delete=False) as s, NamedTemporaryFile(delete=False) as t:
txt = b"""#include <stdio.h>\nint main() {\nint a=1;\nreturn 0;\n}"""
s.write(txt)
cmd = ["gcc", "-Wall", "-fdiagnostics-color=always", "-x", "c", s.name, "-o", t.name]
console_out.print("Expected output as reference", style="magenta")
with Popen(cmd) as proc:
proc.communicate()
console_out.print("Just print piped err to the terminal", style="magenta")
with Popen(cmd, stdout=PIPE, stderr=PIPE) as proc:
out, err = proc.communicate()
print(err.decode("utf-8"))
console_out.print("Rich output - verbatim (expected like that)", style="magenta")
console_err.print(err.decode("utf-8"))
console_out.print("Rich output - from ansi", style="magenta")
err_ansi = text.Text.from_ansi(err.decode("utf-8"))
console_err.print(err_ansi)
@atexit.register
def cleanup():
os.remove(s.name)
os.remove(t.name)
Screenshot of bug:
Platform
Click to expand
Windows 10, Windows Terminal, PowerShell Core Windows 10, Windows Terminal, cmd.exeC:\> python -m rich.diagnose
โญโโโโโโโโโโโโโโโโโโโโโโโโโ <class 'rich.console.Console'> โโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ A high level console interface. โ
โ โ
โ โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ โ
โ โ <console width=138 ColorSystem.TRUECOLOR> โ โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ โ
โ โ
โ color_system = 'truecolor' โ
โ encoding = 'utf-8' โ
โ file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> โ
โ height = 37 โ
โ is_alt_screen = False โ
โ is_dumb_terminal = False โ
โ is_interactive = True โ
โ is_jupyter = False โ
โ is_terminal = True โ
โ legacy_windows = False โ
โ no_color = False โ
โ options = ConsoleOptions( โ
โ size=ConsoleDimensions(width=138, height=37), โ
โ legacy_windows=False, โ
โ min_width=1, โ
โ max_width=138, โ
โ is_terminal=True, โ
โ encoding='utf-8', โ
โ max_height=37, โ
โ justify=None, โ
โ overflow=None, โ
โ no_wrap=False, โ
โ highlight=None, โ
โ markup=None, โ
โ height=None โ
โ ) โ
โ quiet = False โ
โ record = False โ
โ safe_box = True โ
โ size = ConsoleDimensions(width=138, height=37) โ
โ soft_wrap = False โ
โ stderr = False โ
โ style = None โ
โ tab_size = 8 โ
โ width = 138 โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโโ <class 'rich._windows.WindowsConsoleFeatures'> โโโโฎ
โ Windows features available. โ
โ โ
โ โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ โ
โ โ WindowsConsoleFeatures(vt=True, truecolor=True) โ โ
โ โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ โ
โ โ
โ truecolor = True โ
โ vt = True โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโโโโโโ Environment Variables โโโโโโโโฎ
โ { โ
โ 'TERM': None, โ
โ 'COLORTERM': None, โ
โ 'CLICOLOR': None, โ
โ 'NO_COLOR': None, โ
โ 'TERM_PROGRAM': None, โ
โ 'COLUMNS': '138', โ
โ 'LINES': None, โ
โ 'JPY_PARENT_PID': None, โ
โ 'VSCODE_VERBOSE_LOGGING': None โ
โ } โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
platform="Windows"
C:\> pip freeze | findstr rich
rich==12.0.0
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top Results From Across the Web
Why unknown character appear in XML even after convert ...
I've tried your solution just now but it still didn't solve the problem. The unknown character still appear and now the output structure...
Read more >Weird escape sequence - Unix & Linux Stack Exchange
I have several screenshots with such symbols on it. It wasn't a copy/paste error. And I can reproduce this symbol now. For that...
Read more >Bug Issues Known to cause Wrong Results - OracleBlog
The aim here is to provide a list of bugs known to cause wrong results and to provide both version affected and radio...
Read more >CSV import problems with characters like รฆ รธ รฅ รถ รค รผ [#704532]
I'm having German characters like รถรครผ. The problem is: whenever I change the encoding from ansi to utf-8 it breaks the node title....
Read more >18. Known Causes of Trouble with GNU Fortran
18.1 Bugs Not In GNU Fortran ยท 18.1.9 Floating-point Errors ยท 18.1.8 Strange Behavior at Run Time ยท 18.1.7 Nothing Happens ยท 18.1.6...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Works, thanks for the fast fix.
Did I solve your problem?
Why not buy the devs a coffee to say thanks?