返回 CodeWhale
craft.rs
1 use ratatui::{buffer::Buffer, layout::Rect};
2
3 use crate::{
4 DataTrend, Depth, MeterSegment, MicroBadge, Paint, Panel, Role, SegmentedMeter, Theme,
5 };
6
7 use super::Entry;
8
9 pub(crate) fn entries() -> Vec<Entry> {
10 vec![Entry {
11 name: "craft",
12 width: 60,
13 height: 12,
14 draw: draw_craft,
15 }]
16 }
17
18 fn draw_craft(area: Rect, buf: &mut Buffer, theme: &Theme) {
19 let area = area.intersection(buf.area);
20 if area.is_empty() {
21 return;
22 }
23
24 let badge_h = 1.min(area.height);
25 if badge_h > 0 {
26 let mut x = area.x;
27 for (label, role, dot) in [
28 ("OKLab", Role::Accent, true),
29 ("Live", Role::Live, false),
30 ("80% Cap", Role::Attention, false),
31 ] {
32 let badge = MicroBadge::new(label)
33 .role(role)
34 .dot(dot)
35 .on_ground(Role::Background);
36 let w = badge.width(theme);
37 if x >= area.right() {
38 break;
39 }
40 let avail = area.right().saturating_sub(x);
41 badge.paint(Rect::new(x, area.y, w.min(avail), 1), buf, theme);
42 x = x.saturating_add(w.saturating_add(1));
43 }
44 }
45
46 let meter_y = area.y.saturating_add(2);
47 if meter_y < area.bottom() {
48 let segments = [
49 MeterSegment::new("System", 20.0, Role::Accent),
50 MeterSegment::new("History", 44.0, Role::Live),
51 MeterSegment::new("Tools", 14.0, Role::Attention),
52 ];
53 let meter_h = 2.min(area.bottom().saturating_sub(meter_y));
54 SegmentedMeter::new(&segments, 100.0)
55 .label("Context")
56 .threshold(0.80)
57 .pressure_gradient(true)
58 .show_legend(true)
59 .paint(Rect::new(area.x, meter_y, area.width, meter_h), buf, theme);
60 }
61
62 let panel_y = area.y.saturating_add(5);
63 if panel_y < area.bottom() {
64 let panel_h = area.bottom().saturating_sub(panel_y);
65 let panel_rect = Rect::new(area.x, panel_y, area.width, panel_h);
66 let body = Panel::new(Depth::Overlay)
67 .title("Throughput")
68 .aside("area-fill")
69 .focused(true)
70 .specular(true)
71 .draw(panel_rect, buf, theme);
72 if !body.is_empty() {
73 let values = [18.0, 26.0, 42.0, 58.0, 51.0, 64.0, 72.0, 66.0, 79.0, 84.0];
74 DataTrend::new("Tokens/s", &values)
75 .unit("tok/s")
76 .rows(body.height)
77 .area_fill(true)
78 .paint(body, buf, theme);
79 }
80 }
81 }
82
82 lines RUST