Skip to content

Commit 3dcb53b

Browse files
Sweep cli/src/ui: inline wrappers, fix fake tests (#1961)
* Start sweep of cli/src/ui Assisted-by: Claude Code:claude-opus-5-5 * Inline prompt wrappers and fold the VT probes confirm() now builds its Ask inline: the ask() and confirm_waits() wrappers are gone, and read_answer() is folded into confirm_with(). Ask loses non_interactive_answer, which every caller set to default_yes, and Ask, confirm_with and the note consts become private. select_one no longer re-checks the process quiet flag: its only caller passes the same flags ui::init saw, and --json returns earlier. ui/mod.rs replaces the four stdout_vt/stderr_vt fns with one vt() pair, drops the env_var wrapper, and fixes the severity comment that pointed at a moved get.rs fn. status.rs inlines term_is_dumb. Tests: drop the tautological wording test, the setup-style test of the removed field, the read_answer test that repeated the confirm_with cases, and the duplicate nobody-waits test. The TTY-dependent confirm_waits test becomes yes_or_json_answers_the_ default. status.rs drops a duplicate finish_with case. Assisted-by: Claude Code:claude-opus-5-5 * Keep select_one quiet guard and env_var helper Restores select_one's process-wide quiet check (a caller passing derived flags would otherwise print the note under --silent), keeps the env_var helper, and gives each platform its own vt() so the Windows body needs no return (clippy needless_return). Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a722e27 commit 3dcb53b

3 files changed

Lines changed: 60 additions & 215 deletions

File tree

‎crates/socket-patch-cli/src/ui/mod.rs‎

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Terminal UI: everything that decides *how* human output looks.
22
//!
3-
//! - [`StatusLine`]: the one self-rewriting progress line.
3+
//! - [`StatusLine`]: the self-rewriting progress line.
44
//! - [`confirm`], [`select_one`]: prompts.
5-
//! - [`print_json`]: the one `--json` document writer.
6-
//! - [`plural`], [`truncate`], [`sentence_case`]: text shaping.
7-
//! - [`next_steps`]: the one "Next steps:" block (hosted and vendored).
5+
//! - [`print_json`]: the `--json` document writer.
6+
//! - `text`: wording and shaping shared by several commands.
87
//! - [`color_enabled`], [`paint`], [`severity`], [`pad`]: color policy and
98
//! ANSI-aware column alignment.
109
//! - [`init`] / [`quiet`]: the process-wide `--silent`/`--json` switch,
@@ -46,7 +45,7 @@ pub(crate) fn global_scope_arg(common: &GlobalArgs) -> Option<String> {
4645
/// (leading space, empty for a default run): `--cwd`, `--manifest-path`,
4746
/// `-g` / `--global-prefix` and `--ecosystems`, each only when it differs
4847
/// from its default. A remedy a command prints repeats them, so running it
49-
/// verbatim acts on the tree the command just reported on (#464, #1219).
48+
/// verbatim acts on the tree the command just reported on.
5049
pub(crate) fn scope_args(common: &GlobalArgs) -> String {
5150
let mut out = String::new();
5251
if common.cwd != std::path::Path::new(".") {
@@ -69,7 +68,6 @@ pub(crate) fn scope_args(common: &GlobalArgs) -> String {
6968
}
7069

7170
/// Where a physical copy lives, relative to `cwd` when it is inside it.
72-
/// Shared by `apply` and `rollback`.
7371
pub(crate) fn display_copy_path(package_path: &str, cwd: &std::path::Path) -> String {
7472
let path = std::path::Path::new(package_path);
7573
let canonical = std::fs::canonicalize(path).ok();
@@ -118,13 +116,14 @@ pub(crate) fn quiet() -> bool {
118116
socket_patch_core::utils::notice::is_quiet()
119117
}
120118

121-
/// Whether the Windows console behind stdout and stderr accepted VT
122-
/// (escape-sequence) processing, probed once. console's color probe is
123-
/// what switches VT on, so its answer is exactly "escapes will render".
124-
/// `false` for a stream that is not a console (it is then not a terminal
125-
/// either, and escapes in a pipe are the reader's business).
119+
/// Whether escape sequences written to a terminal render, as
120+
/// `(stdout, stderr)`: whether the Windows console accepted VT processing,
121+
/// probed once. console's color probe is what switches VT on, so its
122+
/// answer is exactly "escapes will render". `false` for a stream that is
123+
/// not a console (it is then not a terminal either, and escapes in a pipe
124+
/// are the reader's business).
126125
#[cfg(windows)]
127-
fn vt_probe() -> (bool, bool) {
126+
pub(crate) fn vt() -> (bool, bool) {
128127
static VT: std::sync::OnceLock<(bool, bool)> = std::sync::OnceLock::new();
129128
*VT.get_or_init(|| {
130129
(
@@ -134,29 +133,10 @@ fn vt_probe() -> (bool, bool) {
134133
})
135134
}
136135

137-
/// Whether escape sequences written to a terminal on stdout render: on
138-
/// Windows, whether VT processing could be enabled ([`vt_probe`]).
139-
#[cfg(windows)]
140-
fn stdout_vt() -> bool {
141-
vt_probe().0
142-
}
143-
144-
/// [`stdout_vt`] for stderr (also gates the live [`StatusLine`]).
145-
#[cfg(windows)]
146-
pub(crate) fn stderr_vt() -> bool {
147-
vt_probe().1
148-
}
149-
150-
/// Unix terminals always render escape sequences.
151-
#[cfg(not(windows))]
152-
fn stdout_vt() -> bool {
153-
true
154-
}
155-
156136
/// Unix terminals always render escape sequences.
157137
#[cfg(not(windows))]
158-
pub(crate) fn stderr_vt() -> bool {
159-
true
138+
pub(crate) fn vt() -> (bool, bool) {
139+
(true, true)
160140
}
161141

162142
/// The color policy, pure over its inputs:
@@ -185,17 +165,17 @@ fn env_var(k: &str) -> Option<String> {
185165
}
186166

187167
/// [`color_enabled`] for stdout; a terminal must also render escapes
188-
/// ([`stdout_vt`]).
168+
/// ([`vt`]).
189169
pub(crate) fn stdout_color() -> bool {
190170
let tty = std::io::stdout().is_terminal();
191-
color_enabled(tty, env_var) && (!tty || stdout_vt())
171+
color_enabled(tty, env_var) && (!tty || vt().0)
192172
}
193173

194174
/// [`color_enabled`] for stderr; a terminal must also render escapes
195-
/// ([`stderr_vt`]).
175+
/// ([`vt`]).
196176
pub(crate) fn stderr_color() -> bool {
197177
let tty = std::io::stderr().is_terminal();
198-
color_enabled(tty, env_var) && (!tty || stderr_vt())
178+
color_enabled(tty, env_var) && (!tty || vt().1)
199179
}
200180

201181
/// Columns of the terminal on stderr (status lines, prompts): its size,
@@ -235,7 +215,7 @@ pub fn severity(s: &str, on: bool) -> String {
235215
let code = match s.to_lowercase().as_str() {
236216
"critical" => "91",
237217
"high" => "31",
238-
// GHSA emits `moderate`; same tier as medium (see get.rs severity_rank).
218+
// GHSA emits `moderate`; same tier as medium (core `ranking::severity_order`).
239219
"medium" | "moderate" => "33",
240220
"low" => "36",
241221
_ => return s.to_string(),

0 commit comments

Comments
 (0)