Files
Strata/terminal/strata_cli/noinput.py
T
Niko1221 bd4ed11814 The input that means nobody is there (strata_cli/noinput.py); the boston-only wizard test uses a path that exists nowhere
noinput.stdin_is_no_keyboard: True for the null device only (a pipe or a file may carry answers). Used by the launch's _can_ask in the
hand-off patch (lane TUI's file).
test_tuiqa_wizard StoragePath: the fake storage path started with /home/ana/, a real unreadable home on the lent box boston; the plan's
disk look-up raised PermissionError, the Save screen's repaint stopped silently and the Storage row never appeared. The test path is now
/strata-test-ana/...; the code fix for a folder this account may not read is in the hand-off patch.
2026-11-19 00:43:16 +01:00

25 lines
1.2 KiB
Python

"""Is anybody there to answer a question? (0.2.17: `strata launch < /dev/null` showed "Start it now? [Y/n]" and then ended with "There is nobody to answer".)
The Terminal's conventions for a run with no keyboard: no screens, no question that nobody can answer, a plain sentence that says what to name,
and exit code 2 (``strata launch`` with no choices and no terminal; ``--no-tui`` never asks; the data-folder move keeps the library). This module
holds the one test they share. A pipe or a file may carry answers (Git Bash and mintty give a person's typing as a pipe), so only the null device
counts as "no keyboard".
"""
from __future__ import annotations
import os
import stat
import sys
def stdin_is_no_keyboard(stream=None) -> bool:
"""True when the input is the null device (`< /dev/null`, NUL on Windows): a character device that is not a terminal. False for a terminal, a
pipe, a file, and for anything whose kind cannot be read (a replaced stdin without a file number, a closed one)."""
stream = sys.stdin if stream is None else stream
try:
fd = stream.fileno()
return stat.S_ISCHR(os.fstat(fd).st_mode) and not os.isatty(fd)
except (AttributeError, OSError, ValueError):
return False