Skip to content

Commit

Permalink
Use shutil.get_terminal_size for correct terminal width on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Oct 10, 2018
1 parent 796d5a0 commit 6a37603
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions py/_io/terminalwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys, os, unicodedata
import py
py3k = sys.version_info[0] >= 3
py33 = sys.version_info >= (3, 3)
from py.builtin import text, bytes

win32_and_ctypes = False
Expand All @@ -24,10 +25,15 @@


def _getdimensions():
import termios,fcntl,struct
call = fcntl.ioctl(1,termios.TIOCGWINSZ,"\000"*8)
height,width = struct.unpack( "hhhh", call ) [:2]
return height, width
if py33:
import shutil
size = shutil.get_terminal_size()
return size.lines, size.columns
else:
import termios, fcntl, struct
call = fcntl.ioctl(1, termios.TIOCGWINSZ, "\000" * 8)
height, width = struct.unpack("hhhh", call)[:2]
return height, width


def get_terminal_width():
Expand Down

0 comments on commit 6a37603

Please sign in to comment.