aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer/mod.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-05-02 22:53:30 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-05-02 22:53:30 +0200
commit9e393263e820c328355ac58584ac635540ef2e6b (patch)
tree1dcb48b87c5f919afc1408bd5b508ba17c0a2ecc /src/buffer/mod.rs
parentea012211b6ad4d6973504b334816c568af9e60f3 (diff)
downloadmail-9e393263e820c328355ac58584ac635540ef2e6b.tar.gz
add basic window abstraction
Diffstat (limited to 'src/buffer/mod.rs')
-rw-r--r--src/buffer/mod.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs
index 10b49c1..0a7e9ba 100644
--- a/src/buffer/mod.rs
+++ b/src/buffer/mod.rs
@@ -1,23 +1,33 @@
mod threads;
+use crate::window::Window;
+
use std::io::{Stdin, Write};
use termion::event::Key;
use termion::input::TermRead;
pub use threads::Threads;
+
pub struct Client {
+ window: Window,
buffers: Vec<Buffer>,
}
impl Client {
- pub fn new(initial_buffer: Buffer) -> Self {
+ pub fn new<W: Write>(initial_buffer: Buffer, out: &mut W) -> Self {
+ let mut window = Window::new();
+ match &initial_buffer {
+ Buffer::Threads(t) => t.fill_window(&mut window),
+ }
+ window.draw(out).unwrap();
Self {
+ window,
buffers: vec![initial_buffer],
}
}
- pub fn run<W: Write>(mut self, mut screen: W, stdin: Stdin) {
+ pub fn run<W: Write>(mut self, out: &mut W, stdin: Stdin) {
for c in stdin.keys() {
let c = c.unwrap();
// Global keybinds
@@ -32,12 +42,14 @@ impl Client {
}
let next_buffer = match self.buffers.last_mut().unwrap() {
- Buffer::Threads(s) => s.tick(&mut screen, c),
+ Buffer::Threads(s) => s.tick(&mut self.window, c),
};
if let Some(next_buffer) = next_buffer {
self.buffers.push(next_buffer);
}
+
+ self.window.draw(out).unwrap();
}
}
}