返回 CodeWhale
settings.rs
根目录 / vendor / codewhale-ratatui / src / gallery / settings.rs
1 //! Settings facts are caller-owned; the gallery supplies deterministic examples.
2 use super::Entry;
3 use crate::{Paint, SettingDetail, SettingRow, Theme};
4 use ratatui::{buffer::Buffer, layout::Rect};
5
6 fn setting_rows(area: Rect, buf: &mut Buffer, theme: &Theme) {
7 let rows = [
8 SettingRow::new("Theme", "Shoreline")
9 .source("this project")
10 .changed(true)
11 .modified(true)
12 .selected(true),
13 SettingRow::new("Motion", "Reduced").source("your settings"),
14 SettingRow::new("Context window", "200k tokens")
15 .apply("Read only")
16 .locked("Set by your admin"),
17 ];
18 let mut y = area.y;
19 for row in rows {
20 let height = row
21 .height(area.width, theme)
22 .min(area.bottom().saturating_sub(y));
23 if height == 0 {
24 return;
25 }
26 row.paint(Rect { y, height, ..area }, buf, theme);
27 y += height;
28 }
29 }
30
31 fn setting_detail(area: Rect, buf: &mut Buffer, theme: &Theme) {
32 SettingDetail::new(
33 "Theme",
34 "Sets the colors Codewhale paints. Shoreline follows your terminal's light or dark ground.",
35 )
36 .default_value("System")
37 .source("saved to this project")
38 .modified(true)
39 .paint(area, buf, theme);
40 }
41
42 pub(crate) fn entries() -> Vec<Entry> {
43 vec![
44 Entry {
45 name: "setting-row",
46 width: 80,
47 height: 6,
48 draw: setting_rows,
49 },
50 Entry {
51 name: "setting-detail",
52 width: 80,
53 height: 7,
54 draw: setting_detail,
55 },
56 ]
57 }
58
58 lines RUST