mirror of
https://github.com/beetbox/beets.git
synced 2026-01-08 17:08:12 +01:00
Use cross-platform shutil.get_terminal_size to get term_width
This fixes Python 3.14 incompatibility.
This commit is contained in:
parent
1ea3879aae
commit
3eb68ef830
3 changed files with 7 additions and 22 deletions
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
|
|
@ -20,7 +20,7 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
platform: [ubuntu-latest, windows-latest]
|
||||
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
|
||||
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
|
||||
runs-on: ${{ matrix.platform }}
|
||||
env:
|
||||
IS_MAIN_PYTHON: ${{ matrix.python-version == '3.9' && matrix.platform == 'ubuntu-latest' }}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ import errno
|
|||
import optparse
|
||||
import os.path
|
||||
import re
|
||||
import shutil
|
||||
import sqlite3
|
||||
import struct
|
||||
import sys
|
||||
import textwrap
|
||||
import traceback
|
||||
|
|
@ -699,27 +699,11 @@ def get_replacements():
|
|||
return replacements
|
||||
|
||||
|
||||
def term_width():
|
||||
@cache
|
||||
def term_width() -> int:
|
||||
"""Get the width (columns) of the terminal."""
|
||||
fallback = config["ui"]["terminal_width"].get(int)
|
||||
|
||||
# The fcntl and termios modules are not available on non-Unix
|
||||
# platforms, so we fall back to a constant.
|
||||
try:
|
||||
import fcntl
|
||||
import termios
|
||||
except ImportError:
|
||||
return fallback
|
||||
|
||||
try:
|
||||
buf = fcntl.ioctl(0, termios.TIOCGWINSZ, " " * 4)
|
||||
except OSError:
|
||||
return fallback
|
||||
try:
|
||||
height, width = struct.unpack("hh", buf)
|
||||
except struct.error:
|
||||
return fallback
|
||||
return width
|
||||
columns, _ = shutil.get_terminal_size(fallback=(0, 0))
|
||||
return columns if columns else config["ui"]["terminal_width"].get(int)
|
||||
|
||||
|
||||
def split_into_lines(string, width_tuple):
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ classifiers = [
|
|||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3.13",
|
||||
"Programming Language :: Python :: 3.14",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
]
|
||||
packages = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue