Skip to content

Add a vertical_overflow='crop_above' as an option to Live() #3637

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [UNRELEASED]

### Added

- `Live()`'s `visible_overflow` argument gains a new option of `"crop_above"`
https://github.com/Textualize/rich/pull/3637

## [13.9.4] - 2024-11-01

Expand Down
5 changes: 4 additions & 1 deletion rich/live_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .style import StyleType
from .text import Text

VerticalOverflowMethod = Literal["crop", "ellipsis", "visible"]
VerticalOverflowMethod = Literal["crop", "crop_above", "ellipsis", "visible"]


class LiveRender:
Expand Down Expand Up @@ -92,6 +92,9 @@ def __rich_console__(
if self.vertical_overflow == "crop":
lines = lines[: options.size.height]
shape = Segment.get_shape(lines)
elif self.vertical_overflow == "crop_above":
lines = lines[-(options.size.height) :]
shape = Segment.get_shape(lines)
elif self.vertical_overflow == "ellipsis":
lines = lines[: (options.size.height - 1)]
overflow_text = Text(
Expand Down