https://github.com/thecodetherapy/terminal_size
Small Python snippet that aims to detect your terminal emulator dimensions on any platform (Windows, Mac, Linux, tput, CYGWIN, your toaster, etc.)
https://github.com/thecodetherapy/terminal_size
Last synced: 6 months ago
JSON representation
Small Python snippet that aims to detect your terminal emulator dimensions on any platform (Windows, Mac, Linux, tput, CYGWIN, your toaster, etc.)
- Host: GitHub
- URL: https://github.com/thecodetherapy/terminal_size
- Owner: TheCodeTherapy
- License: mit
- Created: 2019-01-29T22:33:49.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-29T22:35:16.000Z (about 7 years ago)
- Last Synced: 2025-01-08T11:49:24.903Z (about 1 year ago)
- Language: Python
- Size: 1.95 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# terminal_size
## What?
terminal_size is a small Python snippet that aims to detect any terminal emulator size on any platform (Windows, Mac, Linux, tput, CYGWIN, your toaster, etc.). If successful, its main function **get_terminal_size()** returns a tuple composed by two values, representing respectively the width and the height of the terminal emulator in which your code is running.
## How?
Usage:
```
from terminal_size import get_terminal_size
term_size = get_terminal_size()
```
The types returned to term_size in the usage case above can be **tuple** (if size was successfully detected) or **None** (in case the code could not detect the dimensions successfully).
You can test its return with:
```
isinstance(term_size, tuple) and len(term_size) == 2
```
Any other weird stuff that may happen during the detection attempt will simply break and raise.