helix-toolbox 1.25.7

Build, configure and optimize a Linux machine from a terminal menu: installs, dotfiles, updates, backups and health checks, every change planned and confirmed first.
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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
//! The Repositories and Workspaces screens.

use super::super::*;
use super::{Ask, Cx, Read, ToolScreen, View};

/// The Git repositories under the project folders, and one of them opened.
#[derive(Default)]
pub(in crate::tui::app) struct Repos {
    /// Where to look for repositories, in place of the settings' places.
    pub(in crate::tui::app) places: Option<repos::Places>,
    /// The workspaces file, in place of the one beside the settings.
    pub(in crate::tui::app) workspaces_file: Option<PathBuf>,
    /// Where they were looked for, and what was found there.
    found: Option<(repos::Places, Vec<Summary>)>,
    pub(in crate::tui::app) reading: Read<(repos::Places, Vec<Summary>)>,
    /// The opened repository, read in full, and its tasks.
    pub(in crate::tui::app) open: Option<(Details, Vec<Task>)>,
    opening: Read<RepoOpened>,
    /// Why the repository asked for could not be read, answered after the
    /// screen was left.
    unread: Option<String>,
    /// A run while another screen was shown left what it read out of
    /// date.
    stale: bool,
    pub(in crate::tui::app) rows: Vec<RepoRow>,
}

/// A line of the Repositories screen: in the list, a repository; in one
/// repository, a file, branch, stash, commit or task, by its place.
#[derive(Clone, Debug)]
pub(in crate::tui::app) enum RepoRow {
    Heading(String),
    Text(String),
    Repository(usize),
    File(usize),
    Branch(usize),
    Stash(usize),
    Commit(usize),
    Task(usize),
}

/// One repository read, with its tasks, or why it could not be.
type RepoOpened = Result<(Details, Vec<Task>), String>;

/// A task's command as typed, and the shell a "fish:" or "bash:" in front
/// of it names.
pub(in crate::tui::app) fn task_shell(text: &str) -> (workspaces::Shell, String) {
    let text = text.trim();
    for (prefix, shell) in [
        ("fish:", workspaces::Shell::Fish),
        ("bash:", workspaces::Shell::Bash),
    ] {
        if let Some(rest) = text.strip_prefix(prefix)
            && !rest.trim().is_empty()
        {
            return (shell, rest.trim().to_string());
        }
    }
    (workspaces::Shell::Direct, text.to_string())
}

impl Repos {
    /// Where repositories are looked for: the tests' places, else those the
    /// settings name; none in a test that sets none.
    fn places_here(&self, cx: &Cx) -> Option<repos::Places> {
        if let Some(places) = &self.places {
            return Some(places.clone());
        }
        let settings = cx.settings_path?;
        Some(repos::places(settings, cx.host.home()))
    }

    fn workspaces_path(&self, settings_path: Option<&Path>) -> Option<PathBuf> {
        self.workspaces_file
            .clone()
            .or_else(|| settings_path.map(|settings| settings.with_file_name("workspaces.toml")))
    }

    fn kept(&self, settings_path: Option<&Path>) -> Workspaces {
        self.workspaces_path(settings_path)
            .and_then(|path| workspaces::load(&path).ok())
            .unwrap_or_default()
    }

    /// Find the repositories and read each, in the background on this
    /// machine; favorites first.
    fn read(&mut self, cx: &mut Cx) {
        let Some(places) = self.places_here(cx) else {
            self.found = Some((
                repos::Places {
                    roots: Vec::new(),
                    depth: repos::DEFAULT_DEPTH,
                    origin: "default".to_string(),
                },
                Vec::new(),
            ));
            self.build_rows(cx);
            return;
        };
        let kept = self.kept(cx.settings_path);
        self.reading.start(cx.host, move |_| {
            let found = repos::discover(&places);
            let mut summaries = repos::summaries(&repos::Here, &found);
            summaries.sort_by_key(|summary| !kept.favorite(&summary.path));
            (places, summaries)
        });
        self.build_rows(cx);
    }

    /// Read the list again, and the open repository with it.
    fn reload(&mut self, cx: &mut Cx) {
        self.read(cx);
        if let Some((found, _)) = &self.open {
            let path = found.summary.path.clone();
            self.open_repo(cx, path);
        }
    }

    /// Read one repository and its tasks, in the background on this machine.
    pub(in crate::tui::app) fn open_repo(&mut self, cx: &mut Cx, path: PathBuf) {
        let kept = self.kept(cx.settings_path);
        self.opening.start(cx.host, move |_| -> RepoOpened {
            let found = repos::details(&repos::Here, &path)?;
            let tasks = workspaces::tasks(&path, &kept);
            Ok((found, tasks))
        });
        self.build_rows(cx);
    }

    /// The repository asked for was read. The selection and the popup are
    /// the screen shown: when it was left, why it could not be read waits
    /// until it is shown again.
    fn opened(&mut self, cx: &mut Cx, read: RepoOpened) {
        let shown = cx.screen == Screen::Repositories;
        match read {
            Ok(open) => {
                let same = self.open.as_ref().map(|(found, _)| &found.summary.path)
                    == Some(&open.0.summary.path);
                self.open = Some(open);
                if !same && shown {
                    cx.selected.select(Some(0));
                }
                self.build_rows(cx);
            }
            Err(why) if shown => Self::cannot_read(cx, why),
            Err(why) => {
                self.unread = Some(why);
                self.build_rows(cx);
            }
        }
    }

    fn cannot_read(cx: &mut Cx, why: String) {
        *cx.popup = Some(Popup::Text(TextPopup::new(
            "Cannot read the repository",
            why,
            true,
        )));
    }

    /// Back from a repository to the list; false when the list is shown.
    fn close(&mut self, cx: &mut Cx) -> bool {
        if self.open.take().is_none() {
            return false;
        }
        cx.selected.select(Some(0));
        self.build_rows(cx);
        true
    }

    fn selected(&self, at: Option<usize>) -> Option<RepoRow> {
        self.rows.get(at?).cloned()
    }

    /// Enter: open a repository; in one, a file's diff, a branch to switch
    /// to, a stash to apply or a task to run.
    fn enter(&mut self, cx: &mut Cx) {
        let Some(row) = self.selected(cx.at()) else {
            return;
        };
        let Some((found, tasks)) = &self.open else {
            if let (RepoRow::Repository(index), Some((_, summaries))) = (row, &self.found)
                && let Some(summary) = summaries.get(index)
            {
                let path = summary.path.clone();
                self.open_repo(cx, path);
            }
            return;
        };
        match row {
            RepoRow::File(index) => {
                let Some(file) = found.files.get(index) else {
                    return;
                };
                let path = found.summary.path.clone();
                let mut text = String::new();
                for (staged, heading) in [(true, "Staged"), (false, "Not staged")] {
                    if (staged && !file.is_staged()) || (!staged && !file.has_unstaged()) {
                        continue;
                    }
                    match repos::diff(&repos::Here, &path, found, Some(&file.path), staged) {
                        Ok(shown) => {
                            text.push_str(&format!("{heading}:\n{}", shown.text));
                            if shown.truncated {
                                text.push_str("(cut short)\n");
                            }
                        }
                        Err(why) => text.push_str(&format!("{heading}: {why}\n")),
                    }
                }
                let text: String = text
                    .lines()
                    .map(|line| format!("{}\n", helix_toolbox_core::printable(line)))
                    .collect();
                *cx.popup = Some(Popup::Text(TextPopup::new(
                    helix_toolbox_core::printable(&file.path),
                    text,
                    false,
                )));
            }
            RepoRow::Branch(index) => {
                if let Some(branch) = found.branches.get(index).cloned()
                    && Some(&branch) != found.summary.branch.as_ref()
                {
                    self.plan_change(cx, Change::SwitchBranch(branch));
                }
            }
            RepoRow::Stash(index) => {
                if let Some(stash) = found.stashes.get(index) {
                    let id = stash.id.clone();
                    self.plan_change(cx, Change::ApplyStash(id));
                }
            }
            RepoRow::Task(index) => {
                if let Some(task) = tasks.get(index) {
                    cx.confirm_or_say(workspaces::plan_task(&found.summary.path, task));
                }
            }
            _ => {}
        }
    }

    /// Review a change to the open repository.
    pub(in crate::tui::app) fn plan_change(&self, cx: &mut Cx, change: Change) {
        let Some((found, _)) = &self.open else {
            return;
        };
        cx.confirm_or_say(repos::plan(&repos::Here, found, &change));
    }

    /// Space: stage the file's changes, or unstage it when all are staged.
    fn stage_selected(&self, cx: &mut Cx) {
        let (Some(RepoRow::File(index)), Some((found, _))) = (self.selected(cx.at()), &self.open)
        else {
            return;
        };
        let Some(file) = found.files.get(index) else {
            return;
        };
        let paths = vec![file.path.clone()];
        let change = if file.has_unstaged() || file.conflict {
            Change::Stage(paths)
        } else {
            Change::Unstage(paths)
        };
        self.plan_change(cx, change);
    }

    /// P: push to the upstream, or publish the branch to origin (or the
    /// only remote) when it has none.
    fn push(&self, cx: &mut Cx) {
        let Some((found, _)) = &self.open else {
            return;
        };
        let change = if found.push_to.is_some() {
            Change::Push
        } else {
            match found
                .remotes
                .iter()
                .find(|remote| *remote == "origin")
                .or(found.remotes.first())
            {
                Some(remote) => Change::Publish(remote.clone()),
                None => Change::Push,
            }
        };
        self.plan_change(cx, change);
    }

    fn toggle_favorite(&mut self, cx: &mut Cx) {
        let path = match (&self.open, self.selected(cx.at()), &self.found) {
            (Some((found, _)), ..) => found.summary.path.clone(),
            (None, Some(RepoRow::Repository(index)), Some((_, summaries))) => {
                match summaries.get(index) {
                    Some(summary) => summary.path.clone(),
                    None => return,
                }
            }
            _ => return,
        };
        let Some(file) = self.workspaces_path(cx.settings_path) else {
            return;
        };
        let mut kept = self.kept(cx.settings_path);
        let favorite = !kept.favorite(&path);
        kept.set_favorite(&path, favorite);
        if let Err(why) = workspaces::save(&file, &kept) {
            *cx.popup = Some(Popup::Text(TextPopup::new("It did not work", why, true)));
            return;
        }
        self.reload(cx);
    }

    /// Keep a command as a task of the open repository.
    pub(in crate::tui::app) fn add_task(
        &mut self,
        cx: &mut Cx,
        text: &str,
    ) -> Result<String, String> {
        let Some((found, _)) = &self.open else {
            return Err("No repository is open.".to_string());
        };
        // "fish: …" or "bash: …" runs it with that shell, as the window's
        // Run with choice; otherwise it runs as it is.
        let (shell, command) = task_shell(text);
        let mut id: String = command
            .to_lowercase()
            .chars()
            .map(|character| {
                if character.is_ascii_alphanumeric() {
                    character
                } else {
                    '-'
                }
            })
            .collect();
        while id.contains("--") {
            id = id.replace("--", "-");
        }
        let id: String = id.trim_matches('-').chars().take(40).collect();
        let path = found.summary.path.clone();
        let file = self
            .workspaces_path(cx.settings_path)
            .ok_or("There is no configuration folder to keep it in.")?;
        let mut kept = self.kept(cx.settings_path);
        kept.add_task(
            &path,
            Task {
                id: if id.is_empty() {
                    "task".to_string()
                } else {
                    id
                },
                name: command.chars().take(80).collect(),
                command: command.clone(),
                shell,
                detected: false,
            },
        )?;
        workspaces::save(&file, &kept)?;
        self.open_repo(cx, path);
        Ok(format!(
            "{command} is kept as a task in {}. Enter on it runs it, after you review it.",
            file.display()
        ))
    }

    /// x: remove the selected task, when it is one of the user's.
    fn remove_task(&mut self, cx: &mut Cx) {
        let (Some(RepoRow::Task(index)), Some((found, tasks))) =
            (self.selected(cx.at()), &self.open)
        else {
            return;
        };
        let Some(task) = tasks.get(index) else {
            return;
        };
        if task.detected {
            *cx.popup = Some(Popup::Text(TextPopup::new(
                "Not yours to remove",
                "The repository's manifest names this task; only tasks you added are removed.",
                true,
            )));
            return;
        }
        let (path, id) = (found.summary.path.clone(), task.id.clone());
        let Some(file) = self.workspaces_path(cx.settings_path) else {
            return;
        };
        let mut kept = self.kept(cx.settings_path);
        let removed = kept
            .remove_task(&path, &id)
            .and_then(|_| workspaces::save(&file, &kept));
        if let Err(why) = removed {
            *cx.popup = Some(Popup::Text(TextPopup::new("It did not work", why, true)));
            return;
        }
        self.open_repo(cx, path);
    }

    fn build_rows(&mut self, cx: &mut Cx) {
        let mut rows: Vec<RepoRow> = Vec::new();
        if let Some((found, tasks)) = &self.open {
            let summary = &found.summary;
            rows.push(RepoRow::Heading(format!(
                "{} on {}: {}",
                summary.name,
                summary.branch.as_deref().unwrap_or("a detached HEAD"),
                crate::repos::sync_words(summary)
            )));
            rows.push(RepoRow::Text(summary.path.display().to_string()));
            if let Some(origin) = &summary.origin {
                rows.push(RepoRow::Text(format!("origin {origin}")));
            }
            if let Some(busy) = &found.busy {
                rows.push(RepoRow::Text(format!(
                    "In the middle of {busy}: finish it with git."
                )));
            }
            if found.files.is_empty() {
                rows.push(RepoRow::Heading("No changes".into()));
            } else {
                rows.push(RepoRow::Heading(format!(
                    "Changes ({}, {} staged)",
                    found.files.len(),
                    found.staged()
                )));
                rows.extend((0..found.files.len()).map(RepoRow::File));
            }
            if !found.branches.is_empty() {
                rows.push(RepoRow::Heading("Branches".into()));
                rows.extend((0..found.branches.len()).map(RepoRow::Branch));
            }
            if !found.stashes.is_empty() {
                rows.push(RepoRow::Heading("Stashes".into()));
                rows.extend((0..found.stashes.len()).map(RepoRow::Stash));
            }
            rows.push(RepoRow::Heading("Tasks".into()));
            if tasks.is_empty() {
                rows.push(RepoRow::Text(
                    "None found in its manifests; n keeps a command of yours.".into(),
                ));
            }
            rows.extend((0..tasks.len()).map(RepoRow::Task));
            if !found.log.is_empty() {
                rows.push(RepoRow::Heading("Recent commits".into()));
                rows.extend((0..found.log.len()).map(RepoRow::Commit));
            }
        } else if self.opening.busy() {
            rows.push(RepoRow::Heading("Reading the repository…".into()));
        } else {
            match &self.found {
                None if self.reading.failed() => rows.push(RepoRow::Heading(
                    "Could not look for repositories: the search stopped without an answer. r looks again.".into(),
                )),
                None => rows.push(RepoRow::Heading("Looking for repositories…".into())),
                Some((places, summaries)) => {
                    let roots = if places.roots.is_empty() {
                        "no folders".to_string()
                    } else {
                        places
                            .roots
                            .iter()
                            .map(|root| root.display().to_string())
                            .collect::<Vec<_>>()
                            .join(", ")
                    };
                    if summaries.is_empty() {
                        rows.push(RepoRow::Heading("No repositories found".into()));
                    } else {
                        rows.push(RepoRow::Heading(format!(
                            "{} repositories",
                            summaries.len()
                        )));
                        rows.extend((0..summaries.len()).map(RepoRow::Repository));
                    }
                    rows.push(RepoRow::Text(format!(
                        "Under {roots}, {} folders deep (from the {}); [repositories] roots in settings.toml changes it.",
                        places.depth, places.origin
                    )));
                }
            }
            if self.reading.busy() && self.found.is_some() {
                rows.push(RepoRow::Text("Reading them again…".into()));
            }
        }
        self.rows = rows;
        cx.clamp();
    }
}

impl ToolScreen for Repos {
    fn open(&mut self, cx: &mut Cx) {
        if std::mem::take(&mut self.stale) {
            self.reload(cx);
        } else if self.found.is_none() {
            self.read(cx);
        } else {
            self.build_rows(cx);
        }
        if let Some(why) = self.unread.take() {
            Self::cannot_read(cx, why);
        }
    }

    fn len(&self, _view: &View) -> usize {
        self.rows.len()
    }

    fn key(&mut self, cx: &mut Cx, code: KeyCode) {
        let open = self.open.is_some();
        match code {
            KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => self.enter(cx),
            KeyCode::Char('h') | KeyCode::Left | KeyCode::Backspace => {
                if !self.close(cx) {
                    cx.ask(Ask::Sidebar);
                }
            }
            KeyCode::Char('r') => self.reload(cx),
            KeyCode::Char('f') => self.toggle_favorite(cx),
            _ if !open => {}
            KeyCode::Char(' ') => self.stage_selected(cx),
            KeyCode::Char('A') => self.plan_change(cx, Change::StageAll),
            KeyCode::Char('c') => {
                *cx.popup = Some(Popup::Ask(
                    InputPopup::new("Commit", "The commit message:").answering("Review"),
                    Asked::CommitMessage,
                ))
            }
            KeyCode::Char('b') => {
                *cx.popup = Some(Popup::Ask(
                    InputPopup::new("New branch", "The branch to create and switch to:")
                        .answering("Review"),
                    Asked::NewBranch,
                ))
            }
            KeyCode::Char('s') => {
                *cx.popup = Some(Popup::Ask(
                    InputPopup::new("Stash", "A message for the stash (new files go in it too):")
                        .answering("Review"),
                    Asked::StashMessage,
                ))
            }
            KeyCode::Char('F') => self.plan_change(cx, Change::Fetch),
            KeyCode::Char('p') => self.plan_change(cx, Change::Pull),
            KeyCode::Char('P') => self.push(cx),
            KeyCode::Char('n') => {
                *cx.popup = Some(Popup::Ask(
                    InputPopup::new(
                        "A task of yours",
                        "The command, run in the repository's folder, such as npm run serve; begin with fish: or bash: to run it with that shell:",
                    )
                    .answering("Keep"),
                    Asked::AddTask,
                ))
            }
            KeyCode::Char('x') => self.remove_task(cx),
            _ => {}
        }
    }

    fn hints(&self, _view: &View, at: Option<usize>, list: &mut Vec<Hint>) {
        list.push(Hint::new(&["↑↓"], "Navigate"));
        let Some((found, _)) = &self.open else {
            list.push(Hint::new(&["Enter"], "Open"));
            list.push(Hint::new(&["f"], "Favorite"));
            list.push(Hint::new(&["r"], "Read again"));
            return;
        };
        match self.selected(at) {
            Some(RepoRow::File(_)) => {
                list.push(Hint::new(&["Enter"], "Diff"));
                list.push(Hint::new(&["Space"], "Stage"));
            }
            Some(RepoRow::Branch(_)) => list.push(Hint::new(&["Enter"], "Switch")),
            Some(RepoRow::Stash(_)) => list.push(Hint::new(&["Enter"], "Apply")),
            Some(RepoRow::Task(_)) => {
                list.push(Hint::new(&["Enter"], "Run"));
                list.push(Hint::new(&["x"], "Remove"));
            }
            _ => {}
        }
        if found.staged() > 0 {
            list.push(Hint::new(&["c"], "Commit"));
        }
        list.push(Hint::new(&["b"], "Branch"));
        if !found.clean() {
            list.push(Hint::new(&["s"], "Stash"));
        }
        if !found.remotes.is_empty() {
            list.push(Hint::new(&["F", "p", "P"], "Fetch, pull, push"));
        }
        list.push(Hint::new(&["n"], "Task"));
        list.push(Hint::new(&["h"], "Back"));
    }

    fn poll(&mut self, cx: &mut Cx) -> bool {
        if let Some(answer) = self.reading.take() {
            if let Ok(found) = answer {
                self.found = Some(found);
            }
            self.build_rows(cx);
            return true;
        }
        if let Some(answer) = self.opening.take() {
            let read = answer.unwrap_or_else(|_| {
                Err("Reading the repository stopped without an answer.".into())
            });
            self.opened(cx, read);
            return true;
        }
        false
    }

    fn after_run(&mut self, cx: &mut Cx, reading: Reading) {
        if reading == Reading::Tools {
            self.reload(cx);
        }
    }

    fn stale(&mut self, reading: Reading) {
        if reading == Reading::Tools {
            self.stale = true;
        }
    }

    fn draw(&self, view: &View, frame: &mut Frame, area: Rect, state: &mut ListState) {
        let inner = view.page(
            frame,
            area,
            "Repositories",
            "The Git repositories under your project folders. Reading changes nothing; every change is reviewed first.",
        );
        view.fill(frame, inner);
        let focused = view.focused;
        let printable = helix_toolbox_core::printable;
        let muted = Style::default().fg(view.theme.muted());
        let kept = self.kept(view.settings_path);
        let mut items: Vec<Line> = Vec::new();
        for row in &self.rows {
            items.push(match row {
                RepoRow::Heading(text) => Line::styled(
                    printable(text),
                    Style::default().fg(view.theme.group()).bold(),
                ),
                RepoRow::Text(text) => Line::styled(format!("  {}", printable(text)), muted),
                RepoRow::Repository(index) => {
                    let Some(summary) = self
                        .found
                        .as_ref()
                        .and_then(|(_, summaries)| summaries.get(*index))
                    else {
                        continue;
                    };
                    let changes = match (&summary.problem, summary.changed) {
                        (Some(problem), _) => problem.clone(),
                        (None, 0) => "clean".to_string(),
                        (None, count) => format!("{count} changed"),
                    };
                    let color = if summary.problem.is_some() {
                        view.theme.failure()
                    } else if summary.changed > 0 {
                        view.theme.warning()
                    } else {
                        view.theme.success()
                    };
                    Line::from(vec![
                        Span::styled(
                            format!(
                                "{}{:<26}",
                                if kept.favorite(&summary.path) {
                                    "★ "
                                } else {
                                    "  "
                                },
                                printable(&summary.name)
                            ),
                            Style::default().fg(view.theme.entry()),
                        ),
                        Span::styled(
                            format!(
                                "{:<20}",
                                printable(summary.branch.as_deref().unwrap_or("(detached)"))
                            ),
                            muted,
                        ),
                        Span::styled(format!("{changes:<14}"), Style::default().fg(color)),
                        Span::styled(format!("{:<18}", crate::repos::sync_words(summary)), muted),
                        Span::styled(
                            printable(summary.last.as_deref().unwrap_or_default()),
                            muted,
                        ),
                    ])
                }
                RepoRow::File(index) => {
                    let Some(file) = self
                        .open
                        .as_ref()
                        .and_then(|(found, _)| found.files.get(*index))
                    else {
                        continue;
                    };
                    let color = if file.conflict {
                        view.theme.failure()
                    } else if file.is_staged() && !file.has_unstaged() {
                        view.theme.success()
                    } else {
                        view.theme.warning()
                    };
                    Line::from(vec![
                        Span::styled(
                            format!(
                                "  {} {:<13}",
                                if file.is_staged() { "●" } else { "○" },
                                file.state()
                            ),
                            Style::default().fg(color),
                        ),
                        Span::styled(
                            format!(
                                "{}{}",
                                printable(&file.path),
                                file.original
                                    .as_deref()
                                    .map(|original| format!(" (was {})", printable(original)))
                                    .unwrap_or_default()
                            ),
                            Style::default().fg(view.theme.entry()),
                        ),
                    ])
                }
                RepoRow::Branch(index) => {
                    let Some((found, _)) = &self.open else {
                        continue;
                    };
                    let branch = &found.branches[*index];
                    let current = found.summary.branch.as_ref() == Some(branch);
                    Line::styled(
                        format!(
                            "  {} {}",
                            if current { "●" } else { " " },
                            printable(branch)
                        ),
                        Style::default().fg(if current {
                            view.theme.success()
                        } else {
                            view.theme.entry()
                        }),
                    )
                }
                RepoRow::Stash(index) => {
                    let Some((found, _)) = &self.open else {
                        continue;
                    };
                    let stash = &found.stashes[*index];
                    Line::from(vec![
                        Span::styled(
                            format!("  {:<12}", stash.name),
                            Style::default().fg(view.theme.entry()),
                        ),
                        Span::styled(printable(&stash.subject), muted),
                    ])
                }
                RepoRow::Commit(index) => {
                    let Some((found, _)) = &self.open else {
                        continue;
                    };
                    let commit = &found.log[*index];
                    Line::from(vec![
                        Span::styled(format!("  {:<10}", commit.hash), muted),
                        Span::styled(
                            format!(
                                "{:<12}",
                                commit
                                    .at
                                    .map(helix_toolbox_engine::date)
                                    .unwrap_or_default()
                            ),
                            muted,
                        ),
                        Span::styled(
                            printable(&commit.subject),
                            Style::default().fg(view.theme.entry()),
                        ),
                    ])
                }
                RepoRow::Task(index) => {
                    let Some((_, tasks)) = &self.open else {
                        continue;
                    };
                    let task = &tasks[*index];
                    Line::from(vec![
                        Span::styled(
                            format!("  {:<28}", printable(&task.name)),
                            Style::default().fg(view.theme.entry()),
                        ),
                        Span::styled(
                            format!(
                                "{}{}{}",
                                if task.detected { "" } else { "yours: " },
                                match task.shell {
                                    workspaces::Shell::Direct => "",
                                    workspaces::Shell::Fish => "fish: ",
                                    workspaces::Shell::Bash => "bash: ",
                                },
                                printable(&task.command)
                            ),
                            muted,
                        ),
                    ])
                }
            });
        }
        let list = List::new(view.measure(items))
            .block(view.card("Repositories"))
            .highlight_style(view.highlight(focused))
            .highlight_symbol(view.marker(focused))
            .scroll_padding(1);
        bordered_list(frame, list, inner, state, view.hits);
    }
}