diff --git a/src/menu.rs b/src/menu.rs index 6d516cb..0159c03 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -22,8 +22,8 @@ pub struct Line { } impl View for MenuView { - fn render(&self) -> String { - self.render_lines() + fn render(&self, w: u16, h: u16) -> String { + self.render_lines(w, h) } fn process_input(&mut self, key: Key) -> Action { @@ -52,7 +52,7 @@ impl MenuView { self.menu.links() } - fn render_lines(&self) -> String { + fn render_lines(&self, _cols: u16, rows: u16) -> String { let mut out = String::new(); macro_rules! push { @@ -66,7 +66,10 @@ impl MenuView { } let mut links = 0; - for line in self.lines() { + for (i, line) in self.lines().iter().enumerate() { + if i as u16 >= rows - 4 { + return out; + } if line.typ == Type::Info { out.push_str(" "); } else { diff --git a/src/ui.rs b/src/ui.rs index 9055a00..16c9497 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -27,7 +27,7 @@ pub enum Action { pub trait View { fn process_input(&mut self, c: Key) -> Action; - fn render(&self) -> String; + fn render(&self, width: u16, height: u16) -> String; } impl UI { @@ -49,7 +49,7 @@ impl UI { pub fn draw(&mut self) { if self.dirty { let prefix = ""; // debug - // let prefix = "\x1b[2J\x1b[H"; // clear the screen + let prefix = "\x1b[2J\x1b[H"; // clear the screen print!("{}{}", prefix, self.render()); self.dirty = false; } @@ -63,10 +63,10 @@ impl UI { } pub fn render(&self) -> String { - // let (cols, rows) = termion::terminal_size().expect("can't get terminal size"); + let (cols, rows) = termion::terminal_size().expect("can't get terminal size"); // TODO if self.pages.len() > 0 && self.page < self.pages.len() { if let Some(page) = self.pages.get(self.page) { - return page.render(); + return page.render(cols, rows); } } String::from("N/A")