mode_indicator.rs

 1use gpui::{elements::Label, AnyElement, Element, Entity, View, ViewContext};
 2use workspace::{item::ItemHandle, StatusItemView};
 3
 4use crate::state::Mode;
 5
 6pub struct ModeIndicator {
 7    pub mode: Mode,
 8}
 9
10impl ModeIndicator {
11    pub fn new(mode: Mode) -> Self {
12        Self { mode }
13    }
14
15    pub fn set_mode(&mut self, mode: Mode, cx: &mut ViewContext<Self>) {
16        if mode != self.mode {
17            self.mode = mode;
18            cx.notify();
19        }
20    }
21}
22
23impl Entity for ModeIndicator {
24    type Event = ();
25}
26
27impl View for ModeIndicator {
28    fn ui_name() -> &'static str {
29        "ModeIndicatorView"
30    }
31
32    fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
33        let theme = &theme::current(cx).workspace.status_bar;
34        // we always choose text to be 12 monospace characters
35        // so that as the mode indicator changes, the rest of the
36        // UI stays still.
37        let text = match self.mode {
38            Mode::Normal => "-- NORMAL --",
39            Mode::Insert => "-- INSERT --",
40            Mode::Visual { line: false } => "-- VISUAL --",
41            Mode::Visual { line: true } => "VISUAL LINE ",
42        };
43        Label::new(text, theme.vim_mode_indicator.clone()).into_any()
44    }
45}
46
47impl StatusItemView for ModeIndicator {
48    fn set_active_pane_item(
49        &mut self,
50        _active_pane_item: Option<&dyn ItemHandle>,
51        _cx: &mut ViewContext<Self>,
52    ) {
53        // nothing to do.
54    }
55}