lattice_dashboard/
mode.rs1use lattice_config::OptionOverrideSet;
13use lattice_core::BufferKind;
14use lattice_mode::{LifecycleFuture, Mode, ModeContext, ModeId, ModeKind, ModeRegistry};
15use lattice_theme::{ElementOwner, ThemeRegistryHandle};
16
17use crate::theme::register_dashboard_theme_elements;
18
19pub struct DashboardMode;
20
21impl DashboardMode {
22 pub fn mode_id() -> ModeId {
23 ModeId::new("dashboard-mode")
24 }
25}
26
27impl Mode for DashboardMode {
28 type Guard = ();
29
30 fn id(&self) -> ModeId {
31 Self::mode_id()
32 }
33
34 fn kind(&self) -> ModeKind {
35 ModeKind::Major
36 }
37
38 fn target_buffer_kind(&self) -> Option<BufferKind> {
41 Some(BufferKind::Dashboard)
42 }
43
44 fn options(&self) -> OptionOverrideSet {
49 lattice_config::overrides! {
50 lattice_config::ReadOnly = true,
51 lattice_config::Wrap = true,
52 lattice_config::NoFile = true,
53 lattice_config::Number = false,
54 lattice_config::SignColumnOption = lattice_config::SignColumn::No,
55 lattice_config::CursorLine = false,
58 }
59 }
60
61 fn on_activate(&self, ctx: ModeContext) -> LifecycleFuture<'_, ()> {
62 Box::pin(async move {
63 if let Some(theme) = ctx
68 .service::<ThemeRegistryHandle>()
69 .map(|outer| (*outer).clone())
70 {
71 let owner = ElementOwner::Mode(Self::mode_id().as_str().to_string().into());
72 let _ = register_dashboard_theme_elements(theme.as_ref(), owner);
73 }
74 Ok(())
75 })
76 }
77}
78
79pub fn register_dashboard_modes(registry: &mut ModeRegistry) {
82 registry
83 .register(DashboardMode)
84 .expect("dashboard-mode register");
85}
86
87#[cfg(test)]
88mod tests {
89 use super::*;
90
91 #[test]
92 fn id_kind_and_target() {
93 assert_eq!(DashboardMode.id(), DashboardMode::mode_id());
94 assert_eq!(DashboardMode::mode_id().as_str(), "dashboard-mode");
95 assert_eq!(DashboardMode.kind(), ModeKind::Major);
96 assert_eq!(
97 DashboardMode.target_buffer_kind(),
98 Some(BufferKind::Dashboard)
99 );
100 }
101
102 #[test]
103 fn contributes_read_only_gutterless_set() {
104 assert_eq!(DashboardMode.options().iter().count(), 6);
106 }
107}