返回 CodeWhale
artifacts.rs
根目录 / vendor / codewhale-ratatui / src / gallery / artifacts.rs
1 //! Artifact fixtures over illustrative caller data, without filesystem or run claims.
2
3 use ratatui::{buffer::Buffer, layout::Rect};
4
5 use super::Entry;
6 use crate::{
7 Artifact, ArtifactChip, ArtifactChipRow, ArtifactKind, ArtifactShelf, Paint, ReceiptValue,
8 State, Theme,
9 };
10
11 fn artifact(area: Rect, buf: &mut Buffer, theme: &Theme) {
12 Artifact::new("Release checklist.md", ArtifactKind::File, State::Done)
13 .detail("docs/release-checklist.md")
14 .action("Open")
15 .receipt("Size", ReceiptValue::Bytes(Some(4280)))
16 .paint(area, buf, theme);
17 }
18
19 fn shelf(area: Rect, buf: &mut Buffer, theme: &Theme) {
20 ArtifactShelf::new(vec![
21 Artifact::new("Release checklist.md", ArtifactKind::File, State::Done)
22 .detail("docs/release-checklist.md")
23 .action("Open")
24 .receipt("Size", ReceiptValue::Bytes(Some(4280))),
25 Artifact::new(
26 "Conversation changes",
27 ArtifactKind::Review,
28 State::NeedsYou,
29 )
30 .detail("Composer and transcript")
31 .action("Review")
32 .receipt("Files", ReceiptValue::Count(Some(3))),
33 Artifact::new("Local verification", ArtifactKind::Run, State::Done)
34 .detail("Reported by the host")
35 .action("Inspect")
36 .receipt("Checks", ReceiptValue::Count(Some(15))),
37 Artifact::new("Working notes", ArtifactKind::Link, State::Ready)
38 .detail("Project reference")
39 .action("Open"),
40 ])
41 .selected(1)
42 .focused(true)
43 .paint(area, buf, theme);
44 }
45
46 fn narrow(area: Rect, buf: &mut Buffer, theme: &Theme) {
47 ArtifactShelf::new(vec![
48 Artifact::new(
49 "cafe\u{301} 鲸鱼 — terminal review.md",
50 ArtifactKind::File,
51 State::Done,
52 )
53 .detail("notes/terminal-review.md")
54 .action("Open"),
55 Artifact::new(
56 "Changes still need a decision",
57 ArtifactKind::Review,
58 State::NeedsYou,
59 )
60 .detail("A long caller-provided review summary")
61 .action("Review"),
62 Artifact::new("Verification has gaps", ArtifactKind::Run, State::NeedsYou)
63 .status_word("Finished with gaps")
64 .detail("One check was not reported")
65 .action("Inspect"),
66 ])
67 .selected(2)
68 .focused(true)
69 .omitted(1)
70 .paint(area, buf, theme);
71 }
72
73 fn unknown(area: Rect, buf: &mut Buffer, theme: &Theme) {
74 ArtifactShelf::new(vec![
75 Artifact::new("Imported report", ArtifactKind::File, State::Unknown)
76 .detail("No verification reported")
77 .action("Inspect")
78 .receipt("Size", ReceiptValue::Bytes(None)),
79 Artifact::new("Check failed", ArtifactKind::Run, State::Failed)
80 .detail("The host reported an error")
81 .action("Read error"),
82 ])
83 .selected(0)
84 .paint(area, buf, theme);
85 }
86
87 fn empty(area: Rect, buf: &mut Buffer, theme: &Theme) {
88 ArtifactShelf::new(Vec::new()).paint(area, buf, theme);
89 }
90
91 fn chip(area: Rect, buf: &mut Buffer, theme: &Theme) {
92 ArtifactChip::new("summary.md", ArtifactKind::File, State::Done).paint(area, buf, theme);
93 }
94
95 fn chip_row(area: Rect, buf: &mut Buffer, theme: &Theme) {
96 ArtifactChipRow::new(vec![
97 ArtifactChip::new("summary.md", ArtifactKind::File, State::Done),
98 ArtifactChip::new("review.diff", ArtifactKind::Review, State::NeedsYou),
99 ArtifactChip::new("ci-log.txt", ArtifactKind::Run, State::Working),
100 ])
101 .paint(area, buf, theme);
102 }
103
104 pub(crate) fn entries() -> Vec<Entry> {
105 vec![
106 Entry {
107 name: "artifact",
108 width: 80,
109 height: 2,
110 draw: artifact,
111 },
112 Entry {
113 name: "artifact-shelf",
114 width: 80,
115 height: 8,
116 draw: shelf,
117 },
118 Entry {
119 name: "artifact-narrow",
120 width: 40,
121 height: 5,
122 draw: narrow,
123 },
124 Entry {
125 name: "artifact-unknown",
126 width: 80,
127 height: 4,
128 draw: unknown,
129 },
130 Entry {
131 name: "artifact-empty",
132 width: 40,
133 height: 2,
134 draw: empty,
135 },
136 Entry {
137 name: "artifact-chip",
138 width: 40,
139 height: 1,
140 draw: chip,
141 },
142 Entry {
143 name: "artifact-chip-row",
144 width: 60,
145 height: 1,
146 draw: chip_row,
147 },
148 ]
149 }
150
150 lines RUST