Skip to content

Commit

Permalink
Use shutil.get_terminal_size(); requires python 3.3
Browse files Browse the repository at this point in the history
Python 3.3 was released in September 2012 and end of life in September
2017.
  • Loading branch information
ymattw committed Nov 10, 2024
1 parent 7084dfb commit 0b4713e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Ydiff
Term based tool to view *colored*, *incremental* diff in a version controlled
workspace (supports Git, Mercurial, Perforce and Svn so far) or from stdin,
with *side by side* (similar to ``diff -y``) and *auto pager* support. Requires
python >= 3.0 and ``less`` as a pager.
python >= 3.3 and ``less`` as a pager.

See screenshots below.

Expand Down
16 changes: 4 additions & 12 deletions ydiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
"""

import difflib
import fcntl
import os
import re
import shutil
import signal
import struct
import subprocess
import sys
import termios
Expand All @@ -29,8 +28,8 @@
'stdin, with side by side and auto pager support')
}

if sys.hexversion < 0x03000000:
raise SystemExit('*** Requires python >= 3.0.0') # pragma: no cover
if sys.hexversion < 0x03030000:
raise SystemExit('*** Requires python >= 3.3.0') # pragma: no cover


class Color(object):
Expand Down Expand Up @@ -710,15 +709,8 @@ def decode(octets):


def terminal_width():
"""Returns terminal width. Taken from https://gist.github.com/marsam/7268750
but removed win32 support which depends on 3rd party extension. Will raise
IOError or AttributeError when impossible to detect.
"""
s = struct.pack('HHHH', 0, 0, 0, 0)
try:
x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
_, width = struct.unpack('HHHH', x)[0:2] # height unused
return width
return shutil.get_terminal_size().columns
except Exception:
return 80

Expand Down

0 comments on commit 0b4713e

Please sign in to comment.