taimux_cli/rows.rs
1//! The picker's rows, laid out here rather than in awk.
2//!
3//! Step 2 of removing fzf. The awk this replaces exists to hand fzf one TSV line
4//! per row with the colours already burned in as escape sequences; that format
5//! dies with fzf, so the layout is ported into structured cells and the ANSI is
6//! reduced to one renderer used for testing.
7//!
8//! **The layout itself is not being redesigned.** Every rule here was arrived at
9//! by looking at real lists and most of them fix a specific bent row, so they are
10//! ported as they stand and the reasoning is kept with them:
11//!
12//! - The summary follows the label directly, because it is what the list is read
13//! for. Everything that only says WHERE a session is (path, agent, version) is
14//! pinned to the right edge, in fixed columns, so it costs the summary no width
15//! and is what a too-long row truncates away.
16//! - Every column width is measured over the WHOLE list, never per row. Sizing
17//! the trailing block per row moved the path column by however long that row's
18//! agent happened to be, up to 9 columns apart on a mixed list.
19//! - The label column has a floor of 15 in a roomy window and a cap of 15 in a
20//! narrow one, and the floor only applies when the list holds real pane labels.
21//!
22//! The one deliberate improvement is `vlen`: the awk counts characters, this
23//! counts display columns, which is the same answer for everything on an ordinary
24//! list and the right one for a double-width character.
25
26use std::collections::{HashMap, HashSet};
27
28use ratatui::style::{Color, Modifier, Style};
29use unicode_width::UnicodeWidthStr;
30
31/// The paint a cell carries, stored as the SGR prefix the awk emits so the ANSI
32/// renderer is exact, with the ratatui mapping beside it so the TUI never parses
33/// its own escape sequences back.
34#[derive(Clone, Copy, PartialEq, Eq, Debug)]
35pub struct Paint(pub &'static str);
36
37pub const PLAIN: Paint = Paint("");
38/// The label of the pane the picker was opened from.
39pub const LABEL_CUR: Paint = Paint("\x1b[33m");
40pub const LABEL_OTHER: Paint = Paint("\x1b[36m");
41/// A session asking for you: the one glyph here worth a colour of its own.
42pub const MARK_INPUT: Paint = Paint("\x1b[1;33m");
43/// Working, dimmed, because it wants nothing from you.
44pub const MARK_RUN: Paint = Paint("\x1b[2m");
45/// A restart in flight. Cyan rather than the waiting star's bold yellow: it
46/// wants nothing from you, it is just not finished, and it should not compete
47/// with the one glyph that means "this row is asking".
48pub const MARK_RESTART: Paint = Paint("\x1b[36m");
49pub const PATH: Paint = Paint("\x1b[90m");
50/// The permission mode rides on the agent name as brightness rather than taking
51/// a column: louder is less supervised.
52pub const MODE_ASK: Paint = Paint("\x1b[35m");
53pub const MODE_EDIT: Paint = Paint("\x1b[95m");
54pub const MODE_AUTO: Paint = Paint("\x1b[1;95m");
55/// A session running code a self-update has already replaced. Plain yellow, not
56/// the bold yellow of the star, since nothing is being asked of you.
57pub const VER_STALE: Paint = Paint("\x1b[33m");
58pub const VER_OK: Paint = Paint("\x1b[2;35m");
59
60impl Paint {
61 pub fn style(self) -> Style {
62 match self.0 {
63 "\x1b[33m" => Style::default().fg(Color::Yellow),
64 "\x1b[36m" => Style::default().fg(Color::Cyan),
65 "\x1b[1;33m" => Style::default()
66 .fg(Color::Yellow)
67 .add_modifier(Modifier::BOLD),
68 "\x1b[2m" => Style::default().add_modifier(Modifier::DIM),
69 "\x1b[90m" => Style::default().fg(Color::DarkGray),
70 "\x1b[35m" => Style::default().fg(Color::Magenta),
71 "\x1b[95m" => Style::default().fg(Color::LightMagenta),
72 "\x1b[1;95m" => Style::default()
73 .fg(Color::LightMagenta)
74 .add_modifier(Modifier::BOLD),
75 "\x1b[2;35m" => Style::default()
76 .fg(Color::Magenta)
77 .add_modifier(Modifier::DIM),
78 _ => Style::default(),
79 }
80 }
81}
82
83#[derive(Clone, Debug, PartialEq, Eq)]
84pub struct Cell {
85 pub text: String,
86 pub paint: Paint,
87}
88
89fn cell(text: impl Into<String>, paint: Paint) -> Cell {
90 Cell {
91 text: text.into(),
92 paint,
93 }
94}
95
96#[derive(Clone, Debug)]
97pub struct Row {
98 pub cells: Vec<Cell>,
99 pub pane_id: String,
100 /// Kept unabbreviated and unshortened for the preview header, which has the
101 /// room the row does not and wants to say exactly where the session is.
102 pub target: String,
103 pub cwd: String,
104 /// Set for a session on another machine. capture-pane only works where the
105 /// pane is, so the preview has to ask over there rather than locally.
106 pub host: String,
107 /// When the session last said something, in epoch milliseconds, which is
108 /// what ctrl-s sorts every list on. None where nothing tells: an agent other
109 /// than claude, a claude with no hook line, or another host whose taimux
110 /// predates the field.
111 pub since: Option<i64>,
112}
113
114impl Row {
115 /// The exact line the awk prints, for diffing one implementation against the
116 /// other. Nothing in the TUI calls this: it renders the cells directly.
117 pub fn to_ansi(&self) -> String {
118 let mut s = String::new();
119 for c in &self.cells {
120 if c.paint == PLAIN {
121 s.push_str(&c.text);
122 } else {
123 s.push_str(c.paint.0);
124 s.push_str(&c.text);
125 s.push_str("\x1b[0m");
126 }
127 }
128 s.push('\t');
129 s.push_str(&self.pane_id);
130 s
131 }
132
133 /// The row with every escape sequence gone, which is what a width assertion
134 /// and a fuzzy match both want. fzf has to be handed `--ansi` and parse our
135 /// colours back out to get at this; the TUI has it for free.
136 #[allow(dead_code)] // the in-memory filter is step 3
137 pub fn plain(&self) -> String {
138 self.cells.iter().map(|c| c.text.as_str()).collect()
139 }
140}
141
142/// Display width. The awk counts characters (gawk in a UTF-8 locale) and hand
143/// strips UTF-8 continuation bytes where it cannot; this counts columns, which
144/// agrees for everything an ordinary list holds and is right where the awk was
145/// quietly wrong.
146fn vlen(s: &str) -> usize {
147 UnicodeWidthStr::width(s)
148}
149
150fn spaces(n: usize) -> String {
151 " ".repeat(n)
152}
153
154/// Pad on the right to a column width, never truncating: a column measured over
155/// the whole list is already wide enough, and a row that overruns it is a bug
156/// worth seeing rather than hiding.
157fn pad(s: &str, w: usize) -> String {
158 let mut out = s.to_string();
159 out.push_str(&spaces(w.saturating_sub(vlen(s))));
160 out
161}
162
163/// Whatever marker the title leads with, taken off so the column can be filled
164/// from the STATE instead. The title shows the same star for all three states
165/// (and sometimes a spinner frame that means nothing in particular), so the glyph
166/// it carries is dropped rather than shown.
167///
168/// A marker is "a leading run of non-printable-ASCII, then a space or the end",
169/// not a list of the known frames: this only has to find where the summary
170/// starts, so a glyph nobody has seen yet is still stripped cleanly. A title that
171/// merely opens on a non-ASCII WORD is left whole, since the space has to follow
172/// the run directly.
173pub fn summary_of(title: &str) -> &str {
174 let run: usize = title
175 .chars()
176 .take_while(|c| !(' '..='~').contains(c))
177 .map(|c| c.len_utf8())
178 .sum();
179 if run == 0 {
180 return title;
181 }
182 let rest = &title[run..];
183 match rest.strip_prefix(' ') {
184 Some(r) => r,
185 None if rest.is_empty() => rest,
186 None => title,
187 }
188}
189
190/// The permission mode, in brightness. Ordinary magenta for a session that will
191/// stop and ask (default, plan, or nothing known), bright for one applying edits
192/// on its own, bold bright for one that asks nothing at all.
193fn mode_paint(mode: &str) -> Paint {
194 match mode {
195 "acceptEdits" => MODE_EDIT,
196 "bypassPermissions" | "auto" => MODE_AUTO,
197 _ => MODE_ASK,
198 }
199}
200
201/// Is this row running code a self-update has already replaced, i.e. one ctrl-x
202/// applies to?
203///
204/// Never on another host: `newver` is what THIS box would start, and a session on
205/// one host being behind another is not a fact about anything. Never on an ENDED
206/// session either, however far behind it last ran: there is no process to put
207/// back.
208///
209/// One predicate, two uses: the yellow version on a row, and the outdated list
210/// Tab stops on. They have to agree, or the list would hold rows whose colour
211/// says nothing is wrong with them, or leave out ones it paints yellow.
212fn outdated(host: &str, agent: &str, v: &str, state: &str, newver: &str) -> bool {
213 state != "dead"
214 && host.is_empty()
215 && agent == "claude"
216 && !newver.is_empty()
217 && !v.is_empty()
218 && v != newver
219}
220
221/// Yellow means "ctrl-x applies to this row".
222fn version_paint(host: &str, agent: &str, v: &str, state: &str, newver: &str) -> Paint {
223 if outdated(host, agent, v, state, newver) {
224 VER_STALE
225 } else {
226 VER_OK
227 }
228}
229
230/// Each name cut to the fewest letters that still tell it apart from every other
231/// name in the list: one where nothing else starts with it, more only against the
232/// names it actually collides with. A name that is a whole other name plus
233/// something (main, main2) can only be told apart in full.
234///
235/// `minlen` is a floor. Sessions take 1, since you picked those names and they
236/// are on screen constantly. Hosts take 2, because a host is the part of a row
237/// you are least likely to have in your head, and "l" for laptop-two saves nine
238/// columns by giving up the whole point of the column.
239fn abbrev(names: &[String], minlen: usize) -> HashMap<String, String> {
240 let mut out = HashMap::new();
241 for s in names {
242 let chars: Vec<char> = s.chars().collect();
243 let mut n = chars.len() + 1; // nothing distinguished it: keep it whole
244 for k in 1..=chars.len() {
245 let head: String = chars.iter().take(k).collect();
246 let clash = names
247 .iter()
248 .any(|t| t != s && t.chars().take(k).collect::<String>() == head);
249 if !clash {
250 n = k;
251 break;
252 }
253 }
254 let n = n.max(minlen);
255 out.insert(s.clone(), chars.iter().take(n).collect());
256 }
257 out
258}
259
260/// The last two components of the working directory, with $HOME folded to `~`
261/// and a cap of 30 characters, elided from the left because the tail is the part
262/// that says which project it is.
263fn path_display(cwd: &str, home: &str) -> String {
264 let cwd = if !home.is_empty() && cwd.starts_with(home) {
265 format!("~{}", &cwd[home.len()..])
266 } else {
267 cwd.to_string()
268 };
269 let parts: Vec<&str> = cwd.split('/').collect();
270 let disp = if parts.len() >= 2 {
271 format!("{}/{}", parts[parts.len() - 2], parts[parts.len() - 1])
272 } else {
273 cwd.clone()
274 };
275 let n = disp.chars().count();
276 if n > 30 {
277 // the awk takes from length-28 to the end, i.e. the last 29 characters
278 let tail: String = disp.chars().skip(n - 29).collect();
279 format!("…{}", tail)
280 } else {
281 disp
282 }
283}
284
285/// Does the row already show everything that was typed? If it does it needs no
286/// explaining, and keeping its path, agent and version is worth more than quoting
287/// the query back at it.
288///
289/// Case-insensitive, as the content search now is: `terms` arrive folded. The
290/// two have to agree, or a row kept because of a capital the transcript spells
291/// differently would still be told it says nothing.
292fn says_it(s: &str, terms: &[String]) -> bool {
293 if terms.is_empty() {
294 return false;
295 }
296 let hay = s.to_lowercase();
297 terms
298 .iter()
299 .all(|t| t.is_empty() || hay.contains(t.as_str()))
300}
301
302/// Trailing spaces align nothing, so the all-blank remainder a row with no agent
303/// or version leaves is trimmed off. Done over the cells rather than the rendered
304/// string, since a painted cell ends in a reset and would block the trim.
305fn trim_trailing(cells: &mut Vec<Cell>) {
306 while let Some(last) = cells.last_mut() {
307 if last.paint != PLAIN {
308 break;
309 }
310 let trimmed = last.text.trim_end_matches(' ');
311 if trimmed.len() == last.text.len() {
312 break; // ended in something other than a space: nothing to trim
313 }
314 last.text.truncate(trimmed.len());
315 if !last.text.is_empty() {
316 break; // the run of spaces ended inside this cell
317 }
318 cells.pop();
319 }
320}
321
322/// One input line, before anything is measured.
323struct Item {
324 id: String,
325 target: String,
326 agent: String,
327 version: String,
328 state: String,
329 mode: String,
330 title: String,
331 host: String,
332 /// The one row a host that could not answer keeps in the list. Left out of
333 /// the shortening and printed whole: the host name IS the message.
334 note: bool,
335 /// A pane running no agent, which only the every-pane list holds. Its
336 /// command stands where an agent's name would, painted as quietly as the
337 /// path, so the sessions in that list still stand out from the shells.
338 plain: bool,
339 /// The last two components, capped, as the row shows it.
340 path: String,
341 /// The whole thing, as the preview header shows it.
342 cwd: String,
343 session: String,
344 since: Option<i64>,
345}
346
347#[derive(Default)]
348pub struct Input<'a> {
349 pub cur: &'a str,
350 /// 0 means "unknown", which reads as "do not right-align".
351 pub width: usize,
352 pub home: &'a str,
353 /// What a session started right now would run, so a pane left behind by a
354 /// self-update can be told apart from a current one.
355 pub newver: &'a str,
356 /// One state only, or empty for all.
357 pub only: &'a str,
358 /// Keep only the rows a restart would act on, i.e. the ones the version
359 /// column paints yellow.
360 ///
361 /// Separate from `only` because being behind is not a STATE: it is the row's
362 /// version against the one installed here, and a session waiting, working or
363 /// idle can each be behind. Which is also why this list crosses the four
364 /// state modes rather than sitting inside one of them.
365 pub outdated: bool,
366 /// Keep only the rows whose session left work in flight, a shell or a
367 /// subagent still running: the tenth field, `bg`.
368 ///
369 /// Not a state either, for the same reason the hook line's `bg` reads as
370 /// idle: the turn is over and the prompt is free. It is the question
371 /// `restart` asks on top of the state, and a session that has started a new
372 /// turn since can still have that work running.
373 pub background: bool,
374 /// Keep the rows `background` would as well, whatever their state, on top
375 /// of the ones `only` keeps.
376 ///
377 /// What the working list asks for: a shell or a subagent a turn left running
378 /// is work still going on, and the list of what is busy is where you look
379 /// for it, even though the turn that started it is over and the row reads as
380 /// idle. Only the list grows: the row keeps its state and its marker, so it
381 /// still shows as idle in it.
382 pub with_background: bool,
383 /// Keep the rows of panes running no agent, the ones in state `pane`, which
384 /// every list but the every-pane one leaves out. They come in on the same
385 /// scan as the sessions, so this is the only thing that keeps them out of
386 /// the lists of what sessions are doing.
387 pub panes: bool,
388 pub query: &'a str,
389 /// pane id to the snippet of what that session said, when searching.
390 ///
391 /// The layout applies whatever it is given. **The "at least
392 /// TAIMUX_SEARCH_MIN characters" gate lives in the CALLER**, exactly as it
393 /// does in bash: under three characters a term is in every transcript and a
394 /// match would say nothing, so no snippets are looked up at all. Handing this
395 /// a snippet map for a one-letter query would quietly turn every row into a
396 /// search hit.
397 pub snips: HashMap<String, String>,
398 /// pane id to the title its conversation last recorded, for a pane that
399 /// publishes none of its own.
400 pub ptitles: HashMap<String, String>,
401 /// Panes with a restart in flight.
402 ///
403 /// This paints the marker column and nothing else. In particular it does NOT
404 /// touch the state field, which is what keeps such a row where it was: the
405 /// state drives both the Tab filter and the row's place in the list, so a
406 /// synthetic "restarting" state would drop the row out of whichever mode it
407 /// was being watched in, at the exact moment its owner is watching it.
408 pub restarting: HashSet<String>,
409}
410
411pub fn build(lines: &str, input: &Input) -> Vec<Row> {
412 // Folded, because the search behind them is: see `says_it`.
413 let terms: Vec<String> = input
414 .query
415 .split([' ', '\t'])
416 .filter(|t| !t.is_empty())
417 .map(|t| t.to_lowercase())
418 .collect();
419
420 let mut items: Vec<Item> = Vec::new();
421 for line in lines.lines() {
422 let f: Vec<&str> = line.split('\t').collect();
423 if f.len() < 7 {
424 continue;
425 }
426 let state = f[5];
427 let plain = state == taimux_core::panes::PANE;
428 if plain && !input.panes {
429 continue;
430 }
431 // Nothing at all is "not known", which is every row from a host whose
432 // taimux predates the field, and so is anything other than `bg`.
433 let bg = f.get(9) == Some(&"bg");
434 if !input.only.is_empty() && state != input.only && !(input.with_background && bg) {
435 continue;
436 }
437 if input.background && !bg {
438 continue;
439 }
440 let (id, target, cwd) = (f[0], f[1], f[2]);
441
442 // A pane id that does not open on "%" names another host, and the label
443 // leads with it: "ha/main:1.7". What follows the colon says which kind of
444 // row it is, a pane id for a session over there, anything else for a
445 // host that could not answer.
446 let (mut host, mut note) = (String::new(), false);
447 if !id.starts_with('%') {
448 if let Some(c) = id.find(':') {
449 if c > 0 {
450 if id[c + 1..].starts_with('%') {
451 host = id[..c].to_string();
452 } else {
453 note = true;
454 }
455 }
456 }
457 }
458 // Applied here rather than beside `only` because it needs the host, and
459 // the host is what the id above has just been read for.
460 if input.outdated && !outdated(&host, f[3], f[4], state, input.newver) {
461 continue;
462 }
463 let session = match target.find(':') {
464 Some(c) if c > 0 => target[..c].to_string(),
465 _ => target.to_string(),
466 };
467 items.push(Item {
468 id: id.to_string(),
469 target: target.to_string(),
470 agent: f[3].to_string(),
471 version: f[4].to_string(),
472 state: state.to_string(),
473 mode: f[6].to_string(),
474 title: f.get(7).copied().unwrap_or("").to_string(),
475 host,
476 note,
477 plain,
478 path: path_display(cwd, input.home),
479 cwd: cwd.to_string(),
480 session,
481 // A ninth field, where the row has one: `-` or nothing at all is
482 // "not known", and so is anything that is not a number.
483 since: f.get(8).and_then(|s| s.parse().ok()),
484 });
485 }
486
487 // Narrow window: the session name is the first thing asked to give columns
488 // back. Of everything on the row it is the most recognisable from a few
489 // letters, and window.pane stays whole since two digits are no use truncated.
490 // The threshold is the one the tmux binding already uses to switch the popup
491 // to full width.
492 let compact = input.width > 0 && input.width < 100;
493 let mut names: Vec<String> = Vec::new();
494 let mut hnames: Vec<String> = Vec::new();
495 for it in &items {
496 if !it.note && !names.contains(&it.session) {
497 names.push(it.session.clone());
498 }
499 if !it.host.is_empty() && !hnames.contains(&it.host) {
500 hnames.push(it.host.clone());
501 }
502 }
503 let (short, shorth) = if compact {
504 (abbrev(&names, 1), abbrev(&hnames, 2))
505 } else {
506 (HashMap::new(), HashMap::new())
507 };
508
509 // The label column is as wide as the widest label actually in THIS list,
510 // never a guess. A flat 15 broke the moment a target needed more:
511 // "platform:14.11" is 14 plus the 2-column marker, so that one row started
512 // its summary a column right of every other and the whole list looked bent.
513 let mut labels: Vec<String> = Vec::new();
514 let mut labelw = 0;
515 for it in &items {
516 let lbl = if it.note {
517 it.target.clone()
518 } else {
519 let pfx = if it.host.is_empty() {
520 String::new()
521 } else if compact {
522 format!("{}/", shorth.get(&it.host).unwrap_or(&it.host))
523 } else {
524 format!("{}/", it.host)
525 };
526 let body = if compact {
527 let s = short.get(&it.session).cloned().unwrap_or_default();
528 format!("{}{}", s, &it.target[it.session.len()..])
529 } else {
530 it.target.clone()
531 };
532 format!("{}{}", pfx, body)
533 };
534 labelw = labelw.max(vlen(&lbl) + 2);
535 labels.push(lbl);
536 }
537 // A narrow window CAPS it: there the label is the column asked to give width
538 // back to the summary, and a shortened name that still overruns is worth a
539 // bent row. A roomy window gets a FLOOR instead, so the column stops
540 // jittering as sessions with longer names come and go. The old code applied
541 // 15 as a ceiling in BOTH, which is what bent the row.
542 //
543 // The floor only holds up a column of PANE labels, which is what it is for. A
544 // list of ended sessions labels no pane (the column holds an age, three
545 // characters of it), so the floor there would spend twelve columns of summary
546 // on nothing at all.
547 let panes = items.iter().filter(|i| !i.note).count();
548 if compact {
549 labelw = labelw.min(15);
550 } else if panes > 0 {
551 labelw = labelw.max(15);
552 }
553
554 // The trailing columns are a TABLE, so their widths come from the whole list
555 // too. Right-aligning "<path> <agent> <version>" as ONE string moves the path
556 // column by however long the agent and version on THAT row happen to be, and
557 // no two agents are the same length.
558 let mut agw = 0;
559 let mut verw = 0;
560 let mut pathw = 0;
561 for it in &items {
562 agw = agw.max(vlen(&it.agent));
563 verw = verw.max(vlen(&it.version));
564 pathw = pathw.max(vlen(&it.path));
565 }
566 pathw = pathw.min(30);
567 let tailw = pathw + 1 + agw + if verw > 0 { 1 + verw } else { 0 };
568
569 let mut out = Vec::new();
570 for (i, it) in items.iter().enumerate() {
571 let is_cur = it.id == input.cur;
572 let mark = if is_cur { "● " } else { " " };
573 let plabel = pad(&format!("{}{}", mark, labels[i]), labelw);
574
575 let mut sum = summary_of(&it.title).to_string();
576 // Nothing on the pane: fall back to what its conversation calls itself.
577 // claude sets a title at a turn boundary, so a session restored by
578 // tmux-resurrect and not prompted since has nothing there. Never for a
579 // pane with no agent in it, whatever its id once ran.
580 if sum.is_empty() && !it.plain {
581 if let Some(t) = input.ptitles.get(&it.id) {
582 sum = t.clone();
583 }
584 }
585 // A summary that will not fit gives way, rather than pushing the table
586 // off the right edge. Nothing needed this while every summary came from
587 // a pane title, which is a handful of words; a PAST session's summary is
588 // whatever it was asked to do, up to eighty characters of it, and those
589 // rows arrived shoving the directory, the agent and the version out of
590 // the window. The columns beside it are the ones you read down the list,
591 // so the summary is the one that can afford to end in an ellipsis.
592 sum = fit(&sum, summary_room(input.width, vlen(&plabel), tailw));
593
594 let mut cells = vec![
595 cell(plabel.clone(), if is_cur { LABEL_CUR } else { LABEL_OTHER }),
596 cell(" ", PLAIN),
597 ];
598 // A restart in flight outranks the state, because during one the state is
599 // whatever the screen happened to show as the old session went away, and
600 // that is the least useful thing the column could say. The glyph goes
601 // here rather than into the summary because the summary strips a leading
602 // marker (see summary_of), so one put there would be silently eaten.
603 if input.restarting.contains(&it.id) {
604 cells.push(cell("↻", MARK_RESTART));
605 cells.push(cell(" ", PLAIN));
606 } else {
607 match it.state.as_str() {
608 "input" => {
609 cells.push(cell("✳", MARK_INPUT));
610 cells.push(cell(" ", PLAIN));
611 }
612 "run" => {
613 cells.push(cell("◐", MARK_RUN));
614 cells.push(cell(" ", PLAIN));
615 }
616 _ => cells.push(cell(" ", PLAIN)),
617 }
618 }
619 cells.push(cell(sum.clone(), PLAIN));
620
621 // A row that is here because of what its session SAID takes the snippet
622 // where its path would be. Two things at once: the row stops being a
623 // mystery, and the words typed are now ON it, which is what lets the
624 // matcher keep working in the ordinary way rather than being handed a
625 // blob it would match everything against.
626 // Never on a pane with no agent in it: whatever an index still holds
627 // under its id was said by a session that has left it.
628 let snip = input.snips.get(&it.id).filter(|_| !it.plain).filter(|_| {
629 !says_it(
630 &format!("{} {} {} {} {}", plabel, sum, it.path, it.agent, it.version),
631 &terms,
632 )
633 });
634 if let Some(s) = snip {
635 let stail = format!("⌕ {}", s);
636 let gap = gap_of(input.width, &plabel, &sum, vlen(&stail));
637 cells.push(cell(spaces(gap), PLAIN));
638 cells.push(cell(stail, PATH));
639 } else {
640 let gap = gap_of(input.width, &plabel, &sum, tailw);
641 cells.push(cell(spaces(gap), PLAIN));
642 cells.push(cell(pad(&it.path, pathw), PATH));
643 cells.push(cell(" ", PLAIN));
644 // Agent and version are right-aligned inside their columns, so the
645 // row stays flush with the right edge and the version numbers read
646 // down the list. A row missing either keeps the column: what it must
647 // not do is pull the ones beside it out of line.
648 if it.agent.is_empty() {
649 cells.push(cell(spaces(agw), PLAIN));
650 } else {
651 cells.push(cell(spaces(agw - vlen(&it.agent)), PLAIN));
652 let paint = if it.plain { PATH } else { mode_paint(&it.mode) };
653 cells.push(cell(it.agent.clone(), paint));
654 }
655 if verw > 0 {
656 if it.version.is_empty() {
657 cells.push(cell(format!(" {}", spaces(verw)), PLAIN));
658 } else {
659 cells.push(cell(
660 format!(" {}", spaces(verw - vlen(&it.version))),
661 PLAIN,
662 ));
663 cells.push(cell(
664 it.version.clone(),
665 version_paint(&it.host, &it.agent, &it.version, &it.state, input.newver),
666 ));
667 }
668 }
669 }
670 trim_trailing(&mut cells);
671 cells.retain(|c| !c.text.is_empty());
672 out.push(Row {
673 cells,
674 pane_id: it.id.clone(),
675 target: it.target.clone(),
676 cwd: it.cwd.clone(),
677 host: it.host.clone(),
678 since: it.since,
679 });
680 }
681 out
682}
683
684/// What is left between the summary and the right-hand block. Two columns
685/// minimum: a window with no room just trails the tail behind the summary
686/// instead of overlapping it.
687fn gap_of(width: usize, plabel: &str, sum: &str, tailw: usize) -> usize {
688 let used = vlen(plabel) + 1 + 2 + vlen(sum) + tailw;
689 width.saturating_sub(used).max(2)
690}
691
692/// How much width a summary may have before it starts costing the table.
693///
694/// `0` means "as much as it likes", which is what an unmeasured window (width 0,
695/// the machine-readable path) and one too narrow to hold a table both get: in
696/// the first nothing is being drawn, and in the second there is no arrangement
697/// that fits, so a long summary is more use than a stump.
698fn summary_room(width: usize, labelw: usize, tailw: usize) -> usize {
699 if width == 0 {
700 return 0;
701 }
702 let chrome = labelw + 1 + 2 + 2 + tailw; // label, space, marker, gap, table
703 let room = width.saturating_sub(chrome);
704 if room < MIN_SUMMARY {
705 0
706 } else {
707 room
708 }
709}
710
711/// Below this a summary says nothing, so the table gives way instead.
712const MIN_SUMMARY: usize = 20;
713
714/// Cut to a display width, with an ellipsis where it was cut.
715///
716/// `0` is no limit. Character-wise and width-aware, so a double-width character
717/// counts for two and none is ever cut in half.
718fn fit(s: &str, room: usize) -> String {
719 if room == 0 || vlen(s) <= room {
720 return s.to_string();
721 }
722 let mut out = String::new();
723 let mut w = 0;
724 for c in s.chars() {
725 let cw = UnicodeWidthStr::width(c.to_string().as_str());
726 if w + cw > room.saturating_sub(1) {
727 break;
728 }
729 out.push(c);
730 w += cw;
731 }
732 out.push('…');
733 out
734}
735
736#[cfg(test)]
737mod tests {
738 use super::*;
739
740 fn rows(lines: &str, cur: &str, width: usize) -> Vec<String> {
741 build(
742 lines,
743 &Input {
744 cur,
745 width,
746 home: "/home/p",
747 ..Default::default()
748 },
749 )
750 .iter()
751 .map(|r| r.to_ansi())
752 .collect()
753 }
754
755 const THREE: &str = "%10\twork:1.1\t/home/p/proj/web\tclaude\t2.1.229\trun\t-\t◐ Refactor auth\n\
756 %11\tops:2.1\t/home/p\tgemini\t0.41.2\trun\t-\t⠂ tests\n\
757 %12\tops:3.1\t/home/p/longdir/another-very-long-project-name-here\tcodex\t\trun\t-\t◐ X";
758
759 #[test]
760 fn the_pane_id_is_the_hidden_last_field() {
761 let r = rows(THREE, "%11", 100);
762 assert!(r[0].ends_with("\t%10"));
763 assert!(r[1].ends_with("\t%11"));
764 }
765
766 #[test]
767 fn only_the_current_pane_is_marked() {
768 let r = rows(THREE, "%11", 100);
769 assert!(!r[0].contains('●'));
770 assert!(r[1].contains('●'));
771 }
772
773 /// The glyph the title leads with is dropped and the column filled from the
774 /// state, so a title's own spinner frame never leaks into the summary.
775 #[test]
776 fn the_title_marker_is_replaced_by_the_state_marker() {
777 let r = rows(THREE, "%11", 100);
778 assert!(r[0].contains("Refactor auth"));
779 assert!(!r[0].contains("◐ Refactor")); // the title's own glyph is gone
780 assert!(r[0].contains("\x1b[2m◐\x1b[0m ")); // …and the state's is there
781 }
782
783 #[test]
784 fn summary_of_strips_only_a_leading_glyph_run() {
785 assert_eq!(summary_of("◐ Refactor auth"), "Refactor auth");
786 assert_eq!(summary_of("⠂ tests"), "tests");
787 assert_eq!(summary_of("plain title"), "plain title");
788 // a title that merely OPENS on a non-ASCII word keeps it: the space has
789 // to follow the run directly
790 assert_eq!(summary_of("étude du code"), "étude du code");
791 // a bare glyph with nothing after it leaves an empty summary
792 assert_eq!(summary_of("✳"), "");
793 }
794
795 #[test]
796 fn paths_fold_home_and_keep_the_last_two_components() {
797 assert_eq!(path_display("/home/p/proj/web", "/home/p"), "proj/web");
798 assert_eq!(path_display("/home/p", "/home/p"), "~");
799 assert_eq!(path_display("/var/log", "/home/p"), "var/log");
800 }
801
802 #[test]
803 fn a_long_path_is_elided_from_the_left_to_thirty() {
804 let d = path_display(
805 "/home/p/longdir/another-very-long-project-name-here",
806 "/home/p",
807 );
808 assert_eq!(d.chars().count(), 30);
809 assert!(d.starts_with('…'));
810 assert!(d.ends_with("name-here"));
811 }
812
813 /// Every trailing column is measured over the whole list, so the path column
814 /// starts in the same place on every row. Sizing them per row is what bent
815 /// the list: no two agent names are the same length.
816 /// Columns, not bytes: `●` and `◐` are three bytes each, so a byte offset
817 /// reports two rows as misaligned that are in fact flush.
818 fn col_of(line: &str, needle: &str) -> usize {
819 let s = strip(line);
820 let b = s.find(needle).expect("needle on the row");
821 vlen(&s[..b])
822 }
823
824 #[test]
825 fn the_trailing_columns_line_up_down_the_list() {
826 let r = rows(THREE, "%11", 100);
827 // all three paths start at the same column
828 let a = col_of(&r[0], "proj/web");
829 assert_eq!(col_of(&r[1], "~"), a);
830 assert_eq!(col_of(&r[2], "…"), a);
831 }
832
833 fn strip(s: &str) -> String {
834 let mut out = String::new();
835 let mut it = s.chars();
836 while let Some(c) = it.next() {
837 if c == '\x1b' {
838 for c in it.by_ref() {
839 if c == 'm' {
840 break;
841 }
842 }
843 } else {
844 out.push(c);
845 }
846 }
847 out
848 }
849
850 /// A row with no version keeps the column rather than pulling the ones beside
851 /// it out of line, and the blank remainder that leaves is trimmed.
852 #[test]
853 fn a_missing_version_keeps_its_column_but_leaves_no_trailing_space() {
854 let r = rows(THREE, "%11", 100);
855 assert!(!strip(&r[2]).split('\t').next().unwrap().ends_with(' '));
856 assert!(strip(&r[2]).contains("codex"));
857 }
858
859 #[test]
860 fn abbreviates_to_the_shortest_prefix_that_still_tells_names_apart() {
861 let n: Vec<String> = ["main", "master", "ops"]
862 .iter()
863 .map(|s| s.to_string())
864 .collect();
865 let a = abbrev(&n, 1);
866 assert_eq!(a["ops"], "o");
867 assert_eq!(a["main"], "mai");
868 assert_eq!(a["master"], "mas");
869 }
870
871 /// A name that is a whole other name plus something can only be told apart in
872 /// full, which the awk gets by running its loop off the end.
873 #[test]
874 fn a_name_that_contains_another_is_kept_whole() {
875 let n: Vec<String> = ["main", "main2"].iter().map(|s| s.to_string()).collect();
876 let a = abbrev(&n, 1);
877 assert_eq!(a["main"], "main");
878 assert_eq!(a["main2"], "main2");
879 }
880
881 #[test]
882 fn the_host_floor_is_two_letters() {
883 let n: Vec<String> = ["laptop-two", "ha"].iter().map(|s| s.to_string()).collect();
884 let a = abbrev(&n, 2);
885 assert_eq!(a["laptop-two"], "la");
886 assert_eq!(a["ha"], "ha");
887 }
888
889 /// The floor holds up a column of pane labels and nothing else. A list of
890 /// ended sessions labels no pane, so it would spend twelve columns of summary
891 /// on nothing.
892 #[test]
893 fn the_label_floor_applies_to_pane_rows_and_the_cap_to_narrow_windows() {
894 let short = "%1\tw:1.1\t/home/p\tclaude\t1.0\tidle\t-\thi";
895 let wide = rows(short, "", 200);
896 let label_end = strip(&wide[0]).find("hi").unwrap();
897 assert_eq!(label_end, 15 + 1 + 2); // floored at 15, a space, the marker
898
899 // narrow caps rather than floors, so the summary gets the width back
900 let narrow = rows(short, "", 60);
901 assert!(strip(&narrow[0]).find("hi").unwrap() < 15);
902 }
903
904 #[test]
905 fn a_row_with_no_room_still_leaves_two_columns_of_gap() {
906 let r = rows(THREE, "%11", 0);
907 for line in &r {
908 assert!(strip(line).contains(" "));
909 }
910 }
911
912 #[test]
913 fn trims_only_a_trailing_run_of_unpainted_spaces() {
914 let mut c = vec![cell("a", PLAIN), cell("b ", PLAIN)];
915 trim_trailing(&mut c);
916 assert_eq!(c, vec![cell("a", PLAIN), cell("b", PLAIN)]);
917
918 // the run crosses a cell boundary, exactly as it would in the awk's
919 // concatenated string
920 let mut c = vec![cell("a", PLAIN), cell(" ", PLAIN), cell(" ", PLAIN)];
921 trim_trailing(&mut c);
922 assert_eq!(c, vec![cell("a", PLAIN)]);
923
924 // a painted cell ends in a reset, so nothing is trimmed past it
925 let mut c = vec![cell("x ", PATH), cell("", PLAIN)];
926 trim_trailing(&mut c);
927 assert_eq!(c[0].text, "x ");
928 }
929
930 #[test]
931 fn the_permission_mode_rides_on_the_agent_name() {
932 let base = "%1\tw:1.1\t/home/p\tclaude\t1.0\tidle\t";
933 let ask = rows(&format!("{}default\thi", base), "", 100);
934 let edit = rows(&format!("{}acceptEdits\thi", base), "", 100);
935 let auto = rows(&format!("{}bypassPermissions\thi", base), "", 100);
936 assert!(ask[0].contains("\x1b[35mclaude"));
937 assert!(edit[0].contains("\x1b[95mclaude"));
938 assert!(auto[0].contains("\x1b[1;95mclaude"));
939 }
940
941 #[test]
942 fn a_stale_version_goes_yellow_only_where_ctrl_x_could_act() {
943 let line = "%1\tw:1.1\t/home/p\tclaude\t1.0\tidle\t-\thi";
944 let stale = build(
945 line,
946 &Input {
947 newver: "2.0",
948 width: 100,
949 ..Default::default()
950 },
951 );
952 assert!(stale[0].to_ansi().contains("\x1b[33m1.0"));
953
954 // same version installed: nothing to act on
955 let current = build(
956 line,
957 &Input {
958 newver: "1.0",
959 width: 100,
960 ..Default::default()
961 },
962 );
963 assert!(current[0].to_ansi().contains("\x1b[2;35m1.0"));
964
965 // another host: newver is what THIS box would start, so it says nothing
966 let remote = build(
967 "ha:%1\tw:1.1\t/home/p\tclaude\t1.0\tidle\t-\thi",
968 &Input {
969 newver: "2.0",
970 width: 100,
971 ..Default::default()
972 },
973 );
974 assert!(remote[0].to_ansi().contains("\x1b[2;35m1.0"));
975
976 // an ended session has no process to put back
977 let dead = build(
978 "%1\tw:1.1\t/home/p\tclaude\t1.0\tdead\t-\thi",
979 &Input {
980 newver: "2.0",
981 width: 100,
982 ..Default::default()
983 },
984 );
985 assert!(dead[0].to_ansi().contains("\x1b[2;35m1.0"));
986 }
987
988 #[test]
989 fn a_host_that_could_not_answer_keeps_its_name_whole() {
990 // the second field is the message, not a target, and the row is left out
991 // of the shortening
992 let r = build(
993 "laptop-two:unreachable\tlaptop-two: no answer\t\t\t\tnote\t\t",
994 &Input {
995 width: 60,
996 only: "note",
997 ..Default::default()
998 },
999 );
1000 assert!(r[0].to_ansi().contains("laptop-two: no answer"));
1001 }
1002
1003 /// The outdated list holds exactly the rows the version column paints
1004 /// yellow, which is what makes it the list of rows ctrl-x and F8 act on.
1005 /// Same predicate for both, so the two can never disagree.
1006 #[test]
1007 fn the_outdated_list_holds_exactly_the_rows_painted_yellow() {
1008 let lines = "%1\ta:1.1\t/home/p\tclaude\t2.1.229\tidle\t-\tbehind\n\
1009 %2\tb:1.1\t/home/p\tclaude\t2.1.243\trun\t-\tcurrent\n\
1010 %3\tc:1.1\t/home/p\tgemini\t0.41.2\tinput\t-\tanother agent\n\
1011 ha:%4\td:1.1\t/home/p\tclaude\t2.1.229\tidle\t-\tover there";
1012 let r = build(
1013 lines,
1014 &Input {
1015 newver: "2.1.243",
1016 width: 100,
1017 outdated: true,
1018 ..Default::default()
1019 },
1020 );
1021 let ids: Vec<&str> = r.iter().map(|r| r.pane_id.as_str()).collect();
1022 assert_eq!(ids, ["%1"]);
1023 assert!(r[0].to_ansi().contains("\x1b[33m2.1.229"));
1024
1025 // …and the same list with nothing installed to compare against is
1026 // empty rather than everything: the mode is skipped there.
1027 let none = build(
1028 lines,
1029 &Input {
1030 width: 100,
1031 outdated: true,
1032 ..Default::default()
1033 },
1034 );
1035 assert!(none.is_empty());
1036 }
1037
1038 /// Being behind is not a state, so the list crosses all four of them: a
1039 /// session waiting for an answer is as behind as an idle one.
1040 #[test]
1041 fn the_outdated_list_is_not_one_state() {
1042 let lines = "%1\ta:1.1\t/home/p\tclaude\t1.0\tinput\t-\tasking\n\
1043 %2\tb:1.1\t/home/p\tclaude\t1.0\trun\t-\tworking\n\
1044 %3\tc:1.1\t/home/p\tclaude\t1.0\tidle\t-\tidle";
1045 let r = build(
1046 lines,
1047 &Input {
1048 newver: "2.0",
1049 width: 100,
1050 outdated: true,
1051 ..Default::default()
1052 },
1053 );
1054 assert_eq!(r.len(), 3);
1055 }
1056
1057 /// The background list holds the rows whose tenth field is `bg`, whatever
1058 /// their state: a turn that left a shell running is idle, and one started
1059 /// since can be working with that shell still going. A row with no tenth
1060 /// field, from a host whose taimux predates it, is not known to have any.
1061 #[test]
1062 fn the_background_list_holds_the_rows_with_work_in_flight() {
1063 let lines = "%1\ta:1.1\t/home/p\tclaude\t2.1\tidle\t-\twatching\t-\tbg\n\
1064 %2\tb:1.1\t/home/p\tclaude\t2.1\tidle\t-\tnothing left\t-\t-\n\
1065 %3\tc:1.1\t/home/p\tclaude\t2.1\trun\t-\tnew turn\t-\tbg\n\
1066 ha:%4\td:1.1\t/home/p\tclaude\t2.1\tidle\t-\tolder host\t-\n\
1067 ha:%5\te:1.1\t/home/p\tclaude\t2.1\tidle\t-\toldest host";
1068 let r = build(
1069 lines,
1070 &Input {
1071 width: 100,
1072 background: true,
1073 ..Default::default()
1074 },
1075 );
1076 let ids: Vec<&str> = r.iter().map(|r| r.pane_id.as_str()).collect();
1077 assert_eq!(ids, ["%1", "%3"]);
1078 // …and the field changes nothing on screen, nor what every other list holds
1079 let all = build(
1080 lines,
1081 &Input {
1082 width: 100,
1083 ..Default::default()
1084 },
1085 );
1086 assert_eq!(all.len(), 5);
1087 assert_eq!(r[0].plain(), all[0].plain());
1088 }
1089
1090 /// `with_background` widens one state to the rows with work in flight, in
1091 /// their own order and with their own marker: the idle one still shows none.
1092 /// A row from a host that cannot say stays out, as it does of the background
1093 /// list.
1094 #[test]
1095 fn one_state_plus_the_rows_with_work_in_flight() {
1096 let lines = "%1\ta:1.1\t/home/p\tclaude\t2.1\tidle\t-\twatching\t-\tbg\n\
1097 %2\tb:1.1\t/home/p\tclaude\t2.1\tidle\t-\tnothing left\t-\t-\n\
1098 %3\tc:1.1\t/home/p\tclaude\t2.1\trun\t-\tbusy\t-\t-\n\
1099 ha:%4\td:1.1\t/home/p\tclaude\t2.1\tidle\t-\tolder host\t-";
1100 let input = |with_background| Input {
1101 width: 100,
1102 only: "run",
1103 with_background,
1104 ..Default::default()
1105 };
1106 let ids = |r: &[Row]| r.iter().map(|r| r.pane_id.clone()).collect::<Vec<_>>();
1107 assert_eq!(ids(&build(lines, &input(false))), ["%3"]);
1108 let r = build(lines, &input(true));
1109 assert_eq!(ids(&r), ["%1", "%3"]);
1110 assert!(!r[0].plain().contains('◐'), "{}", r[0].plain());
1111 assert!(r[1].plain().contains('◐'), "{}", r[1].plain());
1112 }
1113
1114 #[test]
1115 fn one_state_only_when_asked() {
1116 let r = build(
1117 THREE,
1118 &Input {
1119 only: "run",
1120 width: 100,
1121 ..Default::default()
1122 },
1123 );
1124 assert_eq!(r.len(), 3);
1125 let r = build(
1126 THREE,
1127 &Input {
1128 only: "input",
1129 width: 100,
1130 ..Default::default()
1131 },
1132 );
1133 assert!(r.is_empty());
1134 }
1135
1136 #[test]
1137 fn a_blank_pane_title_borrows_the_one_its_conversation_recorded() {
1138 let mut ptitles = HashMap::new();
1139 ptitles.insert("%1".to_string(), "what it called itself".to_string());
1140 let r = build(
1141 "%1\tw:1.1\t/home/p\tclaude\t1.0\tidle\t-\t",
1142 &Input {
1143 width: 100,
1144 ptitles,
1145 ..Default::default()
1146 },
1147 );
1148 assert!(r[0].plain().contains("what it called itself"));
1149 }
1150
1151 /// The snippet takes the path column, but only on a row that does not already
1152 /// show what was typed: there is nothing to explain then, and the path is
1153 /// worth more.
1154 #[test]
1155 fn a_search_snippet_replaces_the_tail_unless_the_row_already_says_it() {
1156 let mut snips = HashMap::new();
1157 snips.insert("%10".to_string(), "…the words it said…".to_string());
1158 snips.insert("%11".to_string(), "…other words…".to_string());
1159 let r = build(
1160 THREE,
1161 &Input {
1162 cur: "%11",
1163 width: 100,
1164 home: "/home/p",
1165 query: "refactor",
1166 snips,
1167 ..Default::default()
1168 },
1169 );
1170 // %10's summary is "Refactor auth", so it already says it
1171 assert!(r[0].plain().contains("proj/web"));
1172 assert!(!r[0].plain().contains('⌕'));
1173 // %11's does not
1174 assert!(r[1].plain().contains("⌕ …other words…"));
1175 }
1176
1177 /// Whichever side carries the capital. `build` folds the terms, and a row
1178 /// showing `Refactor` answers a query for `REFACTOR` as well as one for
1179 /// `refactor`.
1180 #[test]
1181 fn says_it_ignores_case_both_ways() {
1182 assert!(says_it("Refactor auth", &["refactor".to_string()]));
1183 assert!(says_it("refactor auth", &["refactor".to_string()]));
1184 assert!(!says_it("refactor auth", &["rewrite".to_string()]));
1185 }
1186
1187 /// …and the row built from a shouted query keeps its path rather than being
1188 /// handed a snippet to explain a match it visibly already shows.
1189 #[test]
1190 fn a_shouted_query_still_counts_as_said_on_the_row() {
1191 let mut snips = HashMap::new();
1192 snips.insert("%10".to_string(), "…the words it said…".to_string());
1193 let r = build(
1194 THREE,
1195 &Input {
1196 width: 100,
1197 home: "/home/p",
1198 query: "REFACTOR",
1199 snips,
1200 ..Default::default()
1201 },
1202 );
1203 assert!(r[0].plain().contains("proj/web"));
1204 assert!(!r[0].plain().contains('⌕'));
1205 }
1206
1207 /// When a session last said something rides in a ninth field, and a row
1208 /// without one, from an older host or an agent that cannot say, is read as
1209 /// not knowing rather than refused. Nothing about it is drawn.
1210 #[test]
1211 fn the_last_message_is_read_off_a_ninth_field_when_there_is_one() {
1212 let rows = "%1\tw:1.1\t/a\tclaude\t2.1\tidle\t-\tone\t1700000000000\n\
1213 %2\tw:2.1\t/b\tcodex\t0.9\tidle\t-\ttwo\t-\n\
1214 %3\tw:3.1\t/c\tclaude\t2.1\tidle\t-\tthree\n";
1215 let r = build(rows, &Input::default());
1216 let since: Vec<Option<i64>> = r.iter().map(|r| r.since).collect();
1217 assert_eq!(since, [Some(1_700_000_000_000), None, None]);
1218 let eight = build(&taimux_core::panes::wire(rows, 8), &Input::default());
1219 assert_eq!(
1220 r.iter().map(Row::plain).collect::<Vec<_>>(),
1221 eight.iter().map(Row::plain).collect::<Vec<_>>(),
1222 "the field changes nothing on screen"
1223 );
1224 }
1225
1226 /// Two sessions and the shell between them, as one scan brings them back.
1227 const MIXED: &str = "%1\tw:1.1\t/home/p/a\tclaude\t2.1.229\tidle\t-\tagent one\t-\t-\n\
1228 %2\tw:2.1\t/home/p/b\tbash\t\tpane\t-\tlogs\t-\t-\n\
1229 ha:%3\tm:1.1\t/home/p/c\tssh\t\tpane\t-\tjump\t-\t-\n\
1230 %4\tw:3.1\t/home/p/d\tcodex\t0.9\tinput\t-\tagent two\t-\t-\n";
1231
1232 /// Every list of what sessions are doing leaves the panes with no session
1233 /// in them out, whatever its filter: they come in on the same scan.
1234 #[test]
1235 fn a_pane_with_no_agent_is_in_no_list_but_the_every_pane_one() {
1236 let ids = |input: &Input| -> Vec<String> {
1237 build(MIXED, input).into_iter().map(|r| r.pane_id).collect()
1238 };
1239 assert_eq!(ids(&Input::default()), ["%1", "%4"]);
1240 assert_eq!(
1241 ids(&Input {
1242 only: "idle",
1243 ..Default::default()
1244 }),
1245 ["%1"]
1246 );
1247 assert_eq!(
1248 ids(&Input {
1249 panes: true,
1250 ..Default::default()
1251 }),
1252 ["%1", "%2", "ha:%3", "%4"],
1253 "every pane, in the order the scan has them, another host's included"
1254 );
1255 }
1256
1257 /// In the every-pane list the command stands where an agent's name would,
1258 /// as quiet as the path, so a session still reads as one among the shells.
1259 #[test]
1260 fn a_plain_panes_command_is_painted_like_the_path() {
1261 let r = build(
1262 MIXED,
1263 &Input {
1264 panes: true,
1265 width: 100,
1266 ..Default::default()
1267 },
1268 );
1269 let paint_of =
1270 |row: &Row, text: &str| row.cells.iter().find(|c| c.text == text).map(|c| c.paint);
1271 assert_eq!(paint_of(&r[1], "bash"), Some(PATH));
1272 assert_eq!(paint_of(&r[0], "claude"), Some(MODE_ASK));
1273 assert!(r[1].plain().contains("logs"), "the summary it was given");
1274 }
1275
1276 /// An index can still hold what a session said under a pane id it has since
1277 /// left. A shell in that pane is not where those words are.
1278 #[test]
1279 fn a_plain_pane_never_carries_a_snippet_or_a_borrowed_title() {
1280 let rows = "%2\tw:2.1\t/home/p/b\tbash\t\tpane\t-\t\t-\t-\n";
1281 let r = build(
1282 rows,
1283 &Input {
1284 panes: true,
1285 width: 100,
1286 query: "deploy",
1287 snips: HashMap::from([("%2".to_string(), "…deploy…".to_string())]),
1288 ptitles: HashMap::from([("%2".to_string(), "old talk".to_string())]),
1289 ..Default::default()
1290 },
1291 );
1292 assert!(!r[0].plain().contains('⌕'));
1293 assert!(!r[0].plain().contains("old talk"));
1294 }
1295}