diff --git a/src/buffer.rs b/src/buffer.rs index f4d9ef9..70763df 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -161,8 +161,7 @@ impl Buffer { x, y, self.area); - let index = ((y - self.area.y) * self.area.width + (x - self.area.x)) as usize; - index + ((y - self.area.y) * self.area.width + (x - self.area.x)) as usize } /// Returns the coordinates of a cell given its index @@ -188,7 +187,7 @@ impl Buffer { for s in graphemes.into_iter().take(max_index) { self.content[index].symbol.clear(); self.content[index].symbol.push_str(s); - self.content[index].style = style.clone(); + self.content[index].style = *style; index += 1; } } diff --git a/src/style.rs b/src/style.rs index 54ee4e9..8f3dd8e 100644 --- a/src/style.rs +++ b/src/style.rs @@ -143,26 +143,19 @@ impl Color { } fn rgb_to_byte(r: u8, g: u8, b: u8) -> u16 { - (((r & 255 & 0xC0) + (g & 255 & 0xE0) >> 2 + (b & 0xE0) >> 5) & 0xFF) as u16 + ((((r & 255 & 0xC0) + ((g & 255 & 0xE0) >> 2) + ((b & 0xE0) >> 5))) & 0xFF) as u16 } impl Into for Color { fn into(self) -> rustbox::Color { match self { Color::Reset => rustbox::Color::Default, - Color::Black => rustbox::Color::Black, - Color::Red => rustbox::Color::Red, - Color::Green => rustbox::Color::Green, - Color::Yellow => rustbox::Color::Yellow, - Color::Magenta => rustbox::Color::Magenta, - Color::Cyan => rustbox::Color::Cyan, - Color::Gray => rustbox::Color::Black, - Color::DarkGray => rustbox::Color::Black, - Color::LightRed => rustbox::Color::Red, - Color::LightGreen => rustbox::Color::Green, - Color::LightYellow => rustbox::Color::Yellow, - Color::LightMagenta => rustbox::Color::Magenta, - Color::LightCyan => rustbox::Color::Cyan, + Color::Black | Color::Gray | Color::DarkGray => rustbox::Color::Black, + Color::Red | Color::LightRed => rustbox::Color::Red, + Color::Green | Color::LightGreen => rustbox::Color::Green, + Color::Yellow | Color::LightYellow => rustbox::Color::Yellow, + Color::Magenta | Color::LightMagenta => rustbox::Color::Magenta, + Color::Cyan | Color::LightCyan => rustbox::Color::Cyan, Color::White => rustbox::Color::White, Color::Rgb(r, g, b) => rustbox::Color::Byte(rgb_to_byte(r, g, b)), } @@ -195,7 +188,6 @@ impl Modifier { impl Into for Modifier { fn into(self) -> rustbox::Style { match self { - Modifier::Reset => rustbox::RB_NORMAL, Modifier::Bold => rustbox::RB_BOLD, Modifier::Underline => rustbox::RB_UNDERLINE, Modifier::Invert => rustbox::RB_REVERSE, diff --git a/src/terminal.rs b/src/terminal.rs index c259a4d..cbcbda8 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -229,7 +229,7 @@ impl Terminal /// clean outdated ones at the end of the draw call. pub fn compute_layout(&mut self, group: &Group, area: &Rect) -> Vec { let entry = self.layout_cache - .entry((group.clone(), area.clone())) + .entry((group.clone(), *area)) .or_insert_with(|| { let chunks = split(area, &group.direction, group.margin, &group.sizes); debug!("New layout computed:\n* Group = {:?}\n* Chunks = {:?}", @@ -291,7 +291,7 @@ impl Terminal // Clean layout cache let hot = self.layout_cache .drain() - .filter(|&(_, ref v)| v.hot == true) + .filter(|&(_, ref v)| v.hot) .collect::>(); for (key, value) in hot { diff --git a/src/widgets/gauge.rs b/src/widgets/gauge.rs index a9e1775..0f7daf5 100644 --- a/src/widgets/gauge.rs +++ b/src/widgets/gauge.rs @@ -93,7 +93,7 @@ impl<'a> Widget for Gauge<'a> { let label = self.label.unwrap_or(&precent_label); let label_width = label.width() as u16; let middle = (gauge_area.width - label_width) / 2 + gauge_area.left(); - buf.set_string(middle, y, &label, &self.style); + buf.set_string(middle, y, label, &self.style); } // Fix colors diff --git a/src/widgets/list.rs b/src/widgets/list.rs index e563235..e6b1d64 100644 --- a/src/widgets/list.rs +++ b/src/widgets/list.rs @@ -72,7 +72,7 @@ impl<'a, T> Widget for List<'a, T> list_area.top() + i as u16, item.as_ref(), list_area.width as usize, - &style); + style); } } } @@ -193,7 +193,7 @@ impl<'a> Widget for SelectableList<'a> { // Render items List::default() - .block(self.block.unwrap_or(Default::default())) + .block(self.block.unwrap_or_default()) .items(&items) .draw(area, buf); }