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
//! Cross-platform helpers for binary resolution and terminal capability detection.
//!
//! `resolve_npm_cli` exists because npm-installed CLIs on Windows ship as `.cmd` or
//! `.ps1` shims rather than `.exe`, and `std::process::Command::new("name")` does
//! not always pick them up depending on how PATHEXT is configured.
//!
//! `unicode_support_enabled` centralizes the heuristic used by the interactive UI
//! to decide between Unicode box-drawing and ASCII fallback.
use PathBuf;
/// Resolve a Node/npm-style CLI name to an executable path.
///
/// Resolution order:
/// 1. Env var `<NAME_UPPERCASE>_BINARY` (e.g. `CLAUDE_BINARY`, `CODEX_BINARY`) —
/// if set, returned verbatim. Lets users pin a specific binary.
/// 2. On Windows: probe `<name>.exe`, then `<name>.cmd`, then `<name>.ps1` via
/// the `which` crate (which respects PATH and is independent of cmd.exe's
/// PATHEXT handling).
/// 3. Fallback: return `PathBuf::from(name)` so `Command::new()` behaves
/// identically to the pre-resolver code on platforms where probing finds
/// nothing.
/// Decide whether the terminal supports Unicode box-drawing characters.
///
/// Precedence (highest first):
/// 1. `CC_SWITCH_ASCII=1` → force ASCII (escape hatch for any terminal).
/// 2. `CC_SWITCH_UNICODE=1` → force Unicode (escape hatch for Windows users
/// on terminals our heuristic can't detect).
/// 3. On Windows: only enable Unicode if `WT_SESSION` is set (Windows
/// Terminal). Default to ASCII to avoid mojibake on legacy conhost / CMD
/// where the default codepage is not UTF-8.
/// 4. On non-Windows: enabled by default. Modern Linux and macOS terminals
/// universally support UTF-8; the `CC_SWITCH_ASCII=1` escape hatch above
/// covers exceptions.