Small cleanup

This commit is contained in:
daa 2017-03-09 23:45:45 +03:00
parent 35d2dd1868
commit b7da77ca24
3 changed files with 10 additions and 10 deletions

View File

@ -18,7 +18,7 @@ pub trait RedrawEvents {
fn on_redraw(&self); fn on_redraw(&self);
fn on_highlight_set(&mut self, attrs: &HashMap<String, Value>); fn on_highlight_set(&mut self, attrs: &HashMap<&str, &Value>);
fn on_eol_clear(&mut self); fn on_eol_clear(&mut self);
@ -150,9 +150,9 @@ fn call(ui: &mut Ui, method: &str, args: &Vec<Value>) -> result::Result<(), Stri
"resize" => ui.on_resize(try_uint!(args[0]), try_uint!(args[1])), "resize" => ui.on_resize(try_uint!(args[0]), try_uint!(args[1])),
"highlight_set" => { "highlight_set" => {
if let Value::Map(ref attrs) = args[0] { if let Value::Map(ref attrs) = args[0] {
let attrs_map: HashMap<String, Value> = attrs.iter() let attrs_map = attrs.iter()
.map(|v| match v { .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"), _ => panic!("attribute key must be string"),
}) })
.collect(); .collect();

View File

@ -451,7 +451,7 @@ impl RedrawEvents for Ui {
} }
fn on_put(&mut self, text: &str) { 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) { fn on_clear(&mut self) {
@ -478,15 +478,15 @@ impl RedrawEvents for Ui {
self.model.scroll(count); self.model.scroll(count);
} }
fn on_highlight_set(&mut self, attrs: &HashMap<String, Value>) { fn on_highlight_set(&mut self, attrs: &HashMap<&str, &Value>) {
let mut model_attrs = Attrs::new(); 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)); 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)); 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)); model_attrs.special = Some(split_color(bg));
} }
if attrs.contains_key("reverse") { if attrs.contains_key("reverse") {

View File

@ -113,10 +113,10 @@ impl UiModel {
(self.cur_row, self.cur_col) (self.cur_row, self.cur_col)
} }
pub fn put(&mut self, text: &str, attrs: &Option<Attrs>) { pub fn put(&mut self, text: &str, attrs: Option<&Attrs>) {
let mut cell = &mut self.model[self.cur_row][self.cur_col]; let mut cell = &mut self.model[self.cur_row][self.cur_col];
cell.ch = text.chars().last().unwrap(); 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; self.cur_col += 1;
} }