marver 0.0.20

A TUI workspace for AI agent sessions: tmux orchestration, git worktree management, and repo control in one place.
Documentation
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
//! The repo screen: what every repo is sitting at before any agent touches it.
//!
//! One row per repo the scan found — branch, how far it has drifted from what
//! it tracks and from the default branch, and how much is uncommitted — with
//! `f` and `p` on the row to fetch or fast-forward it.
//!
//! # Nothing here runs on this thread
//!
//! Reading a row costs several git subprocesses and fetching one costs a
//! network round trip, so a [`repos::Job`] is handed to a thread and its
//! [`repos::Update`]s are drained on the tick. Two things follow, and both are
//! deliberate:
//!
//! - **Rows appear as they are read**, rather than all at once at the end. A
//!   scan root with thirty repos in it fills the screen over a second or so
//!   instead of showing an empty one for the whole of it.
//! - **One job at a time.** A second is refused with a word about what is
//!   already running, rather than queued: the screen is a thing you look at for
//!   a moment, and a queue of fetches outliving your interest in them is worse
//!   than being told to press the key again.
//!
//! What is on screen while a job runs is the *previous* answer, which is honest
//! — it was true when it was read — and is why the title carries what is
//! happening rather than the rows being blanked.

use std::sync::mpsc::{Receiver, TryRecvError};

use ratatui::Frame;
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use ratatui::layout::{Constraint, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Cell, Paragraph, Row, Table, TableState};

use super::{Action, Context, Result, View};
use crate::domain::Repo;
use crate::repos::{self, Divergence, RepoStatus, Update};

/// A job in flight, and where its updates arrive.
struct Running {
    job: repos::Job,
    updates: Receiver<Update>,
}

pub struct ReposView {
    /// What the store knows, in the order the rows are shown.
    repos: Vec<Repo>,
    /// What git knows, filled in as the worker reports it. Parallel to
    /// [`Self::repos`] by index, so a row exists from the first frame and gains
    /// its numbers when they arrive.
    rows: Vec<Option<RepoStatus>>,
    table: TableState,
    running: Option<Running>,
    loaded: bool,
}

impl Default for ReposView {
    fn default() -> Self {
        Self::new()
    }
}

impl ReposView {
    pub fn new() -> Self {
        Self {
            repos: Vec::new(),
            rows: Vec::new(),
            table: TableState::default().with_selected(Some(0)),
            running: None,
            loaded: false,
        }
    }

    /// Read the repo list from the store and start reading their state.
    ///
    /// The list comes from the last scan rather than from the filesystem: the
    /// daemon owns scanning, and a screen that walked the disk itself would
    /// disagree with the repo picker on the new-task screen.
    fn load(&mut self, ctx: &mut Context) -> Result<()> {
        self.repos = ctx.store.list_repos(false)?;
        self.rows = vec![None; self.repos.len()];
        self.loaded = true;
        let last = self.repos.len().saturating_sub(1);
        if self.table.selected().unwrap_or(0) > last {
            self.table.select(Some(last));
        }
        self.start(repos::Job::Refresh(self.repos.clone()), ctx);
        Ok(())
    }

    /// Begin a job, unless one is already running.
    fn start(&mut self, job: repos::Job, ctx: &mut Context) {
        if let Some(running) = &self.running {
            ctx.say(format!("still {}", running.job.doing()));
            return;
        }
        self.running = Some(Running {
            updates: repos::spawn(job.clone()),
            job,
        });
    }

    /// Take whatever the worker has reported since the last look.
    ///
    /// Never blocks — `try_recv` until it is empty is the whole of it, which is
    /// why a fetch against an unreachable host costs the screen nothing.
    fn drain(&mut self, ctx: &mut Context) {
        let Some(running) = &self.running else {
            return;
        };
        loop {
            match running.updates.try_recv() {
                Ok(Update::Row(row)) => {
                    if let Some(slot) = self
                        .repos
                        .iter()
                        .position(|repo| repo.id == row.repo_id)
                        .and_then(|index| self.rows.get_mut(index))
                    {
                        *slot = Some(*row);
                    }
                }
                Ok(Update::Says(message)) => ctx.say(message),
                Ok(Update::Done) => break,
                Err(TryRecvError::Empty) => return,
                // The thread is gone without saying so. Treated as done, since
                // a screen stuck on "fetching" for ever is the worse failure.
                Err(TryRecvError::Disconnected) => break,
            }
        }
        if let Some(running) = self.running.take()
            && let Some(message) = running.job.did()
        {
            ctx.say(message);
        }
    }

    fn selected(&self) -> Option<&Repo> {
        self.table.selected().and_then(|i| self.repos.get(i))
    }

    fn move_by(&mut self, delta: isize) {
        if self.repos.is_empty() {
            return;
        }
        let current = self.table.selected().unwrap_or(0) as isize;
        let last = self.repos.len() as isize - 1;
        self.table
            .select(Some(current.saturating_add(delta).clamp(0, last) as usize));
    }

    fn row(&self, index: usize, repo: &Repo) -> Row<'static> {
        let Some(status) = self.rows.get(index).and_then(Option::as_ref) else {
            // Known to exist, not yet read. Dimmed rather than left blank, so
            // the difference between "still reading" and "nothing to say" is
            // visible while a refresh is running.
            return Row::new(vec![
                Cell::from(repo.name.clone()),
                Cell::from(Span::styled(
                    "reading…",
                    Style::default().add_modifier(Modifier::DIM),
                )),
            ]);
        };

        Row::new(vec![
            Cell::from(status.name.clone()),
            Cell::from(branch_cell(status)),
            // The upstream's name is left out when it is the branch's own name
            // on a remote, which is what it is nearly every time — the branch
            // column has already said it. It reappears the moment it differs,
            // because a branch tracking something other than its namesake is
            // exactly the thing you would want to be told.
            Cell::from(gap_cell(
                status.upstream.as_ref(),
                "untracked",
                status.branch.as_deref(),
            )),
            // The default's name always shows: `main` or `master`, local or
            // remote, is the whole content of this column.
            Cell::from(gap_cell(status.default.as_ref(), "", None)),
            Cell::from(changes_cell(status)),
        ])
    }
}

impl View for ReposView {
    fn title(&self) -> String {
        let count = self.repos.len();
        match &self.running {
            Some(running) => format!("Repos ({count}) · {}", running.job.doing()),
            None => format!("Repos ({count})"),
        }
    }

    fn render(&mut self, frame: &mut Frame, area: Rect, ctx: &mut Context) {
        if !self.loaded {
            let _ = self.load(ctx);
        }
        self.drain(ctx);

        if self.repos.is_empty() {
            frame.render_widget(
                Paragraph::new(vec![
                    Line::from(""),
                    Line::from("  No repos found."),
                    Line::from(""),
                    Line::from(Span::styled(
                        "  marver scans below --scan-root; check that it points at your repos.",
                        Style::default().add_modifier(Modifier::DIM),
                    )),
                ]),
                area,
            );
            return;
        }

        let rows: Vec<Row> = self
            .repos
            .iter()
            .enumerate()
            .map(|(index, repo)| self.row(index, repo))
            .collect();

        let table = Table::new(
            rows,
            [
                Constraint::Percentage(22),
                Constraint::Percentage(26),
                Constraint::Length(12),
                Constraint::Min(18),
                Constraint::Length(10),
            ],
        )
        .header(
            Row::new(vec!["repo", "branch", "upstream", "default", "changes"])
                .style(Style::default().add_modifier(Modifier::BOLD | Modifier::DIM)),
        )
        .row_highlight_style(Style::default().add_modifier(Modifier::REVERSED))
        .highlight_symbol("");

        frame.render_stateful_widget(table, area, &mut self.table);
    }

    fn handle_key(&mut self, key: KeyEvent, ctx: &mut Context) -> Result<Action> {
        if key
            .modifiers
            .intersects(KeyModifiers::CONTROL | KeyModifiers::ALT)
        {
            return Ok(match key.code {
                KeyCode::Char('q') | KeyCode::Char('c') => Action::Pop,
                _ => Action::None,
            });
        }

        match key.code {
            KeyCode::Char('q') | KeyCode::Esc => return Ok(Action::Pop),
            KeyCode::Char('j') | KeyCode::Down => self.move_by(1),
            KeyCode::Char('k') | KeyCode::Up => self.move_by(-1),
            KeyCode::Char('g') | KeyCode::Home => self.table.select(Some(0)),
            KeyCode::Char('G') | KeyCode::End => {
                self.table.select(Some(self.repos.len().saturating_sub(1)));
            }
            // Re-reads the list as well as the rows, since a scan may have
            // found something since this screen opened. Refused while a job is
            // running rather than deferred: `load` blanks every row before the
            // worker refills them, and doing that to a refresh that was never
            // going to start would leave the screen reading "reading…" for ever.
            KeyCode::Char('r') => match &self.running {
                Some(running) => ctx.say(format!("still {}", running.job.doing())),
                None => self.load(ctx)?,
            },
            KeyCode::Char('f') => {
                if let Some(repo) = self.selected().cloned() {
                    self.start(repos::Job::Fetch(repo), ctx);
                }
            }
            // Lower-case `p`, as on the task list, where it is also the key
            // that does the safe thing to the thing under the cursor.
            KeyCode::Char('p') => {
                if let Some(repo) = self.selected().cloned() {
                    self.start(repos::Job::Pull(repo), ctx);
                }
            }
            _ => {}
        }
        Ok(Action::None)
    }

    fn tick(&mut self, ctx: &mut Context) -> Result<()> {
        self.drain(ctx);
        Ok(())
    }

    fn keys(&self) -> Vec<(&'static str, &'static str)> {
        vec![
            ("j/k", "move"),
            ("f", "fetch"),
            ("p", "pull"),
            ("r", "refresh"),
            ("esc", "back"),
        ]
    }
}

/// The branch, or what stands in for one.
fn branch_cell(status: &RepoStatus) -> Line<'static> {
    if let Some(trouble) = &status.trouble {
        return Line::from(Span::styled(
            trouble.clone(),
            Style::default().fg(Color::Red),
        ));
    }
    match &status.branch {
        Some(branch) => Line::from(branch.clone()),
        // Not an error, and not styled as one: a detached HEAD is where some
        // repos legitimately sit. It is dimmed because it is not a name.
        None => Line::from(Span::styled(
            "detached",
            Style::default().add_modifier(Modifier::DIM),
        )),
    }
}

/// A drift as `↑2 ↓5 origin/main`, or a word saying why there is no number.
///
/// Both counts, and only the ones that are not zero — `↑0` next to a real
/// number invites reading the pair as one figure. Behind colours the cell,
/// because behind is the one that means "someone else has moved and you have
/// not seen it": ahead is work you did on purpose and already know about.
///
/// `namesake` is a branch whose name makes the reference redundant. Passing one
/// buys back the width that `origin/some-long-branch-name` would have spent
/// repeating the column to its left.
fn gap_cell(gap: Option<&Divergence>, missing: &str, namesake: Option<&str>) -> Line<'static> {
    let dim = Style::default().add_modifier(Modifier::DIM);
    let Some(gap) = gap else {
        return Line::from(Span::styled(missing.to_string(), dim));
    };
    let reference = match namesake {
        Some(branch) if mirrors(&gap.reference, branch) => String::new(),
        _ => format!(" {}", short(&gap.reference)),
    };
    if gap.is_level() {
        // "up to date" rather than "= origin/main" when the name is redundant:
        // the words say the same thing and read faster than the glyph.
        return Line::from(Span::styled(
            if reference.is_empty() {
                "up to date".to_string()
            } else {
                format!("={reference}")
            },
            dim,
        ));
    }

    let mut spans = Vec::new();
    if gap.ahead > 0 {
        spans.push(Span::styled(
            format!("{}", gap.ahead),
            Style::default().fg(Color::Cyan),
        ));
    }
    if gap.behind > 0 {
        if !spans.is_empty() {
            spans.push(Span::raw(" "));
        }
        spans.push(Span::styled(
            format!("{}", gap.behind),
            Style::default().fg(Color::Yellow),
        ));
    }
    if !reference.is_empty() {
        spans.push(Span::styled(reference, dim));
    }
    Line::from(spans)
}

/// Whether a ref is just this branch's name somewhere else.
///
/// `main` tracking `origin/main` is the ordinary case and the remote's name is
/// not news; `release-prep` tracking `origin/main` is news, and is what the
/// exception here keeps visible.
fn mirrors(reference: &str, branch: &str) -> bool {
    let reference = short(reference);
    reference == branch
        || reference
            .rsplit_once('/')
            .is_some_and(|(_, name)| name == branch)
}

/// `origin/main` shown as `origin/main`, but `refs/remotes/...` cut down.
///
/// git answers `@{upstream}` in the short form already; this is only insurance
/// against the long one reaching a column 14 wide.
fn short(reference: &str) -> String {
    reference
        .strip_prefix("refs/remotes/")
        .or_else(|| reference.strip_prefix("refs/heads/"))
        .unwrap_or(reference)
        .to_string()
}

/// How much is uncommitted, in the words the number deserves.
fn changes_cell(status: &RepoStatus) -> Line<'static> {
    if status.trouble.is_some() {
        return Line::from("");
    }
    match status.dirty {
        0 => Line::from(Span::styled(
            "clean",
            Style::default().add_modifier(Modifier::DIM),
        )),
        1 => Line::from(Span::styled("1 file", Style::default().fg(Color::Yellow))),
        n => Line::from(Span::styled(
            format!("{n} files"),
            Style::default().fg(Color::Yellow),
        )),
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::git::testing::init_repo;
    use crate::store::Store;
    use crate::tui::testing::{press, render_view, tick_view, with_context};
    use chrono::{TimeZone, Utc};
    use std::path::Path;
    use std::process::Command;
    use tempfile::TempDir;

    fn key(code: KeyCode) -> KeyEvent {
        KeyEvent::new(code, KeyModifiers::NONE)
    }

    fn store_with(repos: &[&Path]) -> Store {
        let store = Store::open_in_memory().unwrap();
        let now = Utc.timestamp_opt(0, 0).unwrap();
        for path in repos {
            let name = path.file_name().unwrap().to_string_lossy().into_owned();
            store.upsert_repo(path, &name, now).unwrap();
        }
        store
    }

    /// Drive the view until its worker has finished, as the event loop would.
    ///
    /// Bounded rather than looping until done: a hung worker should fail the
    /// test rather than hang the suite.
    fn settle(view: &mut ReposView, store: &mut Store) {
        for _ in 0..200 {
            tick_view(view, store);
            if view.running.is_none() {
                return;
            }
            std::thread::sleep(std::time::Duration::from_millis(10));
        }
        panic!("the worker never finished");
    }

    #[test]
    fn every_scanned_repo_gets_a_row_with_its_branch() {
        let tmp = TempDir::new().unwrap();
        let one = tmp.path().join("api");
        let two = tmp.path().join("web");
        init_repo(&one, "main");
        init_repo(&two, "trunk");
        let mut store = store_with(&[&one, &two]);

        let mut view = ReposView::new();
        render_view(&mut view, &mut store, 90, 10);
        settle(&mut view, &mut store);
        let screen = render_view(&mut view, &mut store, 90, 10);

        assert!(screen.iter().any(|l| l.contains("api")), "{screen:?}");
        assert!(screen.iter().any(|l| l.contains("main")), "{screen:?}");
        assert!(screen.iter().any(|l| l.contains("web")), "{screen:?}");
        assert!(screen.iter().any(|l| l.contains("trunk")), "{screen:?}");
    }

    #[test]
    fn rows_are_shown_before_they_have_been_read() {
        // The first frame lands before the worker has answered, and a repo the
        // store knows about must still have a row on it.
        let tmp = TempDir::new().unwrap();
        let repo = tmp.path().join("api");
        init_repo(&repo, "main");
        let mut store = store_with(&[&repo]);

        let mut view = ReposView::new();
        let screen = render_view(&mut view, &mut store, 90, 10);

        assert!(screen.iter().any(|l| l.contains("api")), "{screen:?}");
    }

    #[test]
    fn the_count_of_uncommitted_files_reaches_the_screen() {
        let tmp = TempDir::new().unwrap();
        let repo = tmp.path().join("api");
        init_repo(&repo, "main");
        std::fs::write(repo.join("a.txt"), "one").unwrap();
        std::fs::write(repo.join("b.txt"), "two").unwrap();
        let mut store = store_with(&[&repo]);

        let mut view = ReposView::new();
        render_view(&mut view, &mut store, 90, 10);
        settle(&mut view, &mut store);
        let screen = render_view(&mut view, &mut store, 90, 10);

        assert!(screen.iter().any(|l| l.contains("2 files")), "{screen:?}");
    }

    #[test]
    fn being_behind_is_shown_once_a_fetch_has_found_out() {
        let tmp = TempDir::new().unwrap();
        let origin = tmp.path().join("origin");
        init_repo(&origin, "main");
        let clone = tmp.path().join("api");
        let out = Command::new("git")
            .args(["clone", "-q"])
            .arg(&origin)
            .arg(&clone)
            .output()
            .unwrap();
        assert!(out.status.success(), "{out:?}");
        std::fs::write(origin.join("theirs.txt"), "new").unwrap();
        for args in [
            vec!["add", "."],
            vec![
                "-c",
                "user.email=t@t.invalid",
                "-c",
                "user.name=t",
                "commit",
                "-q",
                "-m",
                "theirs",
            ],
        ] {
            let out = Command::new("git")
                .arg("-C")
                .arg(&origin)
                .args(args)
                .output()
                .unwrap();
            assert!(out.status.success(), "{out:?}");
        }
        let mut store = store_with(&[&clone]);

        let mut view = ReposView::new();
        render_view(&mut view, &mut store, 90, 10);
        settle(&mut view, &mut store);
        let before = render_view(&mut view, &mut store, 90, 10);
        assert!(
            !before.iter().any(|l| l.contains("↓1")),
            "nothing has been fetched yet: {before:?}"
        );

        press(&mut view, &mut store, key(KeyCode::Char('f')));
        settle(&mut view, &mut store);
        let after = render_view(&mut view, &mut store, 90, 10);

        assert!(after.iter().any(|l| l.contains("↓1")), "{after:?}");
    }

    #[test]
    fn a_second_job_is_refused_rather_than_queued() {
        let tmp = TempDir::new().unwrap();
        let repo = tmp.path().join("api");
        init_repo(&repo, "main");
        let mut store = store_with(&[&repo]);

        let mut view = ReposView::new();
        // Loading starts a refresh, and nothing has drained it yet.
        with_context(&mut store, |ctx| view.load(ctx).unwrap());
        let running = view.running.as_ref().map(|r| r.job.doing());
        let repo = store.list_repos(false).unwrap()[0].clone();
        with_context(&mut store, |ctx| {
            view.start(repos::Job::Fetch(repo), ctx);
        });

        assert_eq!(
            view.running.as_ref().map(|r| r.job.doing()),
            running,
            "the first job must still be the one running"
        );
        settle(&mut view, &mut store);
    }

    /// The text of a cell, spans joined, as it reaches the screen.
    fn text(line: &Line<'_>) -> String {
        line.spans
            .iter()
            .map(|span| span.content.as_ref())
            .collect()
    }

    #[test]
    fn a_branch_tracking_its_namesake_does_not_repeat_the_name() {
        let level = Divergence {
            reference: "origin/main".into(),
            ahead: 0,
            behind: 0,
        };
        assert_eq!(
            text(&gap_cell(Some(&level), "", Some("main"))),
            "up to date"
        );

        let drifted = Divergence {
            reference: "origin/main".into(),
            ahead: 2,
            behind: 5,
        };
        assert_eq!(text(&gap_cell(Some(&drifted), "", Some("main"))), "↑2 ↓5");
    }

    #[test]
    fn a_branch_tracking_something_else_says_what() {
        // The case worth the column: `release-prep` is not `main`, and being
        // five behind `origin/main` is a different fact from being five behind
        // a branch of your own name.
        let gap = Divergence {
            reference: "origin/main".into(),
            ahead: 0,
            behind: 5,
        };
        assert_eq!(
            text(&gap_cell(Some(&gap), "", Some("release-prep"))),
            "↓5 origin/main"
        );
        // And the default column, which never has a namesake to lean on.
        assert_eq!(text(&gap_cell(Some(&gap), "", None)), "↓5 origin/main");
    }

    #[test]
    fn escape_goes_back() {
        let mut store = store_with(&[]);
        let mut view = ReposView::new();

        assert!(matches!(
            press(&mut view, &mut store, key(KeyCode::Esc)),
            Action::Pop
        ));
    }

    #[test]
    fn the_two_chords_that_leave_every_screen_leave_this_one() {
        let mut store = store_with(&[]);
        for chord in ['c', 'q'] {
            let mut view = ReposView::new();
            let key = KeyEvent::new(KeyCode::Char(chord), KeyModifiers::CONTROL);
            assert!(
                matches!(press(&mut view, &mut store, key), Action::Pop),
                "ctrl-{chord} must leave"
            );
        }
    }

    #[test]
    fn an_empty_scan_says_where_to_look_rather_than_showing_a_bare_table() {
        let mut store = store_with(&[]);
        let mut view = ReposView::new();

        let screen = render_view(&mut view, &mut store, 90, 10);
        assert!(
            screen.iter().any(|l| l.contains("No repos found")),
            "{screen:?}"
        );
        assert!(
            screen.iter().any(|l| l.contains("scan-root")),
            "and what to do about it: {screen:?}"
        );
    }

    #[test]
    fn a_repo_that_has_gone_is_flagged_in_place() {
        let tmp = TempDir::new().unwrap();
        let mut store = store_with(&[&tmp.path().join("was-here")]);

        let mut view = ReposView::new();
        render_view(&mut view, &mut store, 90, 10);
        settle(&mut view, &mut store);
        let screen = render_view(&mut view, &mut store, 90, 10);

        assert!(
            screen.iter().any(|l| l.contains("gone from disk")),
            "{screen:?}"
        );
    }
}