From ab427b30a2ddda63917869867863c0ee7022bbad Mon Sep 17 00:00:00 2001 From: LittleLightLittleFire Date: Tue, 3 Mar 2026 11:07:19 +1100 Subject: [PATCH 1/2] Fixes terminal size --- style50/_api.py | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/style50/_api.py b/style50/_api.py index 8d9d96b..91102e1 100644 --- a/style50/_api.py +++ b/style50/_api.py @@ -22,34 +22,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 = os.get_terminal_size() class Style50: From 8fc3e3a6a2428329fe543410f25788b51d0dc5f9 Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Tue, 17 Mar 2026 21:05:52 +0800 Subject: [PATCH 2/2] Update version to 2.11.0 and fix terminal size retrieval method --- setup.py | 2 +- style50/_api.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index b224271..d366b66 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,6 @@ ] }, url="https://github.com/cs50/style50", - version="2.10.4", + version="2.11.0", include_package_data=True, ) diff --git a/style50/_api.py b/style50/_api.py index 91102e1..a1779d4 100644 --- a/style50/_api.py +++ b/style50/_api.py @@ -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 @@ -22,7 +20,7 @@ __all__ = ["Style50", "StyleCheck", "Error"] -COLUMNS, LINES = os.get_terminal_size() +COLUMNS, LINES = shutil.get_terminal_size(fallback=(80, 24)) class Style50: