Basic functions

This commit is contained in:
daa 2017-07-09 01:29:52 +03:00
parent 5a6f7d7581
commit 90dc2d4a53
2 changed files with 24 additions and 2 deletions

View File

@ -26,6 +26,13 @@ impl Mode {
self.mode == *mode
}
pub fn mode_info(&self) -> nvim::ModeInfo {
self.info
.as_ref()
.and_then(|i| i.get(self.idx).cloned())
.unwrap_or_else(nvim::ModeInfo::default)
}
pub fn update(&mut self, mode: &str, idx: usize) {
match mode {
"normal" => self.mode = NvimMode::Normal,

View File

@ -106,7 +106,7 @@ macro_rules! map_array {
);
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum CursorShape {
Block,
Horizontal,
@ -132,13 +132,20 @@ impl CursorShape {
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct ModeInfo {
cursor_shape: Option<CursorShape>,
cell_percentage: Option<u64>,
}
impl ModeInfo {
pub fn default() -> Self {
ModeInfo {
cursor_shape: Some(CursorShape::Block),
cell_percentage: None,
}
}
pub fn new(mode_info_arr: &Vec<(Value, Value)>) -> Result<Self, String> {
let mode_info_map = mode_info_arr.to_attrs_map()?;
@ -159,6 +166,14 @@ impl ModeInfo {
cell_percentage,
})
}
pub fn cursor_shape(&self) -> CursorShape {
self.cursor_shape.as_ref().cloned().unwrap_or(CursorShape::Block)
}
pub fn cell_percentage(&self) -> u64 {
self.cell_percentage.unwrap_or(100)
}
}
#[derive(Debug)]