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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Fixed `Pilot.click` not working with `times` parameter https://github.com/Textualize/textual/pull/5398
- Fixed terminal resize when standard output is not a tty: pipe (e.g. shell command substitution), regular file, /dev/null, etc https://github.com/Textualize/textual/pull/5417

### Added

Expand Down
30 changes: 22 additions & 8 deletions src/textual/drivers/linux_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,33 @@ def _get_terminal_size(self) -> tuple[int, int]:
Returns:
The size of the terminal as a tuple of (WIDTH, HEIGHT).
"""
width: int | None = 80
height: int | None = 25
import shutil
try:
width = int(os.environ['COLUMNS'])
except (KeyError, ValueError):
width = 0

try:
width, height = shutil.get_terminal_size()
except (AttributeError, ValueError, OSError):
height = int(os.environ['LINES'])
except (KeyError, ValueError):
height = 0

if width <= 0 or height <= 0:
# LINES and COLUMNS do not fully define terminal size: query the tty to get its actual size:
try:
width, height = shutil.get_terminal_size()
size = os.get_terminal_size(self._file.fileno())
if width <= 0:
width = size.columns
if height <= 0:
height = size.lines
except (AttributeError, ValueError, OSError):
pass
width = width or 80
height = height or 25

# Default to the de facto standard terminal size:
if width <= 0:
width = 80
if height <= 0:
height = 25

return width, height

def _enable_mouse_support(self) -> None:
Expand Down
30 changes: 22 additions & 8 deletions src/textual/drivers/linux_inline_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,33 @@ def _get_terminal_size(self) -> tuple[int, int]:
Returns:
The size of the terminal as a tuple of (WIDTH, HEIGHT).
"""
width: int | None = 80
height: int | None = 25
import shutil
try:
width = int(os.environ['COLUMNS'])
except (KeyError, ValueError):
width = 0

try:
width, height = shutil.get_terminal_size()
except (AttributeError, ValueError, OSError):
height = int(os.environ['LINES'])
except (KeyError, ValueError):
height = 0

if width <= 0 or height <= 0:
# LINES and COLUMNS do not fully define terminal size: query the tty to get its actual size:
try:
width, height = shutil.get_terminal_size()
size = os.get_terminal_size(self._file.fileno())
if width <= 0:
width = size.columns
if height <= 0:
height = size.lines
except (AttributeError, ValueError, OSError):
pass
width = width or 80
height = height or 25

# Default to the de facto standard terminal size:
if width <= 0:
width = 80
if height <= 0:
height = 25

return width, height

def _enable_mouse_support(self) -> None:
Expand Down