Skip to content

Commit

Permalink
fix(screen): clear area before print buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
metiftikci committed Oct 21, 2023
1 parent edd5428 commit 53d431a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/screen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
buffer::{mode::BufferMode, Buffer},
core::{Point, Size},
core::{Point, Rectangle, Size},
editor::Editor,
terminal::CursorStyle,
theme::{Color, THEME_ONE as T, WHITE},
Expand Down Expand Up @@ -178,6 +178,8 @@ impl Screen {
}

pub fn print_buffer(&mut self, buffer: &Buffer) {
self.clear_square(buffer.area.clone());

for y in 0..buffer.area.height {
let row_index = buffer.scroll.y + y as usize;
match buffer.get_line_visible_text(row_index) {
Expand Down Expand Up @@ -257,4 +259,20 @@ impl Screen {
}
}
}

pub fn clear_square(&mut self, area: Rectangle<u16>) {
for row in 0..area.height {
for column in 0..area.width {
let cell = self
.rows
.get_mut((area.y + row) as usize)
.unwrap()
.get_mut((area.x + column) as usize)
.unwrap();

cell.background_color = T.bg;
cell.char = ' ';
}
}
}
}

0 comments on commit 53d431a

Please sign in to comment.