返回 CodeWhale
workbar.rs
1 //! The eight Codewhale work-dock panels, with ordinary example rows.
2
3 use ratatui::{buffer::Buffer, layout::Rect, text::Line};
4
5 use super::Entry;
6 use crate::{
7 DiffReviewFile, DiffReviewHeader, DiffScope, Paint, Role, TaskProgressHeader, Theme, Workbar,
8 WorkbarAgent, WorkbarPanel, WorkbarPlacement, WorkbarRow, WorkbarTab, WorkbarTone,
9 };
10
11 fn tabs() -> Vec<WorkbarTab> {
12 WorkbarPanel::ORDER
13 .into_iter()
14 .map(|panel| match panel {
15 WorkbarPanel::Tasks => WorkbarTab::new(panel).count(3),
16 WorkbarPanel::Fleet => WorkbarTab::new(panel).count(2),
17 WorkbarPanel::Jobs => WorkbarTab::new(panel).count(1),
18 WorkbarPanel::Files => WorkbarTab::new(panel).count(3),
19 WorkbarPanel::Notes => WorkbarTab::new(panel).count(2),
20 _ => WorkbarTab::new(panel),
21 })
22 .collect()
23 }
24
25 fn rows(panel: WorkbarPanel) -> Vec<WorkbarRow> {
26 let dot = "·";
27 match panel {
28 WorkbarPanel::Tasks => vec![
29 WorkbarRow::new("graph:read", "Read the existing component")
30 .mark("✓")
31 .tone(WorkbarTone::Success)
32 .detail("completed"),
33 WorkbarRow::new("graph:extract", "Extract the native work dock")
34 .mark("●")
35 .tone(WorkbarTone::Live)
36 .detail("in progress"),
37 WorkbarRow::new("graph:document", "Document the reusable API")
38 .mark("○")
39 .detail("pending"),
40 ],
41 WorkbarPanel::Fleet => vec![
42 WorkbarRow::new("worker:build", "Builder").mark("●").agent(
43 WorkbarAgent::new(
44 "builder",
45 "running",
46 "Extract the dock and keep the native layout",
47 )
48 .elapsed_seconds(754)
49 .tokens(111_900)
50 .remaining(2),
51 ),
52 WorkbarRow::new("worker:review", "Reviewer")
53 .mark("✓")
54 .agent(
55 WorkbarAgent::new(
56 "reviewer",
57 "completed",
58 "Review tab and keyboard navigation",
59 )
60 .elapsed_seconds(183),
61 ),
62 ],
63 WorkbarPanel::Terminal => vec![WorkbarRow::new(
64 "terminal:host",
65 "Terminal sessions are supplied by the host",
66 )],
67 WorkbarPanel::Jobs => vec![
68 WorkbarRow::new("shell:gallery", "Render the component gallery")
69 .mark("●")
70 .tone(WorkbarTone::Live)
71 .detail("running"),
72 WorkbarRow::new("shell:check", "Check formatting")
73 .mark("✓")
74 .tone(WorkbarTone::Success)
75 .detail("completed"),
76 ],
77 WorkbarPanel::Files => vec![
78 WorkbarRow::new("files:edited", "Edited 2")
79 .mark("▾")
80 .tone(WorkbarTone::Heading)
81 .selectable(false),
82 WorkbarRow::new("files:edit:workbar", "src/components/workbar.rs")
83 .mark("✎")
84 .tone(WorkbarTone::Success)
85 .detail("+48 -12"),
86 WorkbarRow::new("files:edit:gallery", "src/gallery/workbar.rs")
87 .mark("✎")
88 .tone(WorkbarTone::Success)
89 .detail("+22 -4"),
90 WorkbarRow::new("files:read", "Read 1")
91 .mark("▾")
92 .tone(WorkbarTone::Heading)
93 .selectable(false),
94 WorkbarRow::new("files:read:source", "work_surface/render/mod.rs")
95 .mark("·")
96 .selectable(false),
97 ],
98 WorkbarPanel::Notes => vec![
99 WorkbarRow::new("notes:1", "Keep the native dock tab order")
100 .mark("▪")
101 .tone(WorkbarTone::Live)
102 .detail("/note show 1"),
103 WorkbarRow::new("notes:2", "Make each row independently selectable")
104 .mark("▪")
105 .tone(WorkbarTone::Live)
106 .detail("/note show 2"),
107 ],
108 WorkbarPanel::Context => vec![
109 WorkbarRow::new(
110 "context:budget",
111 format!("48k of 128k {dot} 38% {dot} compacts at 90%"),
112 )
113 .mark("◔")
114 .tone(WorkbarTone::Live)
115 .detail("/context for the full source map"),
116 WorkbarRow::new(
117 "context:system",
118 format!("system + tools {dot} 8.4k {dot} 24 tools"),
119 )
120 .mark("·")
121 .selectable(false),
122 WorkbarRow::new(
123 "context:conversation",
124 format!("conversation {dot} 18 {dot} 29.2k"),
125 )
126 .mark("·")
127 .selectable(false),
128 WorkbarRow::new("context:tool-output", format!("tool output {dot} 10.4k"))
129 .mark("·")
130 .selectable(false),
131 WorkbarRow::new("context:compact", "compact now")
132 .mark("▸")
133 .tone(WorkbarTone::Live)
134 .detail("/compact"),
135 ],
136 WorkbarPanel::Git => vec![
137 WorkbarRow::new("git:branch", format!("feature/work-dock {dot} up to date"))
138 .mark("⎇")
139 .tone(WorkbarTone::Live)
140 .detail("example/component-kit"),
141 WorkbarRow::new("git:changes", "2 modified files")
142 .mark("±")
143 .tone(WorkbarTone::Live)
144 .detail("/diff"),
145 WorkbarRow::new("git:commit", "Extract reusable work dock")
146 .mark("·")
147 .detail("latest commit"),
148 ],
149 WorkbarPanel::Cost => vec![
150 WorkbarRow::new("price:session", format!("session {dot} $0.42"))
151 .mark("$")
152 .tone(WorkbarTone::Live)
153 .detail("/cost for the full ledger"),
154 WorkbarRow::new("price:agents", format!("agents {dot} $0.18"))
155 .mark("·")
156 .detail("2 of 2 agents priced")
157 .selectable(false),
158 WorkbarRow::new(
159 "price:cache",
160 format!("cache hit {dot} parent 72% {dot} agents 64%"),
161 )
162 .mark("·")
163 .detail("/cache for per-turn cache telemetry"),
164 ],
165 }
166 }
167
168 pub(crate) fn sample(panel: WorkbarPanel) -> Workbar {
169 let rows = rows(panel);
170 let selected = rows
171 .iter()
172 .find(|row| row.selectable)
173 .map(|row| row.id.clone());
174 let mut dock = Workbar::new(panel, rows).tabs(tabs()).focused(true);
175 if let Some(selected) = selected {
176 dock = dock.selected(selected);
177 }
178 if panel == WorkbarPanel::Tasks {
179 let dot = "·";
180 dock = dock
181 .goal("Make the work dock reusable")
182 .progress(format!("TODO {dot} 1/3 {dot} 2 left"));
183 }
184 dock
185 }
186
187 fn tasks(area: Rect, buf: &mut Buffer, theme: &Theme) {
188 sample(WorkbarPanel::Tasks).paint(area, buf, theme);
189 }
190 fn fleet(area: Rect, buf: &mut Buffer, theme: &Theme) {
191 sample(WorkbarPanel::Fleet).paint(area, buf, theme);
192 }
193 fn jobs(area: Rect, buf: &mut Buffer, theme: &Theme) {
194 sample(WorkbarPanel::Jobs).paint(area, buf, theme);
195 }
196 fn files(area: Rect, buf: &mut Buffer, theme: &Theme) {
197 sample(WorkbarPanel::Files).paint(area, buf, theme);
198 }
199 fn notes(area: Rect, buf: &mut Buffer, theme: &Theme) {
200 sample(WorkbarPanel::Notes).paint(area, buf, theme);
201 }
202 fn context(area: Rect, buf: &mut Buffer, theme: &Theme) {
203 sample(WorkbarPanel::Context).paint(area, buf, theme);
204 }
205 fn git(area: Rect, buf: &mut Buffer, theme: &Theme) {
206 sample(WorkbarPanel::Git).paint(area, buf, theme);
207 }
208 fn cost(area: Rect, buf: &mut Buffer, theme: &Theme) {
209 sample(WorkbarPanel::Cost).paint(area, buf, theme);
210 }
211 fn top(area: Rect, buf: &mut Buffer, theme: &Theme) {
212 sample(WorkbarPanel::Tasks)
213 .placement(WorkbarPlacement::Top)
214 .paint(area, buf, theme);
215 }
216
217 fn narrow(area: Rect, buf: &mut Buffer, theme: &Theme) {
218 let rows = (0..12)
219 .map(|index| {
220 WorkbarRow::new(format!("graph:{index}"), format!("Plan step {}", index + 1))
221 .mark(if index == 3 { "●" } else { "○" })
222 .tone(if index == 3 {
223 WorkbarTone::Live
224 } else {
225 WorkbarTone::Muted
226 })
227 })
228 .collect();
229 Workbar::new(WorkbarPanel::Tasks, rows)
230 .tabs(tabs())
231 .goal("Extract the native dock")
232 .progress(if theme.ascii() {
233 "TODO . 3/12 . 9 left"
234 } else {
235 "TODO · 3/12 · 9 left"
236 })
237 .focused(true)
238 .selected("graph:3")
239 .offset(3)
240 .paint(area, buf, theme);
241 }
242
243 fn side_with(placement: WorkbarPlacement, area: Rect, buf: &mut Buffer, theme: &Theme) {
244 let area = area.intersection(buf.area);
245 let dock = sample(WorkbarPanel::Fleet).placement(placement);
246 let regions = dock.regions(area);
247 if regions.content.height > 0 && regions.content.width > 0 {
248 buf.set_line(
249 regions.content.x,
250 regions.content.y,
251 &Line::styled("Codewhale", theme.fg(Role::Foreground)),
252 regions.content.width,
253 );
254 if regions.content.height > 2 {
255 buf.set_line(
256 regions.content.x,
257 regions.content.y + 2,
258 &Line::styled("The conversation keeps its space.", theme.fg(Role::Muted)),
259 regions.content.width,
260 );
261 }
262 }
263 if let Some(area) = regions.dock {
264 dock.placement(regions.placement).paint(area, buf, theme);
265 }
266 }
267 fn left(area: Rect, buf: &mut Buffer, theme: &Theme) {
268 side_with(WorkbarPlacement::Left, area, buf, theme);
269 }
270 fn right(area: Rect, buf: &mut Buffer, theme: &Theme) {
271 side_with(WorkbarPlacement::Right, area, buf, theme);
272 }
273
274 fn task_progress(area: Rect, buf: &mut Buffer, theme: &Theme) {
275 TaskProgressHeader::new(2, 5)
276 .active("Verify workbar snapshots")
277 .paint(area, buf, theme);
278 }
279 fn diff_review(area: Rect, buf: &mut Buffer, theme: &Theme) {
280 let files = [
281 DiffReviewFile::new("src/workbar.rs", 24, 6).viewed(true),
282 DiffReviewFile::new("src/diff.rs", 18, 2),
283 ];
284 DiffReviewHeader::from_files(DiffScope::Branch, &files).paint(area, buf, theme);
285 }
286
287 pub(crate) fn entries() -> Vec<Entry> {
288 [
289 (
290 "workbar-tasks",
291 104,
292 7,
293 tasks as fn(Rect, &mut Buffer, &Theme),
294 ),
295 ("workbar-fleet", 104, 5, fleet),
296 ("workbar-jobs", 104, 5, jobs),
297 ("workbar-files", 104, 8, files),
298 ("workbar-notes", 104, 5, notes),
299 ("workbar-context", 104, 8, context),
300 ("workbar-git", 104, 6, git),
301 ("workbar-cost", 104, 6, cost),
302 ("workbar-top", 104, 7, top),
303 ("workbar-narrow", 38, 8, narrow),
304 ("workbar-left", 104, 12, left),
305 ("workbar-right", 104, 12, right),
306 ("workbar-task-progress", 64, 1, task_progress),
307 ("diff-review-header", 48, 1, diff_review),
308 ]
309 .into_iter()
310 .map(|(name, width, height, draw)| Entry {
311 name,
312 width,
313 height,
314 draw,
315 })
316 .collect()
317 }
318
318 lines RUST