From 191a9d8379c417ead23603dcde9b18b971c33d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 25 Apr 2021 18:14:19 +0200 Subject: alternate screen --- src/main.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 44b33d1..4c6c409 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,13 @@ -use std::io::{Stdout, Write, stdin, stdout}; +use std::io::{Write, stdin, stdout}; use termion::color; use termion::event::Key; use termion::input::TermRead; -use termion::raw::{IntoRawMode, RawTerminal}; +use termion::raw::IntoRawMode; +use termion::screen::AlternateScreen; fn main() { let stdin = stdin(); - let mut stdout = stdout().into_raw_mode().unwrap(); + let mut screen = AlternateScreen::from(stdout().into_raw_mode().unwrap()); // open database let db = notmuch::Database::open(&"/home/gustav/.mail", notmuch::DatabaseMode::ReadOnly).unwrap(); @@ -21,7 +22,7 @@ fn main() { .collect(); let mut i: isize = 0; - show_threads(&mut stdout, &threads, i as usize); + show_threads(&mut screen, &threads, i as usize); for c in stdin.keys() { match c.unwrap() { @@ -31,11 +32,11 @@ fn main() { _ => () } i = i.rem_euclid(threads.len() as isize); - show_threads(&mut stdout, &threads, i as usize); + show_threads(&mut screen, &threads, i as usize); } } -fn show_threads(stdout: &mut RawTerminal, threads: &Vec, highlight: usize) { +fn show_threads(stdout: &mut W, threads: &Vec, highlight: usize) { write!(stdout, "{}", termion::clear::All).unwrap(); for (i, thread) in threads.iter().enumerate() { -- cgit v1.2.1