返回 CodeWhale
attention.rs
根目录 / vendor / codewhale-ratatui / src / gallery / attention.rs
1 //! Real attention components with illustrative, caller-owned requests.
2
3 use ratatui::{buffer::Buffer, layout::Rect};
4
5 use super::Entry;
6 use crate::{
7 AttentionItem, AttentionQueue, KeyHint, KeyHints, NeedsAttentionPill, Paint, State, Theme,
8 };
9
10 fn requests<'a>(hints: &'a KeyHints) -> Vec<AttentionItem<'a>> {
11 vec![
12 AttentionItem::new(
13 "Codewhale",
14 "Verification",
15 "Choose the validation gate for the interrupted run.",
16 State::NeedsYou,
17 )
18 .priority(100)
19 .timestamp("2m ago")
20 .action("Review run")
21 .hints(hints),
22 AttentionItem::new(
23 "Desktop",
24 "Review",
25 "Confirm which files should be included in the next change.",
26 State::NeedsYou,
27 )
28 .priority(80)
29 .timestamp("8m ago")
30 .action("Review changes")
31 .hints(hints),
32 AttentionItem::new(
33 "Documentation",
34 "Language",
35 "Choose the tone for the Chinese quickstart.",
36 State::NeedsYou,
37 )
38 .priority(30)
39 .timestamp("14m ago")
40 .action("Answer question")
41 .hints(hints),
42 ]
43 }
44
45 fn inbox(area: Rect, buf: &mut Buffer, theme: &Theme) {
46 let hints = KeyHints::new(vec![
47 KeyHint::new("Enter", "open"),
48 KeyHint::new("s", "later"),
49 ]);
50 let items = requests(&hints);
51 AttentionQueue::new(&items)
52 .selected(0)
53 .focused(true)
54 .paint(area, buf, theme);
55 }
56
57 fn focused(area: Rect, buf: &mut Buffer, theme: &Theme) {
58 let hints = KeyHints::new(vec![
59 KeyHint::new("Enter", "open"),
60 KeyHint::new("Esc", "back"),
61 ]);
62 AttentionItem::new(
63 "codewhale-ratatui",
64 "Package review",
65 "The preview catalogue is ready to inspect.\nReview the package files before publishing.",
66 State::NeedsYou,
67 )
68 .timestamp("just now")
69 .action("Review package")
70 .hints(&hints)
71 .selected(true)
72 .focused(true)
73 .paint(area, buf, theme);
74 }
75
76 fn narrow(area: Rect, buf: &mut Buffer, theme: &Theme) {
77 let hints = KeyHints::new(vec![
78 KeyHint::new("Enter", "open"),
79 KeyHint::new("s", "later"),
80 ]);
81 let items = requests(&hints);
82 AttentionQueue::new(&items)
83 .selected(1)
84 .focused(true)
85 .paint(area, buf, theme);
86 }
87
88 fn empty(area: Rect, buf: &mut Buffer, theme: &Theme) {
89 AttentionQueue::new(&[]).paint(area, buf, theme);
90 }
91
92 fn pill(area: Rect, buf: &mut Buffer, theme: &Theme) {
93 NeedsAttentionPill::new(3).paint(area, buf, theme);
94 }
95
96 pub(crate) fn entries() -> Vec<Entry> {
97 vec![
98 Entry {
99 name: "attention-queue",
100 width: 92,
101 height: 16,
102 draw: inbox,
103 },
104 Entry {
105 name: "attention-focused",
106 width: 84,
107 height: 5,
108 draw: focused,
109 },
110 Entry {
111 name: "attention-narrow",
112 width: 36,
113 height: 16,
114 draw: narrow,
115 },
116 Entry {
117 name: "attention-empty",
118 width: 64,
119 height: 10,
120 draw: empty,
121 },
122 Entry {
123 name: "attention-pill",
124 width: 32,
125 height: 1,
126 draw: pill,
127 },
128 ]
129 }
130
130 lines RUST