diff --git a/examples/colors_rgb.rs b/examples/colors_rgb.rs index d7b5ab68..20e9285d 100644 --- a/examples/colors_rgb.rs +++ b/examples/colors_rgb.rs @@ -39,7 +39,7 @@ use crossterm::{ ExecutableCommand, }; use palette::{convert::FromColorUnclamped, Okhsv, Srgb}; -use ratatui::prelude::*; +use ratatui::{layout::Position, prelude::*}; #[derive(Debug, Default)] struct App { @@ -217,7 +217,7 @@ impl Widget for &mut ColorsWidget { // pixel below it let fg = colors[yi * 2][xi]; let bg = colors[yi * 2 + 1][xi]; - buf.get_mut(x, y).set_char('▀').set_fg(fg).set_bg(bg); + buf[Position::new(x, y)].set_char('▀').set_fg(fg).set_bg(bg); } } self.frame_count += 1; diff --git a/examples/constraints.rs b/examples/constraints.rs index 72601a4b..585eae6b 100644 --- a/examples/constraints.rs +++ b/examples/constraints.rs @@ -238,7 +238,7 @@ impl App { for (i, cell) in visible_content.enumerate() { let x = i as u16 % area.width; let y = i as u16 / area.width; - *buf.get_mut(area.x + x, area.y + y) = cell; + buf[(area.x + x, area.y + y)] = cell; } if scrollbar_needed { diff --git a/examples/demo2/big_text.rs b/examples/demo2/big_text.rs index 05d3667e..6c75d048 100644 --- a/examples/demo2/big_text.rs +++ b/examples/demo2/big_text.rs @@ -245,7 +245,7 @@ fn render_glyph(glyph: [u8; 8], area: Rect, buf: &mut Buffer, pixel_size: PixelS .clone() .zip(area.left()..area.right()) { - let cell = buf.get_mut(x, y); + let cell = &mut buf[(x, y)]; let symbol_character = match pixel_size { PixelSize::Full => match glyph[row] & (1 << col) { 0 => ' ', diff --git a/examples/demo2/colors.rs b/examples/demo2/colors.rs index ec882567..c60a35cf 100644 --- a/examples/demo2/colors.rs +++ b/examples/demo2/colors.rs @@ -19,7 +19,7 @@ impl Widget for RgbSwatch { let hue = xi as f32 * 360.0 / f32::from(area.width); let fg = color_from_oklab(hue, Okhsv::max_saturation(), value_fg); let bg = color_from_oklab(hue, Okhsv::max_saturation(), value_bg); - buf.get_mut(x, y).set_char('▀').set_fg(fg).set_bg(bg); + buf[(x, y)].set_char('▀').set_fg(fg).set_bg(bg); } } } diff --git a/examples/demo2/destroy.rs b/examples/demo2/destroy.rs index 46c386fa..49a3d531 100644 --- a/examples/demo2/destroy.rs +++ b/examples/demo2/destroy.rs @@ -45,7 +45,7 @@ fn drip(frame_count: usize, area: Rect, buf: &mut Buffer) { for _ in 0..pixel_count { let src_x = rng.gen_range(0..area.width); let src_y = rng.gen_range(1..area.height - 2); - let src = buf.get_mut(src_x, src_y).clone(); + let src = buf[(src_x, src_y)].clone(); // 1% of the time, move a blank or pixel (10:1) to the top line of the screen if rng.gen_ratio(1, 100) { let dest_x = rng @@ -53,7 +53,7 @@ fn drip(frame_count: usize, area: Rect, buf: &mut Buffer) { .clamp(area.left(), area.right() - 1); let dest_y = area.top() + 1; - let dest = buf.get_mut(dest_x, dest_y); + let dest = &mut buf[(dest_x, dest_y)]; // copy the cell to the new location about 1/10 of the time blank out the cell the rest // of the time. This has the effect of gradually removing the pixels from the screen. if rng.gen_ratio(1, 10) { @@ -66,8 +66,7 @@ fn drip(frame_count: usize, area: Rect, buf: &mut Buffer) { let dest_x = src_x; let dest_y = src_y.saturating_add(1).min(area.bottom() - 2); // copy the cell to the new location - let dest = buf.get_mut(dest_x, dest_y); - *dest = src; + buf[(dest_x, dest_y)] = src; } } } @@ -98,8 +97,8 @@ fn text(frame_count: usize, area: Rect, buf: &mut Buffer) { for row in area.rows() { for col in row.columns() { - let cell = buf.get_mut(col.x, col.y); - let mask_cell = mask_buf.get(col.x, col.y); + let cell = &mut buf[(col.x, col.y)]; + let mask_cell = &mut mask_buf[(col.x, col.y)]; cell.set_symbol(mask_cell.symbol()); // blend the mask cell color with the cell color diff --git a/examples/demo2/tabs/about.rs b/examples/demo2/tabs/about.rs index cf669bf6..c8dcbfe3 100644 --- a/examples/demo2/tabs/about.rs +++ b/examples/demo2/tabs/about.rs @@ -116,7 +116,7 @@ pub fn render_logo(selected_row: usize, area: Rect, buf: &mut Buffer) { for (x, (ch1, ch2)) in line1.chars().zip(line2.chars()).enumerate() { let x = area.left() + x as u16; let y = area.top() + y as u16; - let cell = buf.get_mut(x, y); + let cell = &mut buf[(x, y)]; let rat_color = THEME.logo.rat; let term_color = THEME.logo.term; match (ch1, ch2) { diff --git a/examples/flex.rs b/examples/flex.rs index 6ba4938e..fb17086b 100644 --- a/examples/flex.rs +++ b/examples/flex.rs @@ -334,7 +334,7 @@ impl App { for (i, cell) in visible_content.enumerate() { let x = i as u16 % area.width; let y = i as u16 / area.width; - *buf.get_mut(area.x + x, area.y + y) = cell; + buf[(area.x + x, area.y + y)] = cell; } if scrollbar_needed { diff --git a/src/backend/test.rs b/src/backend/test.rs index 37cfb8b4..306dbd0d 100644 --- a/src/backend/test.rs +++ b/src/backend/test.rs @@ -139,8 +139,7 @@ impl Backend for TestBackend { I: Iterator, { for (x, y, c) in content { - let cell = self.buffer.get_mut(x, y); - *cell = c.clone(); + self.buffer[(x, y)] = c.clone(); } Ok(()) } diff --git a/src/buffer/assert.rs b/src/buffer/assert.rs index 9504c5f1..3d761fa6 100644 --- a/src/buffer/assert.rs +++ b/src/buffer/assert.rs @@ -18,7 +18,7 @@ macro_rules! assert_buffer_eq { .into_iter() .enumerate() .map(|(i, (x, y, cell))| { - let expected_cell = expected.get(x, y); + let expected_cell = &expected[(x, y)]; format!("{i}: at ({x}, {y})\n expected: {expected_cell:?}\n actual: {cell:?}") }) .collect::>() diff --git a/src/buffer/buffer.rs b/src/buffer/buffer.rs index 7b2bd83c..76e0c629 100644 --- a/src/buffer/buffer.rs +++ b/src/buffer/buffer.rs @@ -23,8 +23,8 @@ use crate::{buffer::Cell, layout::Position, prelude::*}; /// width: 10, /// height: 5, /// }); -/// buf.get_mut(0, 2).set_symbol("x"); -/// assert_eq!(buf.get(0, 2).symbol(), "x"); +/// buf[(0, 2)].set_symbol("x"); +/// assert_eq!(buf[(0, 2)].symbol(), "x"); /// /// buf.set_string( /// 3, @@ -32,13 +32,13 @@ use crate::{buffer::Cell, layout::Position, prelude::*}; /// "string", /// Style::default().fg(Color::Red).bg(Color::White), /// ); -/// let cell = buf.get(5, 0); +/// let cell = &buf[(5, 0)]; /// assert_eq!(cell.symbol(), "r"); /// assert_eq!(cell.fg, Color::Red); /// assert_eq!(cell.bg, Color::White); /// -/// buf.get_mut(5, 0).set_char('x'); -/// assert_eq!(buf.get(5, 0).symbol(), "x"); +/// buf[(5, 0)].set_char('x'); +/// assert_eq!(buf[(5, 0)].symbol(), "x"); /// ``` #[derive(Default, Clone, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -94,8 +94,8 @@ impl Buffer { /// Returns a reference to Cell at the given coordinates /// - /// Callers should generally use the Index trait (`buf[(x, y)]`) or the [`Buffer::cell`] method - /// instead of this method. + /// Callers should generally use the [`ops::Index`] trait ([`Buffer[Position]`]) or the + /// [`Buffer::cell`] method instead of this method. /// /// Note that conventionally methods named `get` usually return `Option<&T>`, but this method /// panics instead. This is kept for backwards compatibility. See `get_opt` for a safe @@ -105,6 +105,7 @@ impl Buffer { /// /// Panics if the index is out of bounds. #[track_caller] + #[deprecated(note = "Use Buffer[] or Buffer::cell instead")] pub fn get(&self, x: u16, y: u16) -> &Cell { let i = self.index_of(x, y); &self.content[i] @@ -112,7 +113,7 @@ impl Buffer { /// Returns a mutable reference to Cell at the given coordinates /// - /// Callers should generally use the `IndexMut` trait (`&mut buf[(x, y)]`) or the + /// Callers should generally use the [`ops::IndexMut`] trait (`&mut Buffer[Position]`) or the /// [`Buffer::cell_mut`] method instead of this method. /// /// Note that conventionally methods named `get_mut` usually return `Option<&mut T>`, but this @@ -123,6 +124,7 @@ impl Buffer { /// /// Panics if the index is out of bounds. #[track_caller] + #[deprecated(note = "Use Buffer[] or Buffer::cell_mut instead")] pub fn get_mut(&mut self, x: u16, y: u16) -> &mut Cell { let i = self.index_of(x, y); &mut self.content[i] @@ -162,11 +164,12 @@ impl Buffer { /// ```rust /// # use ratatui::{prelude::*, buffer::Cell, layout::Position}; /// let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10)); - /// - /// assert_eq!(buffer.cell(Position::new(0, 0)), Some(&mut Cell::default())); - /// assert_eq!(buffer.cell(Position::new(10, 10)), None); - /// assert_eq!(buffer.cell((0, 0)), Some(&mut Cell::default())); - /// assert_eq!(buffer.cell((10, 10)), None); + /// if let Some(cell) = buffer.cell_mut(Position::new(0, 0)) { + /// *cell = Cell::default(); + /// } + /// if let Some(cell) = buffer.cell_mut((0, 0)) { + /// *cell = Cell::default(); + /// } /// ``` pub fn cell_mut>(&mut self, pos: P) -> Option<&mut Cell> { let pos = pos.into(); @@ -297,12 +300,12 @@ impl Buffer { }); let style = style.into(); for (symbol, width) in graphemes { - self.get_mut(x, y).set_symbol(symbol).set_style(style); + self[(x, y)].set_symbol(symbol).set_style(style); let next_symbol = x + width; x += 1; // Reset following cells if multi-width (they would be hidden by the grapheme), while x < next_symbol { - self.get_mut(x, y).reset(); + self[(x, y)].reset(); x += 1; } } @@ -345,7 +348,7 @@ impl Buffer { let area = self.area.intersection(area); for y in area.top()..area.bottom() { for x in area.left()..area.right() { - self.get_mut(x, y).set_style(style); + self[(x, y)].set_style(style); } } } @@ -465,8 +468,8 @@ impl> ops::Index

for Buffer { /// ``` /// # use ratatui::{prelude::*, buffer::Cell, layout::Position}; /// let buf = Buffer::empty(Rect::new(0, 0, 10, 10)); - /// let cell = buf[(0, 0)]; - /// let cell = buf[Position::new(0, 0)]; + /// let cell = &buf[(0, 0)]; + /// let cell = &buf[Position::new(0, 0)]; /// ``` fn index(&self, pos: P) -> &Self::Output { let pos = pos.into(); diff --git a/src/layout/rect.rs b/src/layout/rect.rs index 3e4a3e94..48de49d8 100644 --- a/src/layout/rect.rs +++ b/src/layout/rect.rs @@ -291,7 +291,7 @@ impl Rect { /// # use ratatui::prelude::*; /// fn render(area: Rect, buf: &mut Buffer) { /// for position in area.positions() { - /// buf.get_mut(position.x, position.y).set_symbol("x"); + /// buf[(position.x, position.y)].set_symbol("x"); /// } /// } /// ``` diff --git a/src/style.rs b/src/style.rs index 4c7da969..38e11e8e 100644 --- a/src/style.rs +++ b/src/style.rs @@ -179,7 +179,7 @@ impl fmt::Debug for Modifier { /// ]; /// let mut buffer = Buffer::empty(Rect::new(0, 0, 1, 1)); /// for style in &styles { -/// buffer.get_mut(0, 0).set_style(*style); +/// buffer[(0, 0)].set_style(*style); /// } /// assert_eq!( /// Style { @@ -190,7 +190,7 @@ impl fmt::Debug for Modifier { /// add_modifier: Modifier::BOLD | Modifier::UNDERLINED, /// sub_modifier: Modifier::empty(), /// }, -/// buffer.get(0, 0).style(), +/// buffer[(0, 0)].style(), /// ); /// ``` /// @@ -208,7 +208,7 @@ impl fmt::Debug for Modifier { /// ]; /// let mut buffer = Buffer::empty(Rect::new(0, 0, 1, 1)); /// for style in &styles { -/// buffer.get_mut(0, 0).set_style(*style); +/// buffer[(0, 0)].set_style(*style); /// } /// assert_eq!( /// Style { @@ -219,7 +219,7 @@ impl fmt::Debug for Modifier { /// add_modifier: Modifier::empty(), /// sub_modifier: Modifier::empty(), /// }, -/// buffer.get(0, 0).style(), +/// buffer[(0, 0)].style(), /// ); /// ``` #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] @@ -600,9 +600,9 @@ mod tests { let mut buffer = Buffer::empty(Rect::new(0, 0, 1, 1)); for m in mods { - buffer.get_mut(0, 0).set_style(Style::reset()); - buffer.get_mut(0, 0).set_style(Style::new().add_modifier(m)); - let style = buffer.get(0, 0).style(); + buffer[(0, 0)].set_style(Style::reset()); + buffer[(0, 0)].set_style(Style::new().add_modifier(m)); + let style = buffer[(0, 0)].style(); assert!(style.add_modifier.contains(m)); assert!(!style.sub_modifier.contains(m)); } diff --git a/src/text/span.rs b/src/text/span.rs index cbd5d51a..83060934 100644 --- a/src/text/span.rs +++ b/src/text/span.rs @@ -377,18 +377,16 @@ impl WidgetRef for Span<'_> { if next_x > max_x { break; } - buf.get_mut(current_x, y) - .set_symbol(g.symbol) - .set_style(g.style); + buf[(current_x, y)].set_symbol(g.symbol).set_style(g.style); // multi-width graphemes must clear the cells of characters that are hidden by the // grapheme, otherwise the hidden characters will be re-rendered if the grapheme is // overwritten. for i in (current_x + 1)..next_x { - buf.get_mut(i, y).reset(); + buf[(i, y)].reset(); // it may seem odd that the style of the hidden cells are not set to the style of // the grapheme, but this is how the existing buffer.set_span() method works. - // buf.get_mut(i, y).set_style(g.style); + // buf[(i, y)].set_style(g.style); } current_x = next_x; } diff --git a/src/widgets/barchart.rs b/src/widgets/barchart.rs index 48104743..49c442cc 100644 --- a/src/widgets/barchart.rs +++ b/src/widgets/barchart.rs @@ -431,7 +431,7 @@ impl BarChart<'_> { } else { self.bar_set.empty }; - buf.get_mut(bars_area.left() + x, bar_y) + buf[(bars_area.left() + x, bar_y)] .set_symbol(symbol) .set_style(bar_style); } @@ -507,7 +507,7 @@ impl BarChart<'_> { let bar_style = self.bar_style.patch(bar.style); for x in 0..self.bar_width { - buf.get_mut(bar_x + x, area.top() + j) + buf[(bar_x + x, area.top() + j)] .set_symbol(symbol) .set_style(bar_style); } @@ -698,7 +698,7 @@ mod tests { "f b ", ]); for (x, y) in iproduct!([0, 2], [0, 1]) { - expected.get_mut(x, y).set_fg(Color::Red); + expected[(x, y)].set_fg(Color::Red); } assert_eq!(buffer, expected); } @@ -790,8 +790,8 @@ mod tests { "█1█ █2█ ", "foo bar ", ]); - expected.get_mut(1, 1).set_fg(Color::Red); - expected.get_mut(5, 1).set_fg(Color::Red); + expected[(1, 1)].set_fg(Color::Red); + expected[(5, 1)].set_fg(Color::Red); assert_eq!(buffer, expected); } @@ -808,8 +808,8 @@ mod tests { "1 2 ", "f b ", ]); - expected.get_mut(0, 2).set_fg(Color::Red); - expected.get_mut(2, 2).set_fg(Color::Red); + expected[(0, 2)].set_fg(Color::Red); + expected[(2, 2)].set_fg(Color::Red); assert_eq!(buffer, expected); } @@ -827,7 +827,7 @@ mod tests { "f b ", ]); for (x, y) in iproduct!(0..10, 0..3) { - expected.get_mut(x, y).set_fg(Color::Red); + expected[(x, y)].set_fg(Color::Red); } assert_eq!(buffer, expected); } @@ -958,9 +958,9 @@ mod tests { let mut expected = Buffer::with_lines(["label", "5████"]); // first line has a yellow foreground. first cell contains italic "5" - expected.get_mut(0, 1).modifier.insert(Modifier::ITALIC); + expected[(0, 1)].modifier.insert(Modifier::ITALIC); for x in 0..5 { - expected.get_mut(x, 1).set_fg(Color::Yellow); + expected[(x, 1)].set_fg(Color::Yellow); } let expected_color = if let Some(color) = bar_color { @@ -972,13 +972,13 @@ mod tests { // second line contains the word "label". Since the bar value is 2, // then the first 2 characters of "label" are italic red. // the rest is white (using the Bar's style). - let cell = expected.get_mut(0, 0).set_fg(Color::Red); + let cell = expected[(0, 0)].set_fg(Color::Red); cell.modifier.insert(Modifier::ITALIC); - let cell = expected.get_mut(1, 0).set_fg(Color::Red); + let cell = expected[(1, 0)].set_fg(Color::Red); cell.modifier.insert(Modifier::ITALIC); - expected.get_mut(2, 0).set_fg(expected_color); - expected.get_mut(3, 0).set_fg(expected_color); - expected.get_mut(4, 0).set_fg(expected_color); + expected[(2, 0)].set_fg(expected_color); + expected[(3, 0)].set_fg(expected_color); + expected[(4, 0)].set_fg(expected_color); assert_eq!(buffer, expected); } @@ -1031,9 +1031,9 @@ mod tests { // bold: because of BarChart::label_style // red: is included with the label itself let mut expected = Buffer::with_lines(["2████", "G1 "]); - let cell = expected.get_mut(0, 1).set_fg(Color::Red); + let cell = expected[(0, 1)].set_fg(Color::Red); cell.modifier.insert(Modifier::BOLD); - let cell = expected.get_mut(1, 1).set_fg(Color::Red); + let cell = expected[(1, 1)].set_fg(Color::Red); cell.modifier.insert(Modifier::BOLD); assert_eq!(buffer, expected); diff --git a/src/widgets/block.rs b/src/widgets/block.rs index ef12c8a8..924f5688 100644 --- a/src/widgets/block.rs +++ b/src/widgets/block.rs @@ -628,7 +628,7 @@ impl Block<'_> { fn render_left_side(&self, area: Rect, buf: &mut Buffer) { if self.borders.contains(Borders::LEFT) { for y in area.top()..area.bottom() { - buf.get_mut(area.left(), y) + buf[(area.left(), y)] .set_symbol(self.border_set.vertical_left) .set_style(self.border_style); } @@ -638,7 +638,7 @@ impl Block<'_> { fn render_top_side(&self, area: Rect, buf: &mut Buffer) { if self.borders.contains(Borders::TOP) { for x in area.left()..area.right() { - buf.get_mut(x, area.top()) + buf[(x, area.top())] .set_symbol(self.border_set.horizontal_top) .set_style(self.border_style); } @@ -649,7 +649,7 @@ impl Block<'_> { if self.borders.contains(Borders::RIGHT) { let x = area.right() - 1; for y in area.top()..area.bottom() { - buf.get_mut(x, y) + buf[(x, y)] .set_symbol(self.border_set.vertical_right) .set_style(self.border_style); } @@ -660,7 +660,7 @@ impl Block<'_> { if self.borders.contains(Borders::BOTTOM) { let y = area.bottom() - 1; for x in area.left()..area.right() { - buf.get_mut(x, y) + buf[(x, y)] .set_symbol(self.border_set.horizontal_bottom) .set_style(self.border_style); } @@ -669,7 +669,7 @@ impl Block<'_> { fn render_bottom_right_corner(&self, buf: &mut Buffer, area: Rect) { if self.borders.contains(Borders::RIGHT | Borders::BOTTOM) { - buf.get_mut(area.right() - 1, area.bottom() - 1) + buf[(area.right() - 1, area.bottom() - 1)] .set_symbol(self.border_set.bottom_right) .set_style(self.border_style); } @@ -677,7 +677,7 @@ impl Block<'_> { fn render_top_right_corner(&self, buf: &mut Buffer, area: Rect) { if self.borders.contains(Borders::RIGHT | Borders::TOP) { - buf.get_mut(area.right() - 1, area.top()) + buf[(area.right() - 1, area.top())] .set_symbol(self.border_set.top_right) .set_style(self.border_style); } @@ -685,7 +685,7 @@ impl Block<'_> { fn render_bottom_left_corner(&self, buf: &mut Buffer, area: Rect) { if self.borders.contains(Borders::LEFT | Borders::BOTTOM) { - buf.get_mut(area.left(), area.bottom() - 1) + buf[(area.left(), area.bottom() - 1)] .set_symbol(self.border_set.bottom_left) .set_style(self.border_style); } @@ -693,7 +693,7 @@ impl Block<'_> { fn render_top_left_corner(&self, buf: &mut Buffer, area: Rect) { if self.borders.contains(Borders::LEFT | Borders::TOP) { - buf.get_mut(area.left(), area.top()) + buf[(area.left(), area.top())] .set_symbol(self.border_set.top_left) .set_style(self.border_style); } diff --git a/src/widgets/canvas.rs b/src/widgets/canvas.rs index 66312436..1e357427 100644 --- a/src/widgets/canvas.rs +++ b/src/widgets/canvas.rs @@ -771,7 +771,7 @@ where (index % width) as u16 + canvas_area.left(), (index / width) as u16 + canvas_area.top(), ); - let cell = buf.get_mut(x, y).set_char(ch); + let cell = buf[(x, y)].set_char(ch); if colors.0 != Color::Reset { cell.set_fg(colors.0); } diff --git a/src/widgets/chart.rs b/src/widgets/chart.rs index d4a56b6a..bd1f45cd 100644 --- a/src/widgets/chart.rs +++ b/src/widgets/chart.rs @@ -957,14 +957,14 @@ impl WidgetRef for Chart<'_> { // Sample the style of the entire widget. This sample will be used to reset the style of // the cells that are part of the components put on top of the grah area (i.e legend and // axis names). - let original_style = buf.get(area.left(), area.top()).style(); + let original_style = buf[(area.left(), area.top())].style(); self.render_x_labels(buf, &layout, chart_area, graph_area); self.render_y_labels(buf, &layout, chart_area, graph_area); if let Some(y) = layout.axis_x { for x in graph_area.left()..graph_area.right() { - buf.get_mut(x, y) + buf[(x, y)] .set_symbol(symbols::line::HORIZONTAL) .set_style(self.x_axis.style); } @@ -972,7 +972,7 @@ impl WidgetRef for Chart<'_> { if let Some(x) = layout.axis_y { for y in graph_area.top()..graph_area.bottom() { - buf.get_mut(x, y) + buf[(x, y)] .set_symbol(symbols::line::VERTICAL) .set_style(self.y_axis.style); } @@ -980,7 +980,7 @@ impl WidgetRef for Chart<'_> { if let Some(y) = layout.axis_x { if let Some(x) = layout.axis_y { - buf.get_mut(x, y) + buf[(x, y)] .set_symbol(symbols::line::BOTTOM_LEFT) .set_style(self.x_axis.style); } diff --git a/src/widgets/clear.rs b/src/widgets/clear.rs index c4e47a31..dd544816 100644 --- a/src/widgets/clear.rs +++ b/src/widgets/clear.rs @@ -34,7 +34,7 @@ impl WidgetRef for Clear { fn render_ref(&self, area: Rect, buf: &mut Buffer) { for x in area.left()..area.right() { for y in area.top()..area.bottom() { - buf.get_mut(x, y).reset(); + buf[(x, y)].reset(); } } } diff --git a/src/widgets/gauge.rs b/src/widgets/gauge.rs index ccab0815..0d5cc1bf 100644 --- a/src/widgets/gauge.rs +++ b/src/widgets/gauge.rs @@ -195,23 +195,23 @@ impl Gauge<'_> { for y in gauge_area.top()..gauge_area.bottom() { // render the filled area (left to end) for x in gauge_area.left()..end { - let cell = buf.get_mut(x, y); // Use full block for the filled part of the gauge and spaces for the part that is // covered by the label. Note that the background and foreground colors are swapped // for the label part, otherwise the gauge will be inverted if x < label_col || x > label_col + clamped_label_width || y != label_row { - cell.set_symbol(symbols::block::FULL) + buf[(x, y)] + .set_symbol(symbols::block::FULL) .set_fg(self.gauge_style.fg.unwrap_or(Color::Reset)) .set_bg(self.gauge_style.bg.unwrap_or(Color::Reset)); } else { - cell.set_symbol(" ") + buf[(x, y)] + .set_symbol(" ") .set_fg(self.gauge_style.bg.unwrap_or(Color::Reset)) .set_bg(self.gauge_style.fg.unwrap_or(Color::Reset)); } } if self.use_unicode && self.ratio < 1.0 { - buf.get_mut(end, y) - .set_symbol(get_unicode_block(filled_width % 1.0)); + buf[(end, y)].set_symbol(get_unicode_block(filled_width % 1.0)); } } // render the label @@ -377,7 +377,7 @@ impl WidgetRef for LineGauge<'_> { let end = start + (f64::from(gauge_area.right().saturating_sub(start)) * self.ratio).floor() as u16; for col in start..end { - buf.get_mut(col, row) + buf[(col, row)] .set_symbol(self.line_set.horizontal) .set_style(Style { fg: self.gauge_style.fg, @@ -389,7 +389,7 @@ impl WidgetRef for LineGauge<'_> { }); } for col in end..gauge_area.right() { - buf.get_mut(col, row) + buf[(col, row)] .set_symbol(self.line_set.horizontal) .set_style(Style { fg: self.gauge_style.bg, diff --git a/src/widgets/paragraph.rs b/src/widgets/paragraph.rs index 12544bfc..ee9a2022 100644 --- a/src/widgets/paragraph.rs +++ b/src/widgets/paragraph.rs @@ -376,7 +376,7 @@ impl<'a> Paragraph<'a> { // If the symbol is empty, the last char which rendered last time will // leave on the line. It's a quick fix. let symbol = if symbol.is_empty() { " " } else { symbol }; - buf.get_mut(area.left() + x, area.top() + y - self.scroll.0) + buf[(area.left() + x, area.top() + y - self.scroll.0)] .set_symbol(symbol) .set_style(*style); x += width as u16; diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs index 12a3de53..9f95c370 100644 --- a/src/widgets/sparkline.rs +++ b/src/widgets/sparkline.rs @@ -206,7 +206,7 @@ impl Sparkline<'_> { RenderDirection::LeftToRight => spark_area.left() + i as u16, RenderDirection::RightToLeft => spark_area.right() - i as u16 - 1, }; - buf.get_mut(x, spark_area.top() + j) + buf[(x, spark_area.top() + j)] .set_symbol(symbol) .set_style(self.style); diff --git a/tests/stylize.rs b/tests/stylize.rs index f39b00d7..f0a89166 100644 --- a/tests/stylize.rs +++ b/tests/stylize.rs @@ -39,21 +39,21 @@ fn barchart_can_be_stylized() { for y in area.y..area.height { // background for x in area.x..area.width { - expected.get_mut(x, y).set_bg(Color::White); + expected[(x, y)].set_bg(Color::White); } // bars for x in [0, 1, 3, 4, 6, 7] { - expected.get_mut(x, y).set_fg(Color::Red); + expected[(x, y)].set_fg(Color::Red); } } // values for x in 0..3 { - expected.get_mut(x * 3, 3).set_fg(Color::Green); + expected[(x * 3, 3)].set_fg(Color::Green); } // labels for x in 0..3 { - expected.get_mut(x * 3, 4).set_fg(Color::Blue); - expected.get_mut(x * 3 + 1, 4).set_fg(Color::Reset); + expected[(x * 3, 4)].set_fg(Color::Blue); + expected[(x * 3 + 1, 4)].set_fg(Color::Reset); } terminal.backend().assert_buffer(&expected); } @@ -80,14 +80,11 @@ fn block_can_be_stylized() -> io::Result<()> { ]); for x in area.x..area.width { for y in area.y..area.height { - expected - .get_mut(x, y) - .set_fg(Color::Cyan) - .set_bg(Color::Cyan); + expected[(x, y)].set_fg(Color::Cyan).set_bg(Color::Cyan); } } for x in 1..=5 { - expected.get_mut(x, 0).set_fg(Color::LightBlue); + expected[(x, 0)].set_fg(Color::LightBlue); } terminal.backend().assert_buffer(&expected); Ok(()) @@ -105,7 +102,7 @@ fn paragraph_can_be_stylized() -> io::Result<()> { let mut expected = Buffer::with_lines(["Text "]); for x in 0..4 { - expected.get_mut(x, 0).set_fg(Color::Cyan); + expected[(x, 0)].set_fg(Color::Cyan); } terminal.backend().assert_buffer(&expected); Ok(()) diff --git a/tests/terminal.rs b/tests/terminal.rs index 0ad5efb5..fc307d56 100644 --- a/tests/terminal.rs +++ b/tests/terminal.rs @@ -36,14 +36,14 @@ fn terminal_draw_returns_the_completed_frame() -> Result<(), Box> { let paragraph = Paragraph::new("Test"); f.render_widget(paragraph, f.size()); })?; - assert_eq!(frame.buffer.get(0, 0).symbol(), "T"); + assert_eq!(frame.buffer[(0, 0)].symbol(), "T"); assert_eq!(frame.area, Rect::new(0, 0, 10, 10)); terminal.backend_mut().resize(8, 8); let frame = terminal.draw(|f| { let paragraph = Paragraph::new("test"); f.render_widget(paragraph, f.size()); })?; - assert_eq!(frame.buffer.get(0, 0).symbol(), "t"); + assert_eq!(frame.buffer[(0, 0)].symbol(), "t"); assert_eq!(frame.area, Rect::new(0, 0, 8, 8)); Ok(()) } diff --git a/tests/widgets_barchart.rs b/tests/widgets_barchart.rs index 7b56b795..95679f11 100644 --- a/tests/widgets_barchart.rs +++ b/tests/widgets_barchart.rs @@ -85,11 +85,11 @@ fn widgets_barchart_group() { ]); for y in 1..(TERMINAL_HEIGHT - 3) { for x in 1..5 { - expected.get_mut(x, y).set_fg(Color::Red); - expected.get_mut(x + 5, y).set_fg(Color::Green); + expected[(x, y)].set_fg(Color::Red); + expected[(x + 5, y)].set_fg(Color::Green); } } - expected.get_mut(2, 7).set_fg(Color::Blue); - expected.get_mut(3, 7).set_fg(Color::Blue); + expected[(2, 7)].set_fg(Color::Blue); + expected[(3, 7)].set_fg(Color::Blue); terminal.backend().assert_buffer(&expected); } diff --git a/tests/widgets_block.rs b/tests/widgets_block.rs index 1c5daa13..245d5d95 100644 --- a/tests/widgets_block.rs +++ b/tests/widgets_block.rs @@ -34,7 +34,7 @@ fn widgets_block_renders() { " ", ]); for x in 1..=5 { - expected.get_mut(x, 0).set_fg(Color::LightBlue); + expected[(x, 0)].set_fg(Color::LightBlue); } terminal.backend().assert_buffer(&expected); } diff --git a/tests/widgets_canvas.rs b/tests/widgets_canvas.rs index a8a1f617..219d7e22 100644 --- a/tests/widgets_canvas.rs +++ b/tests/widgets_canvas.rs @@ -32,11 +32,11 @@ fn widgets_canvas_draw_labels() { let mut expected = Buffer::with_lines(["", "", "", "", "test "]); for row in 0..5 { for col in 0..5 { - expected.get_mut(col, row).set_bg(Color::Yellow); + expected[(col, row)].set_bg(Color::Yellow); } } for col in 0..4 { - expected.get_mut(col, 4).set_fg(Color::Blue); + expected[(col, 4)].set_fg(Color::Blue); } terminal.backend().assert_buffer(&expected); } diff --git a/tests/widgets_chart.rs b/tests/widgets_chart.rs index 65e42ce6..bcd039f6 100644 --- a/tests/widgets_chart.rs +++ b/tests/widgets_chart.rs @@ -470,7 +470,7 @@ fn widgets_chart_can_have_a_legend() { // Set expected background color for row in 0..30 { for col in 0..60 { - expected.get_mut(col, row).set_bg(Color::White); + expected[(col, row)].set_bg(Color::White); } } @@ -532,10 +532,10 @@ fn widgets_chart_can_have_a_legend() { (57, 2), ]; for (col, row) in line1 { - expected.get_mut(col, row).set_fg(Color::Blue); + expected[(col, row)].set_fg(Color::Blue); } for (col, row) in legend1 { - expected.get_mut(col, row).set_fg(Color::Blue); + expected[(col, row)].set_fg(Color::Blue); } // Set expected colors of the second dataset @@ -603,16 +603,16 @@ fn widgets_chart_can_have_a_legend() { (57, 3), ]; for (col, row) in line2 { - expected.get_mut(col, row).set_fg(Color::Green); + expected[(col, row)].set_fg(Color::Green); } for (col, row) in legend2 { - expected.get_mut(col, row).set_fg(Color::Green); + expected[(col, row)].set_fg(Color::Green); } // Set expected colors of the x axis let x_axis_title = vec![(53, 26), (54, 26), (55, 26), (56, 26), (57, 26), (58, 26)]; for (col, row) in x_axis_title { - expected.get_mut(col, row).set_fg(Color::Yellow); + expected[(col, row)].set_fg(Color::Yellow); } terminal.backend().assert_buffer(&expected); } diff --git a/tests/widgets_gauge.rs b/tests/widgets_gauge.rs index ba414355..ad296534 100644 --- a/tests/widgets_gauge.rs +++ b/tests/widgets_gauge.rs @@ -214,13 +214,13 @@ fn widgets_line_gauge_renders() { "└──────────────────┘", ]); for col in 4..10 { - expected.get_mut(col, 0).set_fg(Color::Green); + expected[(col, 0)].set_fg(Color::Green); } for col in 10..20 { - expected.get_mut(col, 0).set_fg(Color::White); + expected[(col, 0)].set_fg(Color::White); } for col in 5..7 { - expected.get_mut(col, 2).set_fg(Color::Green); + expected[(col, 2)].set_fg(Color::Green); } terminal.backend().assert_buffer(&expected); } diff --git a/tests/widgets_list.rs b/tests/widgets_list.rs index edd01bdc..27fd9e8e 100644 --- a/tests/widgets_list.rs +++ b/tests/widgets_list.rs @@ -53,7 +53,7 @@ fn widgets_list_should_highlight_the_selected_item() { " Item 3 ", ]); for x in 0..10 { - expected.get_mut(x, 1).set_bg(Color::Yellow); + expected[(x, 1)].set_bg(Color::Yellow); } terminal.backend().assert_buffer(&expected); } @@ -88,7 +88,7 @@ fn widgets_list_should_highlight_the_selected_item_wide_symbol() { " Item 3 ", ]); for x in 0..10 { - expected.get_mut(x, 1).set_bg(Color::Yellow); + expected[(x, 1)].set_bg(Color::Yellow); } terminal.backend().assert_buffer(&expected); } @@ -222,8 +222,8 @@ fn widgets_list_should_display_multiline_items() { " Item 3c", ]); for x in 0..10 { - expected.get_mut(x, 2).set_bg(Color::Yellow); - expected.get_mut(x, 3).set_bg(Color::Yellow); + expected[(x, 2)].set_bg(Color::Yellow); + expected[(x, 3)].set_bg(Color::Yellow); } terminal.backend().assert_buffer(&expected); } @@ -258,8 +258,8 @@ fn widgets_list_should_repeat_highlight_symbol() { " Item 3c", ]); for x in 0..10 { - expected.get_mut(x, 2).set_bg(Color::Yellow); - expected.get_mut(x, 3).set_bg(Color::Yellow); + expected[(x, 2)].set_bg(Color::Yellow); + expected[(x, 3)].set_bg(Color::Yellow); } terminal.backend().assert_buffer(&expected); } diff --git a/tests/widgets_table.rs b/tests/widgets_table.rs index eb8772e9..9aeb6612 100755 --- a/tests/widgets_table.rs +++ b/tests/widgets_table.rs @@ -680,7 +680,7 @@ fn widgets_table_can_have_elements_styled_individually() { ]); // First row = row color + highlight style for col in 1..=28 { - expected.get_mut(col, 2).set_style( + expected[(col, 2)].set_style( Style::default() .fg(Color::Green) .add_modifier(Modifier::BOLD), @@ -689,26 +689,18 @@ fn widgets_table_can_have_elements_styled_individually() { // Second row: // 1. row color for col in 1..=28 { - expected - .get_mut(col, 3) - .set_style(Style::default().fg(Color::LightGreen)); + expected[(col, 3)].set_style(Style::default().fg(Color::LightGreen)); } // 2. cell color for col in 11..=16 { - expected - .get_mut(col, 3) - .set_style(Style::default().fg(Color::Yellow)); + expected[(col, 3)].set_style(Style::default().fg(Color::Yellow)); } for col in 18..=23 { - expected - .get_mut(col, 3) - .set_style(Style::default().fg(Color::Red)); + expected[(col, 3)].set_style(Style::default().fg(Color::Red)); } // 3. text color for col in 21..=22 { - expected - .get_mut(col, 3) - .set_style(Style::default().fg(Color::Blue)); + expected[(col, 3)].set_style(Style::default().fg(Color::Blue)); } terminal.backend().assert_buffer(&expected); }