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
92
93
94
95
96
97
98
99
100
101
102
103
//! Turn a shell command into a label a human can read at a glance (#790, #791).
//!
//! Every long-running command the agent issues starts by entering the working
//! directory, so a label that keeps the `cd` keeps the one part that is
//! identical for every command and drops the part that identifies it. At the 28
//! characters the input-border indicator allows, that leaves a field showing
//! nothing but a path.
//!
//! Multi-line commands carry a second problem: a newline reaching a single-line
//! renderer is not drawn, so the tail of one line touches the head of the next
//! and produces a token that was never in the command (`opencrabs` + `echo` ->
//! `opencrabsecho`). That reads as a real command and is not one, which is
//! worse than truncation.
//!
//! Both are fixed here, once, so the TUI rows, the border indicator and the
//! channel summaries cannot drift apart.
/// A single-line, human-readable label for `command`.
///
/// Leading `cd <path>` segments are dropped, every remaining segment is kept,
/// and segments are joined with `"; "` so nothing can fuse across a break.
/// Returns an empty string for an empty command; callers supply their own
/// placeholder.
/// Is this segment a bare directory change and nothing else?
///
/// Segments are already split on every separator, so everything after `cd ` is
/// the path, spaces and quotes included.
/// Split on top-level `\n`, `;` and `&&`, ignoring separators inside quotes.
///
/// Quote tracking is what makes this safe to run on arbitrary commands: a
/// naive `split(';')` would cut `echo "a; b"` in half and invent a segment.
/// The scan itself lives in `shell_scan` because the background-task
/// classifier needs the same distinction between syntax and data.
/// Collapse runs of whitespace so a command formatted across columns reads as
/// one line. Any newline inside a segment is impossible (they are separators),
/// so this only tidies runs of spaces and tabs.