Skip to content

Conversation

@SergeyNoritsyn
Copy link

Title:

Add enable_link_path parameter to disable OSC 8 hyperlinks

Description:

## Problem
Fixes #3896

In Jupyter notebooks and remote server environments, OSC 8 hyperlinks generated by `console.log()` cause issues:
- Large vertical spacing in Jupyter due to HTML block rendering
- Visible escape sequences when using `force_jupyter=False`
- Hyperlinks are not useful when file paths don't exist on client machines

Previously, the only workaround was to 'monkey-patch' the private `_log_render` method.

## Solution
Added a new `enable_link_path` parameter to the `Console` class:
- Defaults to `True` (backward compatible - existing behavior unchanged)
- When set to `False`, disables OSC 8 hyperlink generation
- File path text is still displayed (only the escape codes are removed)

## Example Usage
```python
from rich.console import Console

# For Jupyter notebooks or remote servers
console = Console(
    force_jupyter=False,
    enable_link_path=False,  # Disable hyperlinks
    log_time=True,
    log_path=True
)

console.log("Clean output without OSC 8 escape sequences")

Testing

  • Added test_enable_link_path() - verifies hyperlinks are disabled
  • Added test_enable_link_path_default() - verifies default behavior unchanged
  • All existing tests pass

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant