aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/grid.rs4
-rw-r--r--src/term.rs4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/grid.rs b/src/grid.rs
index d62903c9..c3473d8c 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -134,6 +134,10 @@ impl<T> Grid<T> {
}
}
+ pub fn contains(&self, cursor: &Cursor) -> bool {
+ self.lines > cursor.line && self.cols > cursor.col
+ }
+
/// Swap two lines in the grid
///
/// This could have used slice::swap internally, but we are able to have
diff --git a/src/term.rs b/src/term.rs
index 45e3cf75..0cb54240 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -36,7 +36,7 @@ pub struct RenderGrid<'a> {
impl<'a> RenderGrid<'a> {
fn new<'b>(grid: &'b mut Grid<Cell>, cursor: &'b Cursor, mode: TermMode) -> RenderGrid<'b> {
- if mode.contains(mode::SHOW_CURSOR) {
+ if mode.contains(mode::SHOW_CURSOR) && grid.contains(cursor) {
let cell = &mut grid[cursor];
mem::swap(&mut cell.fg, &mut cell.bg);
}
@@ -51,7 +51,7 @@ impl<'a> RenderGrid<'a> {
impl<'a> Drop for RenderGrid<'a> {
fn drop(&mut self) {
- if self.mode.contains(mode::SHOW_CURSOR) {
+ if self.mode.contains(mode::SHOW_CURSOR) && self.inner.contains(self.cursor) {
let cell = &mut self.inner[self.cursor];
mem::swap(&mut cell.fg, &mut cell.bg);
}