返回 CodeWhale
pending_input.rs
根目录 / vendor / codewhale-ratatui / src / gallery / pending_input.rs
1 //! Pending input and attached context as fixture data. The host owns the
2 //! queue and every mutation; these entries only show what a caller reported.
3
4 use ratatui::{buffer::Buffer, layout::Rect};
5
6 use super::Entry;
7 use crate::{
8 ContextPreviewItem, ContextPreviewState, Paint, PendingCard, PendingCardContext,
9 PendingCardWords, PendingInputItem, PendingInputPreview, PendingInputStatus, Theme,
10 };
11
12 fn queued(area: Rect, buf: &mut Buffer, theme: &Theme) {
13 PendingInputPreview::new(
14 vec![
15 PendingInputItem::new(
16 "q-1",
17 "Tighten the parser tests before landing",
18 PendingInputStatus::Queued,
19 )
20 .label("tests"),
21 PendingInputItem::new(
22 "q-2",
23 "Run the release checklist after the tests pass",
24 PendingInputStatus::Queued,
25 ),
26 ],
27 Vec::new(),
28 )
29 .selected("q-1")
30 .paint(area, buf, theme);
31 }
32
33 fn steering(area: Rect, buf: &mut Buffer, theme: &Theme) {
34 PendingInputPreview::new(
35 vec![
36 PendingInputItem::new(
37 "s-1",
38 "Keep the migration reversible",
39 PendingInputStatus::Steering,
40 ),
41 PendingInputItem::new(
42 "s-2",
43 "Also check the 256-color profile",
44 PendingInputStatus::Steering,
45 )
46 .label("review"),
47 PendingInputItem::new(
48 "e-1",
49 "Rewording the second paragraph",
50 PendingInputStatus::Editing,
51 )
52 .label("draft"),
53 ],
54 Vec::new(),
55 )
56 .selected("e-1")
57 .paint(area, buf, theme);
58 }
59
60 fn paused(area: Rect, buf: &mut Buffer, theme: &Theme) {
61 PendingInputPreview::new(
62 vec![
63 PendingInputItem::new(
64 "p-1",
65 "Restart the shell after the upgrade",
66 PendingInputStatus::Paused,
67 ),
68 PendingInputItem::new(
69 "f-1",
70 "Comparing the two snapshots",
71 PendingInputStatus::InFlight,
72 ),
73 ],
74 Vec::new(),
75 )
76 .selected("p-1")
77 .paint(area, buf, theme);
78 }
79
80 fn attached_context(area: Rect, buf: &mut Buffer, theme: &Theme) {
81 PendingInputPreview::new(
82 vec![PendingInputItem::new(
83 "q-1",
84 "Continue from these notes",
85 PendingInputStatus::Queued,
86 )],
87 vec![
88 ContextPreviewItem::new("c-1", "notes.md", ContextPreviewState::Included)
89 .detail("4.2 kB"),
90 ContextPreviewItem::new("c-2", "draft.md", ContextPreviewState::Unconfirmed),
91 ContextPreviewItem::new("c-3", "old.log", ContextPreviewState::Removable)
92 .detail("stale"),
93 ],
94 )
95 .paint(area, buf, theme);
96 }
97
98 fn native_mixed(area: Rect, buf: &mut Buffer, theme: &Theme) {
99 let mut card = PendingCard::new(PendingCardWords::default());
100 card.priority_rows
101 .push("1 child request needs attention".into());
102 card.context = vec![
103 PendingCardContext {
104 kind: "file".into(),
105 label: "notes.md".into(),
106 detail: Some("4.2 kB".into()),
107 included: true,
108 removable: true,
109 selected: false,
110 },
111 PendingCardContext {
112 kind: "file".into(),
113 label: "draft.md".into(),
114 detail: None,
115 included: false,
116 removable: true,
117 selected: true,
118 },
119 ];
120 card.sending.push("Check the parser boundary".into());
121 card.editing = Some("Keep the migration reversible".into());
122 card.queued.push("Compare the two snapshots".into());
123 card.paint(area, buf, theme);
124 }
125
126 fn native_queued(area: Rect, buf: &mut Buffer, theme: &Theme) {
127 let mut card = PendingCard::new(PendingCardWords::default());
128 card.queued = vec!["Check the narrow layout".into(), "Read the receipt".into()];
129 card.paint(area, buf, theme);
130 }
131
132 pub(crate) fn entries() -> Vec<Entry> {
133 vec![
134 Entry {
135 name: "pending-queued",
136 width: 40,
137 height: 4,
138 draw: queued,
139 },
140 Entry {
141 name: "pending-steering",
142 width: 40,
143 height: 5,
144 draw: steering,
145 },
146 Entry {
147 name: "pending-paused",
148 width: 40,
149 height: 4,
150 draw: paused,
151 },
152 Entry {
153 name: "pending-context",
154 width: 40,
155 height: 4,
156 draw: attached_context,
157 },
158 Entry {
159 name: "pending-native-mixed",
160 width: 40,
161 height: 15,
162 draw: native_mixed,
163 },
164 Entry {
165 name: "pending-native-queued",
166 width: 40,
167 height: 2,
168 draw: native_queued,
169 },
170 ]
171 }
172
172 lines RUST