blessings is now a dependency

This commit is contained in:
dece 2022-11-28 18:34:25 +01:00
parent 76d2acf8a9
commit 6f83747699
3 changed files with 12 additions and 15 deletions

View file

@ -1,3 +1,6 @@
[build-system] [build-system]
requires = ["setuptools", "wheel"] requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[tool.mypy]
ignore_missing_imports = true

View file

@ -16,6 +16,7 @@ classifiers =
packages = tlfi packages = tlfi
python_requires = >= 3.7 python_requires = >= 3.7
setup_requires = setuptools >= 38.3.0 setup_requires = setuptools >= 38.3.0
install_requires = blessings ~= 1.6
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =

View file

@ -15,17 +15,10 @@ import sys
from pathlib import Path from pathlib import Path
from typing import Generator from typing import Generator
from blessings import Terminal
from bs4 import BeautifulSoup, NavigableString from bs4 import BeautifulSoup, NavigableString
try: T = Terminal()
from blessings import Terminal
t = Terminal()
except ImportError:
class DummyTerminal:
def __getattr__(self, _):
return ""
t = DummyTerminal()
TAG_STRIP_RE = re.compile(r"\s+") TAG_STRIP_RE = re.compile(r"\s+")
@ -84,17 +77,17 @@ def parse_tag(tag) -> str:
if tag.name == "span": if tag.name == "span":
classes = tag.get("class") or [] classes = tag.get("class") or []
if "tlf_cdefinition" in classes: if "tlf_cdefinition" in classes:
content = f"{t.yellow}{content}{t.normal}" content = f"{T.yellow}{content}{T.normal}"
if "tlf_cdomaine" in classes: if "tlf_cdomaine" in classes:
content = f"{t.red}{content}{t.normal}" content = f"{T.red}{content}{T.normal}"
if "tlf_csyntagme" in classes: if "tlf_csyntagme" in classes:
content = f"{t.green}{content}{t.normal}" content = f"{T.green}{content}{T.normal}"
if "tlf_cmot" in classes: if "tlf_cmot" in classes:
content = f"{t.reverse}{content}{t.normal}" content = f"{T.reverse}{content}{T.normal}"
if tag.name == "b": if tag.name == "b":
content = f"{t.bold}{content}{t.normal}" content = f"{T.bold}{content}{T.normal}"
if tag.name == "i": if tag.name == "i":
content = f"{t.italic}{content}{t.no_italic}" content = f"{T.italic}{content}{T.no_italic}"
return content return content