Skip to content

Commit 3e132aa

Browse files
committed
fix cols default on macOS
1 parent ee4643a commit 3e132aa

File tree

1 file changed

+2
-39
lines changed

1 file changed

+2
-39
lines changed

icdiff

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import filecmp
2424
import unicodedata
2525
import codecs
2626
import fnmatch
27+
import shutil
2728

2829
__version__ = "2.0.8"
2930

@@ -734,44 +735,6 @@ def create_option_parser():
734735
return parser
735736

736737

737-
def set_cols_option(options):
738-
if os.name == "nt":
739-
try:
740-
import struct
741-
from ctypes import windll, create_string_buffer
742-
743-
fh = windll.kernel32.GetStdHandle(-12) # stderr is -12
744-
csbi = create_string_buffer(22)
745-
windll.kernel32.GetConsoleScreenBufferInfo(fh, csbi)
746-
res = struct.unpack("hhhhHhhhhhh", csbi.raw)
747-
options.cols = res[7] - res[5] + 1 # right - left + 1
748-
return
749-
750-
except Exception:
751-
pass
752-
753-
else:
754-
755-
def ioctl_GWINSZ(fd):
756-
try:
757-
import fcntl
758-
import termios
759-
import struct
760-
761-
cr = struct.unpack(
762-
"hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234")
763-
)
764-
except Exception:
765-
return None
766-
return cr
767-
768-
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
769-
if cr and cr[1] > 0:
770-
options.cols = cr[1]
771-
return
772-
options.cols = 80
773-
774-
775738
def validate_has_two_arguments(parser, args):
776739
if len(args) != 2:
777740
parser.print_help()
@@ -784,7 +747,7 @@ def start():
784747
options, args = parser.parse_args()
785748
validate_has_two_arguments(parser, args)
786749
if not options.cols:
787-
set_cols_option(options)
750+
options.cols = shutil.get_terminal_size().columns
788751
try:
789752
diffs_found = diff(options, *args)
790753
except KeyboardInterrupt:

0 commit comments

Comments
 (0)