Skip to content
Open
Show file tree
Hide file tree
Changes from 15 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
25 changes: 17 additions & 8 deletions src/textual/drivers/linux_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,28 @@ 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:
try:
width, height = shutil.get_terminal_size()
size = os.get_terminal_size(self._file.fileno())
except (AttributeError, ValueError, OSError):
pass
width = width or 80
height = height or 25

try:
width = size.columns
height = size.lines
except NameError:
width = 80
height = 25
return width, height

def _enable_mouse_support(self) -> None:
Expand Down
25 changes: 17 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,28 @@ 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:
try:
width, height = shutil.get_terminal_size()
width, height = os.get_terminal_size(self._file.fileno())
except (AttributeError, ValueError, OSError):
pass
width = width or 80
height = height or 25

try:
width = size.columns
height = size.lines
except NameError:
width = 80
height = 25
return width, height

def _enable_mouse_support(self) -> None:
Expand Down