pyblock/pybitblock/shared/display.py
GaltRanch 7366e9fe9c Refactor architecture: config singleton, logging, menu system, dependencies
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>
2026-04-01 10:58:24 -03:00

56 lines
1.2 KiB
Python

"""
Shared display utilities for PyBLOCK.
These functions are used by both PyBlock.py and SPV/spvblock.py.
"""
import os
import subprocess
import sys
import time
import psutil
def clear():
subprocess.run(['clear'] if os.name != 'nt' else ['cls'], shell=(os.name == 'nt'))
def close():
print("<<< Ctrl + C.\n\n")
def sysinfo():
print(" \033[0;37;40m----------------------")
print(" \033[3;33;40mCPU Usage: \033[1;32;40m" + str(psutil.cpu_percent()) + "%\033[0;37;40m")
print(
f" \033[3;33;40mMemory Usage: \033[1;32;40m{int(psutil.virtual_memory().percent)}% \033[0;37;40m"
)
print(" \033[0;37;40m----------------------")
def rectangle(n):
x = n - 3
y = n - x
[
print(''.join(i))
for i in
(
'' * x
if i in (0, y - 1)
else
(
f'{"" * n}{"|" * n}{"" * n}'
if i >= (n + 1) / 2 and i <= (1 * n) / 2
else f'{"" * n}{"|" * n}{"" * n}'
)
for i in range(y)
)
]
def delay_print(s):
for c in s:
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(0.25)