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:
Abdessamad Derraz committed 2026-11-21 06:04:39 +01:00
1 parent 1f215f1732
commit 7b89a558ff
10 files changed
+127 -130

No files matched your search

+8 -36
View File
@@ -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