MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_terminal_size

Function get_terminal_size

Lib/shutil.py:1511–1554  ·  view source on GitHub ↗

Get the size of the terminal window. For each of the two dimensions, the environment variable, COLUMNS and LINES respectively, is checked. If the variable is defined and the value is a positive integer, it is used. When COLUMNS or LINES is not defined, which is the common case,

(fallback=(80, 24))

Source from the content-addressed store, hash-verified

1509 follow_symlinks=follow_symlinks)
1510
1511def get_terminal_size(fallback=(80, 24)):
1512 """Get the size of the terminal window.
1513
1514 For each of the two dimensions, the environment variable, COLUMNS
1515 and LINES respectively, is checked. If the variable is defined and
1516 the value is a positive integer, it is used.
1517
1518 When COLUMNS or LINES is not defined, which is the common case,
1519 the terminal connected to sys.__stdout__ is queried
1520 by invoking os.get_terminal_size.
1521
1522 If the terminal size cannot be successfully queried, either because
1523 the system doesn't support querying, or because we are not
1524 connected to a terminal, the value given in fallback parameter
1525 is used. Fallback defaults to (80, 24) which is the default
1526 size used by many terminal emulators.
1527
1528 The value returned is a named tuple of type os.terminal_size.
1529 """
1530 # columns, lines are the working values
1531 try:
1532 columns = int(os.environ['COLUMNS'])
1533 except (KeyError, ValueError):
1534 columns = 0
1535
1536 try:
1537 lines = int(os.environ['LINES'])
1538 except (KeyError, ValueError):
1539 lines = 0
1540
1541 # only query if necessary
1542 if columns <= 0 or lines <= 0:
1543 try:
1544 size = os.get_terminal_size(sys.__stdout__.fileno())
1545 except (AttributeError, ValueError, OSError):
1546 # stdout is None, closed, detached, or not a terminal, or
1547 # os.get_terminal_size() is unsupported
1548 size = os.terminal_size(fallback)
1549 if columns <= 0:
1550 columns = size.columns or fallback[0]
1551 if lines <= 0:
1552 lines = size.lines or fallback[1]
1553
1554 return os.terminal_size((columns, lines))
1555
1556
1557# Check that a given file can be accessed with the correct mode.

Callers

nothing calls this directly

Calls 1

filenoMethod · 0.45

Tested by

no test coverage detected