aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/window.rs')
-rw-r--r--src/window.rs42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/window.rs b/src/window.rs
index 178c484..f01cfe9 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -3,6 +3,14 @@
use std::io::Write;
use termion::{clear, color, cursor};
+#[derive(Clone, Copy)]
+pub struct Area {
+ pub x: u16,
+ pub y: u16,
+ pub w: u16,
+ pub h: u16,
+}
+
pub enum Line {
Normal(String),
Highlight(String),
@@ -19,20 +27,26 @@ impl Window {
}
}
- pub fn draw<W: Write>(&mut self, out: &mut W) -> Result<(), std::io::Error> {
- write!(out, "{}", clear::All)?;
-
- for (i, line) in self.lines.iter().enumerate() {
- write!(out, "{}", cursor::Goto(1, (i + 1) as u16))?;
- match line {
- Line::Normal(s) => write!(out, "{}", s)?,
- Line::Highlight(s) => write!(
- out,
- "{}{}{}",
- color::Fg(color::Red),
- s,
- color::Fg(color::Reset),
- )?,
+ pub fn draw<W: Write>(&mut self, out: &mut W, area: Area) -> Result<(), std::io::Error> {
+ let mut y = area.y;
+ let mut lines = self.lines.iter();
+ while y < area.h + 1 {
+ match lines.next() {
+ Some(line) => {
+ write!(out, "{}", cursor::Goto(area.x, y))?;
+ match line {
+ Line::Normal(s) => write!(out, "{}", s)?,
+ Line::Highlight(s) => write!(
+ out,
+ "{}{}{}",
+ color::Fg(color::Red),
+ s,
+ color::Fg(color::Reset),
+ )?,
+ }
+ y += 1;
+ }
+ None => break,
}
}
out.flush()?;