mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
fix: ask folder questions through one reader
The copy question, the card question and the BIOS folder question each read q, Enter, a listed number or a folder. With no drive listed, the copy question took "2" as the folder ./2. They share one reader now, and the y/N questions read only y or yes: "yeah" created folders.
This commit is contained in:
1 parent
1f215f1732
commit
7b89a558ff
10 files changed
+127
-130
No files matched your search
+27
-1
@@ -9,7 +9,7 @@ from pathlib import Path
|
||||
from typing import Any, TextIO
|
||||
|
||||
from installer.events import EVENTS, EVENT_PROGRESS_INTERVAL
|
||||
from installer.host_fs import _host_path
|
||||
from installer.host_fs import _host_path, _is_dir
|
||||
from installer.terminal import TUI_MIN_COLS, Terminal, terminal_size
|
||||
from installer.text import _split_word, cell_width, format_duration, format_size
|
||||
|
||||
@@ -275,6 +275,32 @@ def _answer_yes(prompt: str) -> bool:
|
||||
return _ask(prompt).strip().lower() in ("y", "yes")
|
||||
|
||||
|
||||
def _folder_answer(prompt: str, usage: str, default: bool, numbers: int = 0) -> str | None:
|
||||
"""A folder question's answer: None for Enter on a default, else the
|
||||
text typed. q quits as at every other question, a folder named q being
|
||||
typed ./q: q was a folder created in the current one and filled. Enter
|
||||
with no default, or a number out of range that names no folder, says
|
||||
what to type: the question came back with no word."""
|
||||
while True:
|
||||
raw = _ask(prompt)
|
||||
if not raw:
|
||||
if default:
|
||||
return None
|
||||
print(usage)
|
||||
continue
|
||||
if raw.lower() == "q":
|
||||
_quit()
|
||||
if raw.isdigit() and not 1 <= int(raw) <= numbers and not _is_dir(_typed_folder(raw)):
|
||||
print(usage)
|
||||
continue
|
||||
return raw
|
||||
|
||||
|
||||
def _numbers_hint(count: int) -> str:
|
||||
"""" or 1 to N" after a question that takes a listed number, N rows."""
|
||||
return "" if not count else " or 1" if count == 1 else f" or 1 to {count}"
|
||||
|
||||
|
||||
class ReadCounter:
|
||||
"""Files read so far, as event_kind events and on the live line: the
|
||||
program driving the installer gets the count the terminal gets."""
|
||||
|
||||
+15
-21
@@ -23,7 +23,7 @@ from installer.cards import (
|
||||
share_doubt,
|
||||
share_drive,
|
||||
)
|
||||
from installer.console import _ask, _quit, _typed_folder, detail
|
||||
from installer.console import _answer_yes, _folder_answer, _numbers_hint, _typed_folder, detail
|
||||
from installer.detect_os import _DETECTED_OS, card_title, detect_os, detected_os, os_conflict
|
||||
from installer.embedded import CARD_MARKER, CARD_PLATFORMS, _EMBEDDED_RULES, _a, _built_on
|
||||
from installer.events import EVENTS
|
||||
@@ -95,15 +95,14 @@ def _missing_dest(dest: Path, ask: bool, named: str = "named with --dest",
|
||||
(print if missing > 1 and ask else detail)(
|
||||
f" {shown_path(dest)} does not exist. The nearest folder that does: "
|
||||
f"{shown_path(nearest)}")
|
||||
if missing > 1 and ask:
|
||||
answer = _ask(f" Create {_plural(missing, 'folder')} under {shown_path(nearest)}? [y/N] ")
|
||||
if not answer.strip().lower().startswith("y"):
|
||||
if again:
|
||||
print(" Not created.")
|
||||
return False
|
||||
print(f" Nothing installed. Check the folder {named}, then run "
|
||||
"the command again.")
|
||||
sys.exit(2)
|
||||
if missing > 1 and ask and not _answer_yes(
|
||||
f" Create {_plural(missing, 'folder')} under {shown_path(nearest)}? [y/N] "):
|
||||
if again:
|
||||
print(" Not created.")
|
||||
return False
|
||||
print(f" Nothing installed. Check the folder {named}, then run "
|
||||
"the command again.")
|
||||
sys.exit(2)
|
||||
return True
|
||||
|
||||
|
||||
@@ -539,23 +538,18 @@ def card_install_dest(named: str, plat: str, interactive: bool, ask: bool = True
|
||||
else "Mount the card, then type its top folder."))
|
||||
listed = _list_cards(cards, blank)
|
||||
while True:
|
||||
numbers = ("" if not listed else " or 1" if len(listed) == 1
|
||||
else f" or 1 to {len(listed)}")
|
||||
usage = (f" Type a number from 1 to {len(listed)}, a folder, Enter to look "
|
||||
"again, or q to quit." if listed else
|
||||
" Type the card's top folder, Enter to look again, or q to quit.")
|
||||
# Enter looks again, as the screen's Look again does: a card
|
||||
# inserted after the question was never found.
|
||||
raw = _ask(f"Card root{numbers}, Enter to look again, q to quit: ")
|
||||
if not raw:
|
||||
raw = _folder_answer(f"Card root{_numbers_hint(len(listed))}, Enter to look again, "
|
||||
"q to quit: ", usage, True, len(listed))
|
||||
if raw is None:
|
||||
listed = _list_cards(mounted_cards_of(system, plat), blank_cards_of(system, plat),
|
||||
f"Still no {system} card is mounted.")
|
||||
continue
|
||||
if raw.lower() == "q":
|
||||
_quit()
|
||||
chosen = raw.isdigit() and 1 <= int(raw) <= len(listed)
|
||||
if raw.isdigit() and not chosen and not _is_dir(_typed_folder(raw)):
|
||||
print(f" Type a number from 1 to {len(listed)}, a folder, Enter to look "
|
||||
"again, or q to quit." if listed else
|
||||
" Type the card's top folder, Enter to look again, or q to quit.")
|
||||
continue
|
||||
root = listed[int(raw) - 1] if chosen else _typed_folder(raw).absolute()
|
||||
choice = card_choice(system, plat, root)
|
||||
if choice.refused:
|
||||
|
||||
@@ -18,7 +18,7 @@ from pathlib import Path, PurePosixPath
|
||||
from typing import NamedTuple
|
||||
|
||||
from installer.cards import card_system
|
||||
from installer.console import _ask
|
||||
from installer.console import _answer_yes
|
||||
from installer.events import EVENTS
|
||||
from installer.host_fs import NOT_WRITABLE, _write_refused
|
||||
from installer.local_check import _sha256_file
|
||||
@@ -393,9 +393,8 @@ def finish_app(
|
||||
continue
|
||||
if not interactive or args.yes or LOCAL.offline:
|
||||
continue
|
||||
answer = _ask(f"\nPut RetroBIOS on this {card.system} card, to check and update "
|
||||
"its BIOS files from the console later? [y/N] ")
|
||||
if answer.lower() in ("y", "yes"):
|
||||
if _answer_yes(f"\nPut RetroBIOS on this {card.system} card, to check and "
|
||||
"update its BIOS files from the console later? [y/N] "):
|
||||
chosen.append(card)
|
||||
failed = False
|
||||
for card in chosen:
|
||||
|
||||
@@ -15,7 +15,7 @@ from installer.cards import (
|
||||
setup_bios_folder,
|
||||
share_doubt,
|
||||
)
|
||||
from installer.console import _ask, _quit, _typed_folder, fold_line
|
||||
from installer.console import _ask, _folder_answer, _numbers_hint, _quit, _typed_folder, fold_line
|
||||
from installer.destination import (
|
||||
_last_name,
|
||||
_missing_dest,
|
||||
@@ -49,22 +49,16 @@ def _ask_from_folder(files: list[dict] | None = None, bios_path: Path | None = N
|
||||
print("\nCopy from:")
|
||||
for number, mount in enumerate(drives, 1):
|
||||
print(f" {number}) {card_line(mount)}")
|
||||
numbers = "" if not drives else " or 1" if len(drives) == 1 else f" or 1 to {len(drives)}"
|
||||
count = "" if not drives else "1, " if len(drives) == 1 else f"a number from 1 to {len(drives)}, "
|
||||
# A number out of range, said as one: "2" was read as the folder ./2.
|
||||
usage = f" Type {count}a folder, or Enter."
|
||||
while True:
|
||||
raw = _ask(f"Folder, old card or ZIP to copy from{numbers} (Enter to go back, "
|
||||
"q to quit): ").strip()
|
||||
if not raw:
|
||||
raw = _folder_answer(f"Folder, old card or ZIP to copy from{_numbers_hint(len(drives))} "
|
||||
"(Enter to go back, q to quit): ", usage, True, len(drives))
|
||||
if raw is None:
|
||||
return
|
||||
if raw.lower() == "q":
|
||||
_quit()
|
||||
if raw.isdigit() and 1 <= int(raw) <= len(drives):
|
||||
label = str(drives[int(raw) - 1])
|
||||
elif raw.isdigit() and drives and not _is_dir(_typed_folder(raw)):
|
||||
# A number out of range, said as one: "2" was read as the folder
|
||||
# ./2.
|
||||
count = "1" if len(drives) == 1 else f"a number from 1 to {len(drives)}"
|
||||
print(f" Type {count}, a folder, or Enter.")
|
||||
continue
|
||||
else:
|
||||
label = os.path.normpath(str(_typed_folder(raw).absolute()))
|
||||
refused = copy_source_refusal(Path(label), bios_path)
|
||||
@@ -268,8 +262,7 @@ def ask_platform_folder(os_type: str, plat: str, ask: bool = True,
|
||||
unproven = "" if shared else unproven_words()
|
||||
if unproven:
|
||||
print(f" {unproven}")
|
||||
numbers = "" if not targets else (" or 1" if len(targets) == 1
|
||||
else f" or 1 to {len(targets)}")
|
||||
numbers = _numbers_hint(len(targets))
|
||||
why = ("" if default is not None or shared
|
||||
else " (no default, a folder above could not be opened)"
|
||||
if _default_set_aside(os_type, plat) else " (no default on this system)")
|
||||
@@ -301,27 +294,6 @@ def ask_platform_folder(os_type: str, plat: str, ask: bool = True,
|
||||
return folder
|
||||
|
||||
|
||||
def _folder_answer(prompt: str, usage: str, default: bool, numbers: int = 0) -> str | None:
|
||||
"""A folder question's answer: None for Enter on a default, else the
|
||||
text typed. q quits as at every other question, a folder named q being
|
||||
typed ./q: q was a folder created in the current one and filled. Enter
|
||||
with no default, or a number out of range that names no folder, says
|
||||
what to type: the question came back with no word."""
|
||||
while True:
|
||||
raw = _ask(prompt)
|
||||
if not raw:
|
||||
if default:
|
||||
return None
|
||||
print(usage)
|
||||
continue
|
||||
if raw.lower() == "q":
|
||||
_quit()
|
||||
if raw.isdigit() and not 1 <= int(raw) <= numbers and not _is_dir(_typed_folder(raw)):
|
||||
print(usage)
|
||||
continue
|
||||
return raw
|
||||
|
||||
|
||||
def other_side(os_type: str, plat: str) -> list[tuple[str, Path]]:
|
||||
"""(label, folder) of the Windows side's usual folder under WSL, where
|
||||
the one offered first is this Linux's: a Windows RetroArch outside the
|
||||
|
||||
Reference in new issue
Block a user