Skip to content

Conversation

wsxrdv
Copy link

@wsxrdv wsxrdv commented Oct 2, 2025

The function shutil.get_terminal_size returns environment variables COLUMNS and LINES when those exist. But this information is stale after resizing the terminal. First try to retrieve from os.get_terminal_size and only after fall back to shutil.

Please review the following checklist.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)
The function `shutil.get_terminal_size` returns environment variables `COLUMNS` and `LINES` when those exist. But this information is stale after resizing the terminal. First try to retrieve from `os.get_terminal_size` and only after fall back to `shutil`.
@wsxrdv
Copy link
Author

wsxrdv commented Oct 2, 2025

Previous version of src/textual/drivers/linux_driver.py had os.get_terminal_size but was changed by d1235e0 All other changes I found were directly adding the shutil version.

@wsxrdv
Copy link
Author

wsxrdv commented Oct 2, 2025

This change allows proper reactivity to resize on Ubuntu inside tmux. One can also test these changes using the following script while resizing:

import os import shutil import time while True: # os.get_terminal_size changes with resize # shutil.get_terminal_size uses env variables (is constant) print(f"{os.get_terminal_size() = } {shutil.get_terminal_size() = }") time.sleep(1)
@wsxrdv wsxrdv marked this pull request as ready for review October 2, 2025 17:51
@wsxrdv
Copy link
Author

wsxrdv commented Oct 2, 2025

@wsxrdv
Copy link
Author

wsxrdv commented Oct 3, 2025

I tried to dig deeper:

  • Debian 13 seems that neither COLUMNS nor LINES are present in Python os.environ and thus shutil is giving always the correct result.
  • Jupyterlab shell with tmux run inside from a tensorflow/tensorflow:latest-gpu docker seems to have both COLUMNS and LINES in the os.environ and thus shutil gives the wrong result.
  • Possible workaround (without changing textual) is removing COLUMNS and LINES from os.environ before starting the app:
for d in ["LINES", "COLUMNS"]: if d in os.environ: del os.environ[d]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant