limit height for now

pull/6/head
dvkt 5 years ago
parent 8741ac8aa4
commit a48615b5d0

@ -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 {

@ -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")

Loading…
Cancel
Save