返回 CodeWhale
primitives.rs
根目录 / vendor / codewhale-ratatui / src / gallery / primitives.rs
1 use ratatui::{buffer::Buffer, layout::Rect};
2
3 use crate::{
4 ChecksMark, ChecksState, Count, KeyHint, MotionMode, Notice, Paint, Role, Skeleton, Theme,
5 };
6
7 use super::Entry;
8
9 pub(crate) fn entries() -> Vec<Entry> {
10 vec![Entry {
11 name: "primitives",
12 width: 56,
13 height: 10,
14 draw: draw_primitives,
15 }]
16 }
17
18 fn draw_primitives(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 notice = Notice::warning("Provider rate limit")
25 .body("Using fallback route while quota recovers.")
26 .action(KeyHint::new("r", "retry"))
27 .dismissable(true);
28 let notice_h = notice.height(area.width, theme).min(area.height);
29 notice.paint(
30 Rect {
31 x: area.x,
32 y: area.y,
33 width: area.width,
34 height: notice_h,
35 },
36 buf,
37 theme,
38 );
39
40 let y = area.y.saturating_add(notice_h + 1);
41 if y < area.bottom() {
42 let skel = Skeleton::text(2).motion(MotionMode::Reduced);
43 let skel_h = skel
44 .height(area.width, theme)
45 .min(area.bottom().saturating_sub(y));
46 skel.paint(
47 Rect {
48 x: area.x,
49 y,
50 width: area.width,
51 height: skel_h,
52 },
53 buf,
54 theme,
55 );
56 }
57
58 let y = area.y.saturating_add(notice_h + 4);
59 if y < area.bottom() {
60 let count = Count::new(120).max(99).role(Role::Attention);
61 count.paint(
62 Rect {
63 x: area.x,
64 y,
65 width: area.width.min(6),
66 height: 1,
67 },
68 buf,
69 theme,
70 );
71 let checks = ChecksMark::new(ChecksState::Passing).count(12);
72 let x = area.x.saturating_add(6);
73 if x < area.right() {
74 checks.paint(
75 Rect {
76 x,
77 y,
78 width: area.right().saturating_sub(x),
79 height: 1,
80 },
81 buf,
82 theme,
83 );
84 }
85 }
86 }
87
87 lines RUST