Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] OSC8 hyperlink captures padding spaces in a table cell #3491

Closed
2 tasks done
dandavison opened this issue Sep 14, 2024 · 5 comments
Closed
2 tasks done

[BUG] OSC8 hyperlink captures padding spaces in a table cell #3491

dandavison opened this issue Sep 14, 2024 · 5 comments

Comments

@dandavison
Copy link

Hi, thanks for rich!

Describe the bug

It looks like the OSC8 hyperlinks are capturing padding spaces in table cell contents. It would be nice if the hyperlink applied to the text only, with padding outside the link:

from rich.console import Console
from rich.table import Table
from rich.text import Text

console = Console()

table = Table(show_header=False)
table.add_row("Key", "I am wide I am wide I am wide")
table.add_row("Key", Text("Value", style="link http://example.com"))
console.print(table)

screenshot uses Alacritty, with cmd held down and pointer over link:

image

Platform

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?

MacOS

I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.

If you're using Rich in a terminal:

uv run python -m rich.diagnose
uv pip freeze | grep rich
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=214 None>                                                     │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = None                                                          │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 59                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = False                                                         │
│       is_jupyter = False                                                         │
│      is_terminal = False                                                         │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=214, height=59),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=214,                                            │
│                        is_terminal=False,                                        │
│                        encoding='utf-8',                                         │
│                        max_height=59,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=214, height=59)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 214                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'screen-256color',     │
│     'COLORTERM': 'truecolor',      │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': 'tmux',        │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Darwin"
rich==13.8.0
Copy link

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

@dandavison
Copy link
Author

I see that this alternative link syntax doesn't have the same problem:

table.add_row("Key", "[link=http://example.com]Value[/link]")

@willmcgugan
Copy link
Collaborator

This is the expected behavior. The style attribute will apply to the entire cell. If you want to apply a style to specific parts of the text you can use console markup, or Text.stylize

@dandavison
Copy link
Author

Great, thanks.

Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants