Skip to content
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

Bash alias command substitution window resize bug #5417

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
lap1nou marked this conversation as resolved.
Show resolved Hide resolved
return width, height

def _enable_mouse_support(self) -> None:
Expand Down
25 changes: 17 additions & 8 deletions src/textual/drivers/linux_inline_driver.py
lap1nou marked this conversation as resolved.
Show resolved Hide resolved
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