Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Added

- Fixed `Live(transient=True)` leaving a blank line when the renderable produces no output.


# Changelog

All notable changes to this project will be documented in this file.
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ The following people have contributed to the development of Rich:
- [Jonathan Helmus](https://github.com/jjhelmus)
- [Brandon Capener](https://github.com/bcapener)
- [Alex Zheng](https://github.com/alexzheng111)
- [Mohammed Faheem](https://github.com/Faheem12005)
6 changes: 5 additions & 1 deletion rich/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ def stop(self) -> None:
finally:
self._disable_redirect_io()
self.console.pop_render_hook()
if not self._alt_screen and self.console.is_terminal:
if (
not self._alt_screen
and self.console.is_terminal
and self._live_render.has_rendered_rows()
):
self.console.line()
self.console.show_cursor(True)
if self._alt_screen:
Expand Down
14 changes: 12 additions & 2 deletions rich/live_render.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Optional, Tuple, Literal

from typing import Literal, Optional, Tuple

from ._loop import loop_last
from .console import Console, ConsoleOptions, RenderableType, RenderResult
Expand Down Expand Up @@ -59,6 +58,17 @@ def position_cursor(self) -> Control:
)
return Control()

def has_rendered_rows(self) -> bool:
"""Check if there are any rendered rows.

Returns:
bool: True if there are rendered rows, False otherwise.
"""
if self._shape is not None:
_, height = self._shape
return height > 0
return False

def restore_cursor(self) -> Control:
"""Get control codes to clear the render and restore the cursor to its previous position.

Expand Down
13 changes: 11 additions & 2 deletions tests/test_live_render.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
from rich.live_render import LiveRender

from rich.console import Console, ConsoleDimensions, ConsoleOptions
from rich.style import Style
from rich.live_render import LiveRender
from rich.segment import Segment
from rich.style import Style


@pytest.fixture
Expand All @@ -28,6 +29,14 @@ def test_restore_cursor(live_render):
assert str(live_render.restore_cursor()) == "\r\x1b[1A\x1b[2K\x1b[1A\x1b[2K"


def test_has_rendered_rows(live_render):
assert live_render.has_rendered_rows() is False
live_render._shape = (80, 0)
assert live_render.has_rendered_rows() is False
live_render._shape = (80, 1)
assert live_render.has_rendered_rows() is True


def test_rich_console(live_render):
options = ConsoleOptions(
ConsoleDimensions(80, 25),
Expand Down