Skip to content

Commit

Permalink
Merge pull request #336 from jtschuster/WriteOver
Browse files Browse the repository at this point in the history
Write over instead of clearing to avoid flicker
  • Loading branch information
cantino authored Mar 6, 2023
2 parents 85e024f + a0840f9 commit 48fc3df
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,16 @@ impl<'a> Interface<'a> {

fn results<W: Write>(&mut self, screen: &mut W) {
let result_top_index = self.result_top_index();
queue!(
screen,
cursor::Hide,
cursor::MoveTo(1, result_top_index),
Clear(ClearType::All)
)
.unwrap();
queue!(screen, cursor::Hide, cursor::MoveTo(1, result_top_index)).unwrap();

let (width, _height): (u16, u16) = terminal::size().unwrap();

if !self.matches.is_empty() && self.selection > self.matches.len() - 1 {
self.selection = self.matches.len() - 1;
}

for (index, command) in self.matches.iter().enumerate() {
let mut index: usize = 0;
for command in self.matches.iter() {
let mut fg = if self.settings.lightmode {
Color::Black
} else {
Expand Down Expand Up @@ -249,6 +244,7 @@ impl<'a> Interface<'a> {
queue!(
screen,
cursor::MoveTo(1, (command_line_index + result_top_index as i16) as u16),
Clear(ClearType::CurrentLine),
SetBackgroundColor(bg),
SetForegroundColor(fg),
Print(Interface::truncate_for_display(
Expand Down Expand Up @@ -320,6 +316,18 @@ impl<'a> Interface<'a> {
)
.unwrap();
}
index += 1;
}
// Since we only clear by line instead of clearing the screen each update,
// we need to clear all the lines that may have previously had a command
for i in index..(self.settings.results as usize) {
let command_line_index = self.command_line_index(i as i16);
queue!(
screen,
cursor::MoveTo(1, (command_line_index + result_top_index as i16) as u16),
Clear(ClearType::CurrentLine)
)
.unwrap();
}
}

Expand Down

0 comments on commit 48fc3df

Please sign in to comment.