diff --git a/src/nvim.rs b/src/nvim.rs index 99a4feb..3e4964f 100644 --- a/src/nvim.rs +++ b/src/nvim.rs @@ -18,7 +18,7 @@ pub trait RedrawEvents { fn on_redraw(&self); - fn on_highlight_set(&mut self, attrs: &HashMap); + fn on_highlight_set(&mut self, attrs: &HashMap<&str, &Value>); fn on_eol_clear(&mut self); @@ -150,9 +150,9 @@ fn call(ui: &mut Ui, method: &str, args: &Vec) -> result::Result<(), Stri "resize" => ui.on_resize(try_uint!(args[0]), try_uint!(args[1])), "highlight_set" => { if let Value::Map(ref attrs) = args[0] { - let attrs_map: HashMap = attrs.iter() + let attrs_map = attrs.iter() .map(|v| match v { - &(Value::String(ref key), ref value) => (key.clone(), value.clone()), + &(Value::String(ref key), ref value) => (key.as_str(), value), _ => panic!("attribute key must be string"), }) .collect(); diff --git a/src/ui.rs b/src/ui.rs index 8a0fb4d..aa61851 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -451,7 +451,7 @@ impl RedrawEvents for Ui { } fn on_put(&mut self, text: &str) { - self.model.put(text, &self.cur_attrs); + self.model.put(text, self.cur_attrs.as_ref()); } fn on_clear(&mut self) { @@ -478,15 +478,15 @@ impl RedrawEvents for Ui { self.model.scroll(count); } - fn on_highlight_set(&mut self, attrs: &HashMap) { + fn on_highlight_set(&mut self, attrs: &HashMap<&str, &Value>) { let mut model_attrs = Attrs::new(); - if let Some(&Value::Integer(Integer::U64(fg))) = attrs.get("foreground") { + if let Some(&&Value::Integer(Integer::U64(fg))) = attrs.get("foreground") { model_attrs.foreground = Some(split_color(fg)); } - if let Some(&Value::Integer(Integer::U64(bg))) = attrs.get("background") { + if let Some(&&Value::Integer(Integer::U64(bg))) = attrs.get("background") { model_attrs.background = Some(split_color(bg)); } - if let Some(&Value::Integer(Integer::U64(bg))) = attrs.get("special") { + if let Some(&&Value::Integer(Integer::U64(bg))) = attrs.get("special") { model_attrs.special = Some(split_color(bg)); } if attrs.contains_key("reverse") { diff --git a/src/ui_model.rs b/src/ui_model.rs index 15bbd50..e8939cb 100644 --- a/src/ui_model.rs +++ b/src/ui_model.rs @@ -113,10 +113,10 @@ impl UiModel { (self.cur_row, self.cur_col) } - pub fn put(&mut self, text: &str, attrs: &Option) { + pub fn put(&mut self, text: &str, attrs: Option<&Attrs>) { let mut cell = &mut self.model[self.cur_row][self.cur_col]; cell.ch = text.chars().last().unwrap(); - cell.attrs = attrs.as_ref().map(|o| o.clone()).unwrap_or_else(|| Attrs::new()); + cell.attrs = attrs.map(Attrs::clone).unwrap_or_else(|| Attrs::new()); self.cur_col += 1; }