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