Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 2 additions & 39 deletions icdiff
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import filecmp
import unicodedata
import codecs
import fnmatch
import shutil

__version__ = "2.0.8"

Expand Down Expand Up @@ -734,44 +735,6 @@ def create_option_parser():
return parser


def set_cols_option(options):
if os.name == "nt":
try:
import struct
from ctypes import windll, create_string_buffer

fh = windll.kernel32.GetStdHandle(-12) # stderr is -12
csbi = create_string_buffer(22)
windll.kernel32.GetConsoleScreenBufferInfo(fh, csbi)
res = struct.unpack("hhhhHhhhhhh", csbi.raw)
options.cols = res[7] - res[5] + 1 # right - left + 1
return

except Exception:
pass

else:

def ioctl_GWINSZ(fd):
try:
import fcntl
import termios
import struct

cr = struct.unpack(
"hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234")
)
except Exception:
return None
return cr

cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if cr and cr[1] > 0:
options.cols = cr[1]
return
options.cols = 80


def validate_has_two_arguments(parser, args):
if len(args) != 2:
parser.print_help()
Expand All @@ -784,7 +747,7 @@ def start():
options, args = parser.parse_args()
validate_has_two_arguments(parser, args)
if not options.cols:
set_cols_option(options)
options.cols = shutil.get_terminal_size().columns
try:
diffs_found = diff(options, *args)
except KeyboardInterrupt:
Expand Down