rich icon indicating copy to clipboard operation
rich copied to clipboard

live: add "tail" vertical_overflow method

Open bretello opened this issue 1 year ago • 1 comments

Type of changes

  • [ ] Bug fix
  • [x] New feature
  • [x] Documentation / docstrings
  • [x] Tests
  • [ ] Other

Checklist

  • [x] I've run the latest black with default args on new code.
  • [ ] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • [x] I've added tests for new code.
  • [x] I accept that @willmcgugan may be pedantic in the code review.

Description

This implements an alternative vertical_overflow="tail" mode for Live, behaving somehow like "crop" but only showing the trailing lines that fit the terminal height, adding an ellipsis at the top

Here is an example:

vertical_overflow_tail

bretello avatar Mar 26 '24 10:03 bretello

Here's the code used to generate the above asciicast:

from time import sleep
from rich.live import Live
from rich.console import Console

console = Console(
    height=5,
    force_terminal=True,
    legacy_windows=False,
    color_system=None,
    _environ={},
)
console.print("This is a console with height=5")

with Live(
    console=console,
    auto_refresh=False,
    vertical_overflow="tail",
) as live:
    display = ""
    for step in range(10):
        display += f"Step {step}\n"
        sleep(1)
        live.update(display, refresh=True)

bretello avatar Mar 26 '24 10:03 bretello

Im afraid I don't think this is a good idea. Consider Textual for such functionality.

https://textual.textualize.io/blog/2023/07/29/pull-requests-are-cake-or-puppies/

willmcgugan avatar Jul 01 '24 20:07 willmcgugan