Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T04:26:19.911Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

diff_stat.rs

94 lines · 2.6 KB · rust
1use crate::Tooltip;
2use crate::prelude::*;
3use num_format::{Locale, ToFormattedString};
4
5#[derive(IntoElement, RegisterComponent)]
6pub struct DiffStat {
7    id: ElementId,
8    added: usize,
9    removed: usize,
10    label_size: LabelSize,
11    tooltip: Option<SharedString>,
12}
13
14impl DiffStat {
15    pub fn new(id: impl Into<ElementId>, added: usize, removed: usize) -> Self {
16        Self {
17            id: id.into(),
18            added,
19            removed,
20            label_size: LabelSize::Small,
21            tooltip: None,
22        }
23    }
24
25    pub fn label_size(mut self, label_size: LabelSize) -> Self {
26        self.label_size = label_size;
27        self
28    }
29
30    pub fn tooltip(mut self, tooltip: impl Into<SharedString>) -> Self {
31        self.tooltip = Some(tooltip.into());
32        self
33    }
34}
35
36impl RenderOnce for DiffStat {
37    fn render(self, _: &mut Window, _cx: &mut App) -> impl IntoElement {
38        let tooltip = self.tooltip;
39        let added = self.added.to_formatted_string(&Locale::en);
40        let removed = self.removed.to_formatted_string(&Locale::en);
41
42        h_flex()
43            .id(self.id)
44            .gap_1()
45            .child(
46                Label::new(format!("+\u{2009}{added}"))
47                    .color(Color::Success)
48                    .size(self.label_size),
49            )
50            .child(
51                Label::new(format!("\u{2012}\u{2009}{removed}"))
52                    .color(Color::Error)
53                    .size(self.label_size),
54            )
55            .when_some(tooltip, |this, tooltip| {
56                this.tooltip(Tooltip::text(tooltip))
57            })
58    }
59}
60
61impl Component for DiffStat {
62    fn scope() -> ComponentScope {
63        ComponentScope::VersionControl
64    }
65
66    fn description() -> &'static str {
67        "A compact summary of additions and deletions for a diff, \
68        displayed as colored insertion and deletion counts."
69    }
70
71    fn preview(_window: &mut Window, cx: &mut App) -> AnyElement {
72        let container = || {
73            h_flex()
74                .py_4()
75                .w_72()
76                .justify_center()
77                .border_1()
78                .border_color(cx.theme().colors().border_variant)
79                .bg(cx.theme().colors().panel_background)
80        };
81
82        let diff_stat_example = vec![single_example(
83            "Default",
84            container()
85                .child(DiffStat::new("id", 1_234, 5_678))
86                .into_any_element(),
87        )];
88
89        example_group(diff_stat_example)
90            .vertical()
91            .into_any_element()
92    }
93}
94
Served at tenant.openagents/omega Member data and write actions are omitted.