mirror of
https://github.com/curly60e/pyblock.git
synced 2026-08-14 12:43:15 +02:00
Major improvements across 7 areas: - Add centralized Config singleton (config.py) replacing ~176 config reloads per session with a single cached load - Add logging framework (log.py) with RotatingFileHandler, replacing silent except Exception: pass blocks with structured logging - Refactor menu system (menu.py) with data-driven color selection, eliminating ~1,370 lines of duplicate menu functions - Create shared/ modules extracting 7 utility functions duplicated between PyBlock.py and SPV/spvblock.py - Clean dependencies: pin all versions, remove stdlib packages (asyncio, threading), remove unused imports - Improve Docker: pin ubuntu:24.04, add non-root user, use venv - Improve CI: update to actions v4/v5, add test job before publish - Fix entry point: wrap main loop in def main(), proper module import Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
17 lines
480 B
Python
17 lines
480 B
Python
"""
|
|
Shared color and formatting utilities for PyBLOCK.
|
|
|
|
Used by both PyBlock.py and SPV/spvblock.py for ANSI color rendering.
|
|
"""
|
|
|
|
|
|
def get_ansi_color_code(r, g, b):
|
|
if r == g == b:
|
|
if r < 8:
|
|
return 16
|
|
return 231 if r > 248 else round(((r - 8) / 247) * 24) + 232
|
|
return 16 + (36 * round(r / 255 * 5)) + (6 * round(g / 255 * 5)) + round(b / 255 * 5)
|
|
|
|
|
|
def get_color(r, g, b):
|
|
return f"\x1b[48;5;{int(get_ansi_color_code(r, g, b))}m \x1b[0m"
|