Skip to content

Commit 0f81cd1

Browse files
authored
Remove eyed3.utils.console.getTtySize() implementation (#682)
`shutil.get_terminal_size()` was added in Python 3.3, use it instead. Fixes #680
1 parent 00e7faf commit 0f81cd1

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

eyed3/__regarding__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class Version:
2222

2323

2424
project_name = "eyeD3"
25-
version = "0.9.8"
25+
version = "0.9.9.dev0"
2626
version_info = Version(
27-
0, 9, 8,
28-
None,
27+
0, 9, 9,
28+
0,
2929
None,
3030
None,
3131
"Armed & Dangerous",
@@ -35,7 +35,7 @@ class Version:
3535
author_email = "[email protected]"
3636
years = "2002-2025"
3737
description = "Python audio data toolkit (ID3 and MP3)"
38-
homepage = "https://eyeD3.nicfit.net/"
38+
homepage = "https://eyed3.readthedocs.io/"
3939

4040

4141
def versionBanner() -> str:

eyed3/plugins/classic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import os
22
import re
33
import dataclasses
4+
import shutil
45
from functools import partial
56
from argparse import ArgumentTypeError
67

78
from eyed3.plugins import LoaderPlugin
89
from eyed3 import core, id3, mp3
910
from eyed3.utils import makeUniqueFileName, b, formatTime
1011
from eyed3.utils.console import (
11-
printMsg, printError, printWarning, boldText, getTtySize,
12+
printMsg, printError, printWarning, boldText,
1213
)
1314
from eyed3.id3.frames import ImageFrame
1415
from eyed3.mimetype import guessMimetype
@@ -444,7 +445,7 @@ def handleFile(self, f):
444445
if not self.audio_file:
445446
return
446447

447-
self.terminal_width = getTtySize()[1]
448+
self.terminal_width = shutil.get_terminal_size()[1]
448449
self.printHeader(f)
449450

450451
if self.audio_file.tag and self.handleRemoves(self.audio_file.tag):

eyed3/plugins/lameinfo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import math
2+
import shutil
3+
24
from eyed3.utils import formatSize
3-
from eyed3.utils.console import printMsg, getTtySize
5+
from eyed3.utils.console import printMsg
46
from eyed3.plugins import LoaderPlugin
57

68

@@ -16,7 +18,7 @@ class LameInfoPlugin(LoaderPlugin):
1618
)
1719

1820
def printHeader(self, file_path):
19-
w = getTtySize()[1]
21+
w = shutil.get_terminal_size()[1]
2022
printMsg(self._getFileHeader(file_path, w))
2123
printMsg(self._getHardRule(w))
2224

eyed3/utils/console.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import os
2-
import struct
32
import sys
43
import time
54
import typing
5+
import shutil
66
from typing import Union
77

8+
import deprecation
9+
from ..__about__ import __version__
10+
811
try:
9-
import fcntl
10-
import termios
1112
import signal
1213
_CAN_RESIZE_TERMINAL = True
1314
except ImportError:
@@ -277,8 +278,7 @@ def __init__(self, total_or_items: Union[int, typing.Sequence], file=None):
277278
self.update(0)
278279

279280
def _handle_resize(self, signum=None, frame=None):
280-
self._terminal_width = getTtySize(self._file,
281-
self._should_handle_resize)[1]
281+
self._terminal_width = shutil.get_terminal_size()[1]
282282

283283
def __enter__(self):
284284
return self
@@ -469,21 +469,10 @@ def cformat(msg, fg, bg=None, styles=None):
469469
return output
470470

471471

472+
@deprecation.deprecated(deprecated_in="0.9.9", removed_in="1.0", current_version=__version__,
473+
details="Use shutil.get_terminal_size() instead.")
472474
def getTtySize(fd=sys.stdout, check_tty=True):
473-
hw = None
474-
if check_tty:
475-
try:
476-
data = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 4)
477-
hw = struct.unpack("hh", data)
478-
except (OSError, NameError):
479-
pass
480-
if not hw:
481-
try:
482-
hw = (int(os.environ.get('LINES')),
483-
int(os.environ.get('COLUMNS')))
484-
except (TypeError, ValueError):
485-
hw = (25, 79)
486-
return hw
475+
return shutil.get_terminal_size() # Added in Python 3.3
487476

488477

489478
def cprint(msg, fg, bg=None, styles=None, file=sys.stdout):

0 commit comments

Comments
 (0)