1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Keeping a fatal message readable when the console is about to disappear.
//!
//! A console application started from Explorer — a double-click on
//! `mindfork.exe`, the shortcut the installer creates — gets a console of its
//! own, and Windows destroys that window the moment the process exits. Every
//! refusal the app prints before the interface opens (another instance already
//! running, a corrupt `defaults.json`, storage that will not open) therefore
//! reached a window that closed too fast to read, which is indistinguishable
//! from "it does nothing when I click it".
//!
//! Whether that is the situation is a question Windows answers:
//! `GetConsoleProcessList` reports how many processes are attached to this
//! console. Measured on a development machine
//! (docs/research/robustness-and-defaults.md §2.2): started from a shell — **3**;
//! started with a console of its own — **1**. One means nobody else is there, so
//! nothing survives our exit.
//!
//! Unix has no equivalent problem (a terminal that was already open stays open),
//! so there the answer is always "no".
use ;
use crateLocale;
/// Whether this process is the **only** one attached to its console.
///
/// Windows only, via `GetConsoleProcessList`; anywhere else this is `false`, and
/// deliberately so — a unix terminal outlives the process that printed into it.
/// Whether a message just printed would be lost without waiting for the reader.
///
/// A pure function so both arms are testable: the environment is asked once, in
/// [`hold_if_sole_owner`]. `stdout_is_terminal` is the second condition and not a
/// formality — output redirected to a file or a pipe has a reader that is not a
/// person, and blocking there would hang a script (the same reasoning that makes
/// `refuses_tui_launch` in `main.rs` ask about stdout rather than stdin).
/// Waits for Enter when the console belongs to this process alone, so the line
/// just printed can be read. Does nothing otherwise, and never fails: a console
/// that cannot be read from is one more reason to exit rather than to hang.