From c36df73b1e3d3c7f2feeda16e79bbdb2e1a4f251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 3 May 2021 22:47:58 +0200 Subject: draw inside terminal size --- src/buffer/mod.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/buffer/mod.rs') diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 0a7e9ba..3cff6f5 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -1,6 +1,6 @@ mod threads; -use crate::window::Window; +use crate::window::{Area, Window}; use std::io::{Stdin, Write}; use termion::event::Key; @@ -16,11 +16,17 @@ pub struct Client { impl Client { pub fn new(initial_buffer: Buffer, out: &mut W) -> Self { + let size = termion::terminal_size().unwrap(); let mut window = Window::new(); match &initial_buffer { Buffer::Threads(t) => t.fill_window(&mut window), } - window.draw(out).unwrap(); + window.draw(out, Area { + x: 1, + y: 1, + w: size.0, + h: size.1, + }).unwrap(); Self { window, buffers: vec![initial_buffer], @@ -49,7 +55,15 @@ impl Client { self.buffers.push(next_buffer); } - self.window.draw(out).unwrap(); + write!(out, "{}", termion::clear::All).unwrap(); + + let size = termion::terminal_size().unwrap(); + self.window.draw(out, Area { + x: 1, + y: 1, + w: size.0, + h: size.1, + }).unwrap(); } } } -- cgit v1.2.1