tix-tracker 0.11.0

A terminal issue tracker: markdown + YAML frontmatter issues with a kanban TUI and CLI
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
#[allow(clippy::wildcard_imports)]
use super::*;

/// An empty chain, for tests with no graph to hand.
#[cfg(test)]
pub(super) fn no_chain() -> crate::relationships::DependencyChain {
    crate::relationships::DependencyChain {
        root: 0,
        paths: vec![],
        truncated: false,
    }
}

/// One `label: value` line in the detail pane, in the pane's own field style.
pub(super) fn health_line(label: &str, value: &str) -> Line<'static> {
    Line::from(vec![
        Span::styled(format!("{label}: "), Style::default().fg(Color::DarkGray)),
        Span::raw(value.to_string()),
    ])
}

/// The columns of the shared time table, in the order `tix time show` prints them.
///
/// The one difference from that table's header casing is typographic: both surfaces
/// label the same five fields in the same order, so a reader comparing the pane with
/// the CLI is comparing values, not columns.
pub(super) const TIME_COLUMNS: [&str; 5] = ["ENTRY", "MINUTES", "DATE", "AUTHOR", "NOTE"];

/// The column widths, one per [`TIME_COLUMNS`] entry.
pub(super) const TIME_WIDTHS: [usize; 5] = [18, 7, 10, 14, 0];
#[allow(clippy::too_many_lines)]
pub fn render(detail: &DetailState, f: &mut Frame, area: Rect, theme: &crate::ui::color::Theme) {
    let mut lines: Vec<Line<'static>> = Vec::new();
    let mut files_line_index: Option<usize> = None;

    let fields: Vec<(&str, String)> = vec![
        ("number", detail.issue.number.to_string()),
        ("title", detail.issue.title.clone()),
        ("status", detail.issue.status.to_string()),
        // The category label, from the service's own `label()` — never reworded
        // here (T023 step 1). Rendered as a plain field so it is greppable in the
        // detail view exactly as the other frontmatter fields are.
        // The WIP row appears only when the board configures a limit for this
        // issue's column: a limit-free board's detail view is byte-identical to what
        // it rendered before this mission.
        ("wip", detail.wip.clone().unwrap_or_default()),
        (
            "category",
            detail
                .category
                .as_ref()
                .map(|(label, _)| label.clone())
                .unwrap_or_else(|| "(unmapped)".to_string()),
        ),
        ("priority", detail.issue.priority.to_string()),
        ("created", detail.issue.created.clone()),
        ("updated", detail.issue.updated.clone()),
    ];

    for (key, value) in &fields {
        lines.push(Line::from(vec![
            Span::styled(format!("{key}: "), Style::default().fg(Color::DarkGray)),
            Span::raw(value.clone()),
        ]));
    }

    // The health block (WP06 T031/T033): the same facts the CLI prints — the state,
    // its layer, the policy version, the contributors, the audit entries — plus every
    // diagnostic with its remedy. Rendered from the shared DTO, so a reader comparing
    // this pane with `tix health show` sees one set of facts rather than two.
    if let Some(health) = &detail.health {
        let mut layer = format!(
            "{} ({}, {})",
            health.state,
            health.source,
            health
                .recorded_policy_version
                .as_deref()
                .unwrap_or("no policy version recorded")
        );
        if let Some(recorded) = &health.recorded {
            if recorded != &health.state {
                layer.push_str(&format!(" recorded `{recorded}`"));
            }
        }
        lines.push(health_line("health", &layer));
        if let Some(derived) = &health.rollup {
            let contributors: Vec<String> = derived
                .contributors
                .iter()
                .map(|contributor| format!("#{} {}", contributor.number, contributor.state))
                .collect();
            lines.push(health_line(
                "health derived",
                &format!(
                    "{} ({}, {} contributor{}: {})",
                    derived.state,
                    derived.policy_version,
                    derived.contributors.len(),
                    if derived.contributors.len() == 1 {
                        ""
                    } else {
                        "s"
                    },
                    if contributors.is_empty() {
                        "nothing contributes yet".to_string()
                    } else {
                        contributors.join(", ")
                    }
                ),
            ));
        }
        lines.push(health_line(
            "health history",
            &format!(
                "{} entr{}",
                health.events.len(),
                if health.events.len() == 1 { "y" } else { "ies" }
            ),
        ));
    }
    for diagnostic in &detail.health_diagnostics {
        lines.push(health_line(
            "health diagnostic",
            &format!("{}: {}", diagnostic.kind.as_str(), diagnostic.message),
        ));
        if let Some(remedy) = &diagnostic.remedy {
            lines.push(health_line("  remedy", remedy));
        }
    }

    if let Some(rendered) = render_assignee(detail.issue.assignee.as_deref()) {
        lines.push(Line::from(vec![
            Span::styled("assignee: ", Style::default().fg(Color::DarkGray)),
            Span::raw(rendered),
        ]));
    }

    if let Some(estimate) = &detail.issue.estimate {
        lines.push(Line::from(vec![
            Span::styled("estimate: ", Style::default().fg(Color::DarkGray)),
            Span::raw(estimate.clone()),
        ]));
    }

    // The capacity block (WP06 T031): the issue's own contributing estimate and the
    // scope context it is counted in, from the shared calculation. Read-only — the
    // pane renders the DTO's values and never offers to change one — and an issue in
    // no scope draws no block at all rather than an empty heading.
    if !detail.capacity.is_empty() {
        lines.push(Line::from(Span::styled("", Style::default())));
        lines.push(Line::from(Span::styled(
            "capacity:",
            Style::default()
                .fg(Color::DarkGray)
                .add_modifier(Modifier::BOLD),
        )));
        for view in &detail.capacity {
            lines.push(Line::from(vec![
                Span::styled("  ", Style::default()),
                Span::styled(
                    view.scope.clone(),
                    Style::default().add_modifier(Modifier::BOLD),
                ),
            ]));
            lines.push(health_line("    this issue", &view.issue_line));
            for (key, value) in &view.fields {
                lines.push(health_line(&format!("    {key}"), value));
            }
            if !view.diagnostics.is_empty() {
                lines.push(health_line(
                    "    findings",
                    &view.diagnostics.len().to_string(),
                ));
                for diagnostic in &view.diagnostics {
                    for line in diagnostic.lines() {
                        lines.push(health_line("      ", line));
                    }
                }
            }
        }
    }

    // The time block (WP05 T024): the issue's current entries and their total, from
    // the shared aggregation DTO — the same rows and the same total the CLI's
    // `tix time show` and this page's Time tab render, so the pane cannot count a
    // minute the CLI would not. Read-only: the pane draws the DTO's values and never
    // offers to change one, and the mutations live on the Stats page's Time tab,
    // which routes them through the same service.
    //
    // The block is drawn even for an issue with no entry, because the total's typed
    // state is the answer: `nothing` ("this issue recorded nothing") and `recorded
    // 0` ("an entry recorded zero minutes") are different facts, and a pane that drew
    // nothing would leave the reader to guess which one this is (C-005).
    {
        let filter =
            crate::time_tracking::filters::TimeFilter::new().for_issue(detail.issue.number);
        let snapshot =
            crate::time_tracking::aggregate::TimeSnapshot::of(std::slice::from_ref(&detail.issue));
        let total = snapshot.total(&filter);
        lines.push(Line::from(Span::styled("", Style::default())));
        lines.push(Line::from(Span::styled(
            "time:",
            Style::default()
                .fg(Color::DarkGray)
                .add_modifier(Modifier::BOLD),
        )));
        lines.push(health_line("  state", total.state().as_str()));
        lines.push(health_line("  total", &dash_number(total.total_minutes)));
        lines.push(health_line("  entries", &total.entry_count.to_string()));
        if total.is_partial() {
            // Only when the total is not the whole story: the counts say why the
            // number above must be read with the findings below (C-005).
            lines.push(health_line(
                "  malformed",
                &total.malformed_count.to_string(),
            ));
            lines.push(health_line("  undated", &total.undated_count.to_string()));
        }
        let deleted = snapshot.deletions_on(detail.issue.number).len();
        let corrected = snapshot.corrections_on(detail.issue.number);
        if deleted > 0 || corrected > 0 {
            // The History side, shown beside the current one: a correction and a
            // deletion keep their prior value in History, which is what makes them
            // auditable rather than silent (C-003, C-004).
            lines.push(health_line("  history deleted", &deleted.to_string()));
            lines.push(health_line("  history corrected", &corrected.to_string()));
        }
        let rows: Vec<&crate::time_tracking::aggregate::IndexedEntry> = snapshot
            .entries()
            .iter()
            .filter(|indexed| filter.selects(indexed.issue, &indexed.entry))
            .collect();
        if !rows.is_empty() {
            // The table's own heading and rows, indented like the fields above: the
            // heading is a label line rather than a `label: value` pair, because the
            // five column names are not a value of the pane's.
            lines.push(Line::from(Span::styled(
                format!("  {}", time_entry_heading()),
                Style::default().fg(Color::DarkGray),
            )));
            for indexed in rows {
                lines.push(Line::from(vec![
                    Span::styled("  ", Style::default()),
                    Span::raw(time_entry_row(&indexed.entry)),
                ]));
            }
        }
        for finding in &total.diagnostics {
            lines.push(health_line(
                "  finding",
                &format!("{}: {}", finding.kind.as_str(), finding.reason),
            ));
            // The remedy is what the reader does about it, so it travels with the
            // finding rather than being left to the CLI's refusal block.
            lines.push(health_line("    remedy", &finding.remedy));
        }
    }

    if let Some(commit) = &detail.issue.commit {
        lines.push(Line::from(vec![
            Span::styled("commit: ", Style::default().fg(Color::DarkGray)),
            Span::raw(commit.clone()),
        ]));
    }

    if !detail.issue.labels.is_empty() {
        // Each label renders in its tag color when `docs/tags` configures one
        // (tix #1530); an unconfigured label keeps the default foreground.
        let mut spans = vec![Span::styled(
            "labels: ",
            Style::default().fg(Color::DarkGray),
        )];
        for (index, label) in detail.issue.labels.iter().enumerate() {
            if index > 0 {
                spans.push(Span::raw(", "));
            }
            let style = theme
                .tag(label)
                .map_or_else(Style::default, |color| Style::default().fg(color));
            spans.push(Span::styled(label.clone(), style));
        }
        lines.push(Line::from(spans));
    }

    // The `related:` block (tix #1513). Prominent and **near the top**, above the
    // relationship rows: `related_issues` is the cross-repository surface the user
    // came to this pane for, and a block below the dependency graph would be below
    // the fold on a long issue. Non-empty only — an issue with no `related_issues:`
    // field draws nothing, because an empty heading would be noise on every issue.
    //
    // The selected entry carries a `>` marker exactly like the relationship row, so
    // `o` (follow) acts on something the reader can see. `related_cursor` is clamped
    // on every mutation, so indexing here cannot panic.
    if !detail.related.is_empty() {
        let accent = Style::default()
            .fg(Color::Magenta)
            .add_modifier(Modifier::BOLD);
        lines.push(Line::from(vec![
            Span::styled("related: ", accent),
            // The count, so a long list is legible at a glance. Stated rather than
            // implied by the number of following lines, which the viewport may clip.
            Span::styled(detail.related.len().to_string(), accent),
        ]));
        let cursor = detail.related_cursor;
        for (index, entry) in detail.related.iter().enumerate() {
            let marker = if index == cursor {
                Span::styled("  > ", Style::default().fg(Color::Cyan))
            } else {
                Span::styled("    ", Style::default())
            };
            lines.push(Line::from(vec![
                marker,
                Span::styled(entry.display(), Style::default().fg(Color::Magenta)),
            ]));
        }
    }

    if !detail.relationships.is_empty() {
        // The selected edge is marked, because `E` and `d` act on it and a key that
        // acts on an invisible selection is a key the user cannot use. The marker is
        // `>` on the row itself rather than a separate "selected: …" line, so the
        // row's text is unchanged and stays byte-comparable with `tix view`'s.
        //
        // `rel_cursor` is clamped by `DetailState::clamp_rel_cursor` on every
        // mutation, so indexing here cannot panic even if a future caller forgets.
        let cursor = detail.rel_cursor;
        // Owned strings, because `lines` is `Vec<Line<'static>>` — the pane builds
        // every row that way, and borrowing `rel.display` here would pin the whole
        // vector to the detail's lifetime.
        let mut spans: Vec<Span<'static>> = vec![Span::styled(
            "links: ",
            Style::default().fg(Color::DarkGray),
        )];
        for (index, rel) in detail.relationships.iter().enumerate() {
            if index > 0 {
                spans.push(Span::raw(", "));
            }
            if index == cursor {
                spans.push(Span::styled("> ", Style::default().fg(Color::Cyan)));
            }
            spans.push(Span::raw(rel.display.clone()));
        }
        lines.push(Line::from(spans));
    }

    // Field order matches `tix view --show relationships` exactly:
    // relationships, then chain, then blocked (`surface-parity.md` §2 requires the
    // *outcome* to match and permits presentation to differ **if documented**;
    // WP06 T027 asks for the same order outright, and one order for both surfaces
    // is one fewer thing to explain).
    //
    // WP04 deliberately put the blocked reason first, on the grounds that it is
    // "the fact that changes what the reader should do next". That is a
    // presentation preference rather than a correctness claim — the row is on the
    // same screen either way — so it yields to the shared order. The reasoning is
    // recorded rather than deleted, because if this ever moves back the reason
    // should come with it.
    if detail.chain.paths.is_empty() {
        // The empty state is **stated**, not omitted. `tix view` prints
        // "No dependency chain for #N", and a detail pane that prints nothing
        // cannot distinguish "there is no chain" from "the chain was not
        // computed" — two very different facts about the same issue.
        lines.push(Line::from(vec![
            Span::styled("chain: ", Style::default().fg(Color::DarkGray)),
            Span::styled("none", Style::default().fg(Color::DarkGray)),
        ]));
    } else {
        for (depth, path) in detail.chain.paths.iter().enumerate() {
            let rendered: Vec<String> = path
                .iter()
                .map(|node| {
                    let title = node.title.trim();
                    if title.is_empty() {
                        format!("#{}", node.number)
                    } else {
                        format!("#{} {}", node.number, title)
                    }
                })
                .collect();
            let label = if depth == 0 { "chain: " } else { "        " };
            lines.push(Line::from(vec![
                Span::styled(label, Style::default().fg(Color::DarkGray)),
                Span::raw(rendered.join(" -> ")),
            ]));
        }
    }

    // Likewise the blocked state. An unblocked issue says so. Silently omitting
    // the row would make "not blocked" and "not looked at" the same picture.
    match &detail.blocked {
        Some(reason) => lines.push(Line::from(vec![
            Span::styled("blocked: ", Style::default().fg(Color::Red)),
            Span::styled(
                reason.clone(),
                Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
            ),
        ])),
        None => lines.push(Line::from(vec![
            Span::styled("blocked: ", Style::default().fg(Color::DarkGray)),
            Span::styled("not blocked", Style::default().fg(Color::DarkGray)),
        ])),
    }

    // The hierarchy block. **Same facts, same order as the CLI block** (parent,
    // child count, rollup, children) — the parity contract requires the content
    // to match even though the presentation does not.
    lines.push(Line::from(Span::styled("", Style::default())));
    lines.push(Line::from(Span::styled(
        "hierarchy:",
        Style::default()
            .fg(Color::DarkGray)
            .add_modifier(Modifier::BOLD),
    )));
    lines.push(Line::from(vec![
        Span::styled("  parent: ", Style::default().fg(Color::DarkGray)),
        Span::raw(crate::commands::parent::parent_text(&detail.hierarchy)),
    ]));
    lines.push(Line::from(vec![
        Span::styled("  ", Style::default()),
        Span::raw(detail.hierarchy.child_count_line()),
    ]));
    lines.push(Line::from(vec![
        Span::styled("  ", Style::default()),
        Span::raw(detail.hierarchy.completion_line()),
    ]));
    for child in &detail.hierarchy.children {
        lines.push(Line::from(vec![
            Span::styled("    ", Style::default()),
            Span::raw(child.display.clone()),
        ]));
    }
    // An explicit empty state, not a bare heading — the CLI block says
    // "No children for #N" and a silent omission would read as "not looked at".
    if !detail.hierarchy.has_children() {
        lines.push(Line::from(vec![
            Span::styled("    ", Style::default()),
            Span::raw(crate::commands::parent::no_children_text(
                detail.hierarchy.number,
            )),
        ]));
    }

    // The epic block (WP04 T019, FR-003, C-005): the same facts `tix show` prints —
    // the id, the name, the hierarchy summary, and the rollup figures — because both
    // render the service's canonical rows ([`crate::commands::view::EpicBlockEntry`]).
    // The pane adds styling, never a fact. An issue in no epic draws nothing at all,
    // not an empty heading.
    if !detail.epics.is_empty() {
        lines.push(Line::from(Span::styled("", Style::default())));
        lines.push(Line::from(Span::styled(
            "epics:",
            Style::default()
                .fg(Color::DarkGray)
                .add_modifier(Modifier::BOLD),
        )));
        for entry in &detail.epics {
            lines.push(Line::from(vec![
                Span::styled("  ", Style::default()),
                Span::raw(entry.heading.clone()),
            ]));
            for line in &entry.detail {
                lines.push(Line::from(vec![
                    Span::styled("    ", Style::default()),
                    Span::raw(line.clone()),
                ]));
            }
        }
        // FR-004: the pane never becomes the only way to reach an issue. The epic
        // layer is a presentation, and a member's detail opens from the epic view's
        // member list directly — stated here so the affordance is explicit rather
        // than implied by the absence of a trap.
        lines.push(Line::from(vec![
            Span::styled("  ", Style::default()),
            Span::styled(
                "members open directly from the epic view — no epic layer",
                Style::default().fg(Color::DarkGray),
            ),
        ]));
    }

    if detail.chain.truncated {
        // Said, not silently dropped: a partial chain shown as a whole one is a
        // false statement about the graph.
        lines.push(Line::from(Span::styled(
            format!(
                "note: chain display truncated at {} nodes; the chain may continue",
                crate::relationships::MAX_CHAIN_NODES
            ),
            Style::default().fg(Color::Yellow),
        )));
    }

    if !detail.issue.files.is_empty() {
        lines.push(Line::from(vec![
            Span::styled("files: ", Style::default().fg(Color::DarkGray)),
            Span::raw(detail.issue.files.join(", ")),
        ]));
        files_line_index = Some(lines.len() - 1);
    }

    lines.push(Line::from(""));
    lines.push(Line::from(Span::styled(
        "---",
        Style::default().fg(Color::DarkGray),
    )));
    lines.push(Line::from(""));

    for line_text in detail.issue.body.lines() {
        lines.push(Line::from(Span::raw(line_text.to_string())));
    }

    let content_lines = lines.len();
    let title = if detail.read_only {
        // An external file has no store to write through, so the pane says so
        // rather than offering an `e` that would fail (#1513).
        "Detail [read-only] [Esc=back]"
    } else {
        "Detail [Esc=back e=edit A=agent]"
    };
    let para = Paragraph::new(lines)
        .scroll((detail.scroll_offset, 0))
        .block(Block::default().borders(Borders::ALL).title(title));

    // tix #1442: the pane records its own geometry, so a page step means the page
    // the reader is looking at and no step can scroll past the last line into a
    // blank pane. Recorded here because only the renderer knows either number.
    let viewport = area.height.saturating_sub(2); // the block's two border rows
    detail.viewport.set(viewport);
    detail.max_scroll.set(
        u16::try_from(content_lines)
            .unwrap_or(u16::MAX)
            .saturating_sub(viewport),
    );

    f.render_widget(para, area);

    if let Some(idx) = files_line_index {
        inject_files_hyperlinks(
            f.buffer_mut(),
            area,
            idx,
            detail.scroll_offset,
            &detail.issue.files,
        );
    }
}

/// Render an assignee for the detail view (FR-030):
/// - a full git identity (`Name <email>`) is shown verbatim (identity form
///   sniffed on the `<>` pair),
/// - a bare handle gets the cosmetic `@` prefix,
/// - an already `@`-prefixed value passes through unchanged,
/// - unassigned renders no line at all.
pub fn render_assignee(assignee: Option<&str>) -> Option<String> {
    let raw = assignee?;
    if raw.contains('<') && raw.contains('>') {
        return Some(raw.to_string());
    }
    if raw.starts_with('@') {
        return Some(raw.to_string());
    }
    Some(format!("@{raw}"))
}

/// A zero-width OSC 8 terminal hyperlink wrapping `label` around `uri`, so a
/// `files:` entry renders as a clickable link in supporting terminals. The
/// sequence is invisible and only has an effect when emitted verbatim.
pub fn hyperlink(uri: &str, label: &str) -> String {
    format!("{}{}{}", osc8_start(uri), label, osc8_end())
}

pub(super) fn osc8_start(uri: &str) -> String {
    format!("\u{1b}]8;;{uri}\u{1b}\\")
}

pub(super) fn osc8_end() -> String {
    "\u{1b}]8;;\u{1b}\\".to_string()
}

/// Best-effort `file://` URI for a repo-relative path, resolved against the
/// current working directory (the repo root when tix runs from it). No path
/// validation — a missing file still gets a clickable entry (D3 non-goal).
pub(super) fn file_uri(path: &str) -> String {
    if path.starts_with("file://") {
        return path.to_string();
    }
    let abs = std::path::absolute(path).unwrap_or_else(|_| path.into());
    format!("file://{}", abs.to_string_lossy())
}

/// Wrap every `files:` entry on its rendered line in an OSC 8 hyperlink.
///
/// ratatui's [`Buffer::set_stringn`] strips control characters from span
/// content, so the escape sequences are spliced into the already-rendered
/// cells instead: the opening sequence is prepended to the first cell of each
/// path and the reset sequence appended to its last cell. The text between
/// them passes through untouched, keeping the visible layout identical. Both
/// spliced cells are forced to single-cell width
/// ([`CellDiffOption::ForcedWidth`]) so the render diff treats the escape
/// sequence as zero-width and does not skip the following path cells as the
/// trailing columns of a wide glyph. Entries truncated by the block's inner
/// width are skipped best-effort.
pub(super) fn inject_files_hyperlinks(
    buf: &mut Buffer,
    area: Rect,
    line_index: usize,
    scroll_offset: u16,
    files: &[String],
) {
    let inner_top = area.top() + 1;
    let scrolled = line_index as i32 - scroll_offset as i32;
    if scrolled < 0 {
        return;
    }
    let y0 = inner_top + scrolled as u16;
    if y0 >= area.bottom() {
        return;
    }
    let (x0, inner_right) = (area.left() + 1, area.right().saturating_sub(1));
    let mut x = x0 + "files: ".len() as u16;
    for entry in files {
        if entry.is_empty() {
            continue;
        }
        let len = entry.chars().count() as u16;
        if x + len > inner_right {
            break;
        }
        let uri = file_uri(entry);
        let first = &mut buf[(x, y0)];
        first.set_symbol(&format!("{}{}", osc8_start(&uri), first.symbol()));
        first.set_diff_option(CellDiffOption::ForcedWidth(
            NonZeroU16::new(1).expect("one is non-zero"),
        ));
        let last = &mut buf[(x + len - 1, y0)];
        last.set_symbol(&format!("{}{}", last.symbol(), osc8_end()));
        last.set_diff_option(CellDiffOption::ForcedWidth(
            NonZeroU16::new(1).expect("one is non-zero"),
        ));
        x += len + 2; // `, ` separator
    }
}