feat: Implement interactive font selection by scanning the fonts/ directory for .otf, .ttf, and .ttc files, adding new fonts and updating documentation.
This commit is contained in:
@@ -5,6 +5,8 @@ Configuration constants, CLI flags, and glyph tables.
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
_REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
_FONT_EXTENSIONS = {".otf", ".ttf", ".ttc"}
|
||||
|
||||
|
||||
def _arg_value(flag):
|
||||
@@ -31,8 +33,24 @@ def _resolve_font_path(raw_path):
|
||||
p = Path(raw_path).expanduser()
|
||||
if p.is_absolute():
|
||||
return str(p)
|
||||
repo_root = Path(__file__).resolve().parent.parent
|
||||
return str((repo_root / p).resolve())
|
||||
return str((_REPO_ROOT / p).resolve())
|
||||
|
||||
|
||||
def _list_font_files(font_dir):
|
||||
"""List supported font files within a font directory."""
|
||||
font_root = Path(font_dir)
|
||||
if not font_root.exists() or not font_root.is_dir():
|
||||
return []
|
||||
return [
|
||||
str(path.resolve())
|
||||
for path in sorted(font_root.iterdir())
|
||||
if path.is_file() and path.suffix.lower() in _FONT_EXTENSIONS
|
||||
]
|
||||
|
||||
|
||||
def list_repo_font_files():
|
||||
"""Public helper for discovering repository font files."""
|
||||
return _list_font_files(FONT_DIR)
|
||||
# ─── RUNTIME ──────────────────────────────────────────────
|
||||
HEADLINE_LIMIT = 1000
|
||||
FEED_TIMEOUT = 10
|
||||
@@ -46,9 +64,13 @@ NTFY_POLL_INTERVAL = 15 # seconds between polls
|
||||
MESSAGE_DISPLAY_SECS = 30 # how long a message holds the screen
|
||||
|
||||
# ─── FONT RENDERING ──────────────────────────────────────
|
||||
FONT_PATH = _resolve_font_path(
|
||||
_arg_value('--font-file')
|
||||
or "/Users/genejohnson/Documents/CS Bishop Drawn/CSBishopDrawn-Italic.otf"
|
||||
FONT_DIR = _resolve_font_path(_arg_value('--font-dir') or "fonts")
|
||||
_FONT_FILE_ARG = _arg_value('--font-file')
|
||||
_FONT_FILES = _list_font_files(FONT_DIR)
|
||||
FONT_PATH = (
|
||||
_resolve_font_path(_FONT_FILE_ARG)
|
||||
if _FONT_FILE_ARG
|
||||
else (_FONT_FILES[0] if _FONT_FILES else "")
|
||||
)
|
||||
FONT_INDEX = max(0, _arg_int('--font-index', 0))
|
||||
FONT_PICKER = '--no-font-picker' not in sys.argv
|
||||
|
||||
Reference in New Issue
Block a user