rich
rich copied to clipboard
[BUG] significantly changes the text to be printed. [v13.7.0]
- [x] I've checked docs and closed issues for possible solutions.
- [x] I can't find my issue in the FAQ.
Describe the bug
python3 -c 'import rich; rich.get_console().print(open("man.1", "rt").read())'
And this is what I get:
MAN(1) General Commands Manual MAN(1)
NNAAMMEE
mmaann, aapprrooppooss, wwhhaattiiss – display online manual documentation pages
SSYYNNOOPPSSIISS
mmaann [--aaddhhoo] [--tt | --ww] [--MM _m_a_n_p_a_t_h] [--PP _p_a_g_e_r] [--SS _m_a_n_s_e_c_t]
[--mm _a_r_c_h[:_m_a_c_h_i_n_e]] [--pp [_e_p_r_t_v]] [_m_a_n_s_e_c_t] _p_a_g_e _._._.
mmaann --ff [--dd] [--MM _m_a_n_p_a_t_h] [--PP _p_a_g_e_r] [--SS _m_a_n_s_e_c_t] _k_e_y_w_o_r_d _._._.
wwhhaattiiss [--dd] [--ss _m_a_n_s_e_c_t] _k_e_y_w_o_r_d _._._.
mmaann --kk [--dd] [--MM _m_a_n_p_a_t_h] [--PP _p_a_g_e_r] [--SS _m_a_n_s_e_c_t] _k_e_y_w_o_r_d _._._.
aapprrooppooss [--dd] [--ss _m_a_n_s_e_c_t] _k_e_y_w_o_r_d _._._.
DDEESSCCRRIIPPTTIIOONN
The mmaann utility finds and displays online manual documentation pages. If
_m_a_n_s_e_c_t is provided, mmaann restricts the search to the specific section of
the manual.
Specifying markup=False
to console.print
does not make any difference.
The original document content looks like this:
MAN(1) General Commands Manual MAN(1)
NAME
man, apropos, whatis – display online manual documentation pages
SYNOPSIS
man [-adho] [-t | -w] [-M manpath] [-P pager] [-S mansect]
[-m arch[:machine]] [-p [eprtv]] [mansect] page ...
man -f [-d] [-M manpath] [-P pager] [-S mansect] keyword ...
whatis [-d] [-s mansect] keyword ...
man -k [-d] [-M manpath] [-P pager] [-S mansect] keyword ...
apropos [-d] [-s mansect] keyword ...
DESCRIPTION
The man utility finds and displays online manual documentation pages. If
mansect is provided, man restricts the search to the specific section of
the manual.
I got this original text by man man > man.1
.
Mac OS 14.0. Found this issue in Terminal.
If you're using Rich in a terminal:
python3 -m rich.diagnoze
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface. │
│ │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=202 ColorSystem.EIGHT_BIT> │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ color_system = '256' │
│ encoding = 'utf-8' │
│ file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│ height = 53 │
│ 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=202, height=53), │
│ legacy_windows=False, │
│ min_width=1, │
│ max_width=202, │
│ is_terminal=True, │
│ encoding='utf-8', │
│ max_height=53, │
│ justify=None, │
│ overflow=None, │
│ no_wrap=False, │
│ highlight=None, │
│ markup=None, │
│ height=None │
│ ) │
│ quiet = False │
│ record = False │
│ safe_box = True │
│ size = ConsoleDimensions(width=202, height=53) │
│ soft_wrap = False │
│ stderr = False │
│ style = None │
│ tab_size = 8 │
│ width = 202 │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available. │
│ │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│ │
│ truecolor = False │
│ vt = False │
╰───────────────────────────────────────────────────────╯
╭──────── Environment Variables ────────╮
│ { │
│ 'TERM': 'xterm-256color', │
│ 'COLORTERM': None, │
│ 'CLICOLOR': None, │
│ 'NO_COLOR': None, │
│ 'TERM_PROGRAM': 'Apple_Terminal', │
│ 'COLUMNS': None, │
│ 'LINES': None, │
│ 'JUPYTER_COLUMNS': None, │
│ 'JUPYTER_LINES': None, │
│ 'JPY_PARENT_PID': None, │
│ 'VSCODE_VERBOSE_LOGGING': None │
│ } │
╰───────────────────────────────────────╯
platform="Darwin"
Thank you for your issue. Give us a little time to review it.
PS. You might want to check the FAQ if you haven't done so already.
This is an automated reply, generated by FAQtory
This issue is not found on Linux (Debian unstable), with both rich 13.3.1 and 13.7.0. Maybe apple has done some good job here.
The bold and underlined formatting you see in man pages is produced using backspace (BS) control characters. This harks back to the days of the typewriter, where to make text bold you would print a character, backspace, and then print it again. For underlined text you would print an underscore, backspace, and then print the character.
It looks like this backspace is not being interpreted in the print output, so the bold text has these duplicated characters and underlined text includes the underscores. I'm not familiar enough yet with Rich to explain why you're seeing this only on macOS but not Linux though...
You probably want to strip these BS control characters from your document:
man man | col -b > out.txt
On MacOS 14.0 copying and pasting the text to a document named man.1
did not reproduced the error but creating the document using man man > man.1
did.
Using vim, we can see that the document created by man man > man.1
has some unique characters added (not sure what it means but seems to be related to what @TomJGooding mentioned)