Skip to content

Commit fde10a7

Browse files
coolreader18jonathanslenders
authored andcommitted
Use os.get_terminal_size for vt100._get_size
1 parent ed1e2f1 commit fde10a7

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

prompt_toolkit/output/vt100.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -375,30 +375,14 @@ def get(color: str, bg: bool) -> List[int]:
375375

376376

377377
def _get_size(fileno: int) -> Tuple[int, int]:
378-
# Thanks to fabric (fabfile.org), and
379-
# http://sqizit.bartletts.id.au/2011/02/14/pseudo-terminals-in-python/
380378
"""
381379
Get the size of this pseudo terminal.
382380
383381
:param fileno: stdout.fileno()
384382
:returns: A (rows, cols) tuple.
385383
"""
386-
# Inline imports, because these modules are not available on Windows.
387-
# (This file is used by ConEmuOutput, which is used on Windows.)
388-
import fcntl
389-
import termios
390-
391-
# Buffer for the C call
392-
buf = array.array("h", [0, 0, 0, 0])
393-
394-
# Do TIOCGWINSZ (Get)
395-
# Note: We should not pass 'True' as a fourth parameter to 'ioctl'. (True
396-
# is the default.) This causes segmentation faults on some systems.
397-
# See: https://github.com/jonathanslenders/python-prompt-toolkit/pull/364
398-
fcntl.ioctl(fileno, termios.TIOCGWINSZ, buf)
399-
400-
# Return rows, cols
401-
return buf[0], buf[1]
384+
size = os.get_terminal_size(fileno)
385+
return size.lines, size.columns
402386

403387

404388
class Vt100_Output(Output):

0 commit comments

Comments
 (0)