Repository navigation
Replies: 1 comment
|
Worth knowing before implementing this: What the code actually does (rich 15.0.0,
if self._link and not legacy_windows:
rendered = (
f"\x1b]8;id={self._link_id};{self._link}\x1b\\{rendered}\x1b]8;;\x1b\\"
)and
Reproduced with Workaround that works today, using the primitive rich already has — from rich.console import Console
from rich.segment import Segment
class NoLinkConsole(Console):
def _render_buffer(self, buffer):
return super()._render_buffer(Segment.strip_links(buffer))With that Console in your script, # osc8strip.py
import re, sys
OSC8 = re.compile("\x1b]8;[^\x1b]*\x1b\\\\")
sys.stdout.write(OSC8.sub("", sys.stdin.read()))Patch shape for the feature itself (mirrors the
self.hyperlinks = (
hyperlinks
if hyperlinks is not None
else self._environ.get("NO_HYPERLINKS", "") == ""
or "FORCE_HYPERLINKS" in self._environ
)
if not self.hyperlinks:
buffer = Segment.strip_links(buffer)Use |
Uh oh!
There was an error while loading. Please reload this page.
Rich already supports NO_COLOR/FORCE_COLOR environment variables, which is very nice. Currently these also affect hyperlinks.
I would like Rich to also support NO_HYPERLINKS/FORCE_HYPERLINKS, as specified by https://no-hyperlinks.org.
My reason: there are situations where I want color but don't want hyperlinks. Specifically, the very nice Unix
watchutility supports color, but does not support hyperlinks. If I runto see the tail end of my nicely formatted script output, I lose color. I can do
but watch mishandles OSC 8 and fills my screen with
]8;id=1234567;https://example.com\link text]8;;\.Being able to
would solve this until procps (and, apparently, ncurses) add support for OSC 8.
All reactions