mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 10:58:52 -06:00
refactor: keep detection lines as data
Detection now keeps what it says in DETECTION_NOTES and prints it only in line mode. The full screen reads the list under detection_held() instead of capturing stdout and stderr and dropping refusals by comparing text, which said a refusal twice once screen_text escaped its folder.
This commit is contained in:
1 parent
36d5827b25
commit
4cb82adce3
12 files changed
+148
-44
No files matched your search
@@ -0,0 +1,39 @@
|
||||
"""What detection says, kept as lines the screen reads and printed as it comes in line mode."""
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import sys
|
||||
from collections.abc import Iterator
|
||||
from typing import TextIO
|
||||
|
||||
# Each line detection said, in order, other than a folder it could not look
|
||||
# in (_DETECTION_REFUSED keeps those): a system found with no folder, a
|
||||
# configuration naming a folder nobody can type, an Android folder out of
|
||||
# reach, a card that fits two systems.
|
||||
DETECTION_NOTES: list[str] = []
|
||||
# Set while the full screen runs detection: it shows the notes and the
|
||||
# refusals itself, and a line printed under it would tear the screen.
|
||||
_HELD = {"active": False}
|
||||
|
||||
|
||||
def echo_detection(line: str, stream: TextIO | None = None) -> None:
|
||||
"""Print a line detection says, unless the screen shows it itself."""
|
||||
if not _HELD["active"]:
|
||||
print(line, file=stream if stream is not None else sys.stderr)
|
||||
|
||||
|
||||
def note_detection(line: str, stream: TextIO | None = None) -> None:
|
||||
"""Keep a line detection says, and print it in line mode."""
|
||||
DETECTION_NOTES.append(line)
|
||||
echo_detection(line, stream)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def detection_held() -> Iterator[None]:
|
||||
"""Detection that keeps its lines without printing them."""
|
||||
outer = _HELD["active"]
|
||||
_HELD["active"] = True
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
_HELD["active"] = outer
|
||||
Reference in new issue
Block a user