Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
]
},
url="https://github.com/cs50/style50",
version="2.10.4",
version="2.11.0",
include_package_data=True,
)
33 changes: 2 additions & 31 deletions style50/_api.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from abc import ABCMeta, abstractmethod
import errno
import difflib
import fcntl
import fnmatch
import html
import itertools
import json
import os
import re
import struct
import shutil
import subprocess
import sys
import tempfile
from termios import TIOCGWINSZ

import icdiff
import magic
Expand All @@ -22,34 +20,7 @@

__all__ = ["Style50", "StyleCheck", "Error"]



def get_terminal_size(fallback=(80, 24)):
"""
Return tuple containing columns and rows of controlling terminal, trying harder
than shutil.get_terminal_size to find a tty before returning fallback.

Theoretically, stdout, stderr, and stdin could all be different ttys that could
cause us to get the wrong measurements (instead of using the fallback) but the much more
common case is that IO is piped.
"""
for stream in [sys.__stdout__, sys.__stderr__, sys.__stdin__]:
try:
# Make WINSIZE call to terminal
data = fcntl.ioctl(stream.fileno(), TIOCGWINSZ, b"\x00\x00\00\x00")
except OSError:
pass
else:
# Unpack two shorts from ioctl call
lines, columns = struct.unpack("hh", data)
break
else:
columns, lines = fallback

return columns, lines


COLUMNS, LINES = get_terminal_size()
COLUMNS, LINES = shutil.get_terminal_size(fallback=(80, 24))


class Style50:
Expand Down
Loading