| 1 | //! Settings facts are caller-owned; the gallery supplies deterministic examples. |
| 2 | use super::Entry; |
| 3 | use crate::{ |
| 4 | Paint, SessionGroupHeader, SettingDetail, SettingRow, SettingsRail, SettingsSection, Theme, |
| 5 | }; |
| 6 | use ratatui::{buffer::Buffer, layout::Rect}; |
| 7 | |
| 8 | fn setting_rows(area: Rect, buf: &mut Buffer, theme: &Theme) { |
| 9 | let rows = [ |
| 10 | SettingRow::new("Theme", "Shoreline") |
| 11 | .source("this project") |
| 12 | .changed(true) |
| 13 | .modified(true) |
| 14 | .selected(true), |
| 15 | SettingRow::new("Motion", "Reduced").source("your settings"), |
| 16 | SettingRow::new("Context window", "200k tokens") |
| 17 | .apply("Read only") |
| 18 | .locked("Set by your admin"), |
| 19 | ]; |
| 20 | let mut y = area.y; |
| 21 | for row in rows { |
| 22 | let height = row |
| 23 | .height(area.width, theme) |
| 24 | .min(area.bottom().saturating_sub(y)); |
| 25 | if height == 0 { |
| 26 | return; |
| 27 | } |
| 28 | row.paint(Rect { y, height, ..area }, buf, theme); |
| 29 | y += height; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fn setting_detail(area: Rect, buf: &mut Buffer, theme: &Theme) { |
| 34 | SettingDetail::new( |
| 35 | "Theme", |
| 36 | "Sets the colors Codewhale paints. Shoreline follows your terminal's light or dark ground.", |
| 37 | ) |
| 38 | .default_value("System") |
| 39 | .source("saved to this project") |
| 40 | .modified(true) |
| 41 | .paint(area, buf, theme); |
| 42 | } |
| 43 | |
| 44 | fn setting_rail(area: Rect, buf: &mut Buffer, theme: &Theme) { |
| 45 | let sections = [ |
| 46 | SettingsSection::new("General", 4), |
| 47 | SettingsSection::new("Providers", 0), |
| 48 | SettingsSection::new("Models", 2), |
| 49 | SettingsSection::new("Appearance", 3), |
| 50 | ]; |
| 51 | SettingsRail::new(§ions, 0) |
| 52 | .searching(true) |
| 53 | .paint(area, buf, theme); |
| 54 | } |
| 55 | |
| 56 | fn session_group_headers(area: Rect, buf: &mut Buffer, theme: &Theme) { |
| 57 | let cue = if theme.ascii() { |
| 58 | "Tab - 1 needs you" |
| 59 | } else { |
| 60 | "Tab · 1 needs you" |
| 61 | }; |
| 62 | let headers = [ |
| 63 | SessionGroupHeader::in_progress(3).attention_cue(cue), |
| 64 | SessionGroupHeader::idle(5), |
| 65 | ]; |
| 66 | for (i, header) in headers.iter().enumerate() { |
| 67 | let y = area.y.saturating_add(u16::try_from(i).unwrap_or(u16::MAX)); |
| 68 | if y >= area.bottom() { |
| 69 | break; |
| 70 | } |
| 71 | header.paint( |
| 72 | Rect { |
| 73 | y, |
| 74 | height: 1, |
| 75 | ..area |
| 76 | }, |
| 77 | buf, |
| 78 | theme, |
| 79 | ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | pub(crate) fn entries() -> Vec<Entry> { |
| 84 | vec![ |
| 85 | Entry { |
| 86 | name: "setting-row", |
| 87 | width: 80, |
| 88 | height: 6, |
| 89 | draw: setting_rows, |
| 90 | }, |
| 91 | Entry { |
| 92 | name: "setting-detail", |
| 93 | width: 80, |
| 94 | height: 7, |
| 95 | draw: setting_detail, |
| 96 | }, |
| 97 | Entry { |
| 98 | name: "settings-rail", |
| 99 | width: 28, |
| 100 | height: 6, |
| 101 | draw: setting_rail, |
| 102 | }, |
| 103 | Entry { |
| 104 | name: "session-group-header", |
| 105 | width: 56, |
| 106 | height: 2, |
| 107 | draw: session_group_headers, |
| 108 | }, |
| 109 | ] |
| 110 | } |
| 111 |