redraw screen instead of clearing

pull/6/head
dvkt 5 years ago
parent 40f2457743
commit e7132a0bc8

@ -134,9 +134,13 @@ impl Menu {
}
};
let mut line_count = 0;
for line in iter {
line_count += 1;
let mut line_size = 0;
if !self.wide {
out.push_str(&indent);
line_size += indent.len();
}
if line.typ == Type::Info {
out.push_str(" ");
@ -154,6 +158,8 @@ impl Menu {
out.push_str(&(line.link + 1).to_string());
out.push_str(".\x1b[0m ");
}
line_size += 6;
// truncate long lines, instead of wrapping
let name = if line.name.len() > MAX_COLS {
line.name.chars().take(MAX_COLS).collect::<String>()
@ -171,11 +177,25 @@ impl Menu {
typ if !typ.is_supported() => push!("107;91", name),
_ => push!("0", name),
}
// clear rest of line
line_size += name.len();
out.push_str(&" ".repeat(cols - line_size)); // fill line
out.push_str("\r\n");
}
if self.searching {
out.push_str(&self.render_input());
}
// clear remainder of screen
let blank_line = " ".repeat(cols);
for _ in 0..rows - line_count - 1 {
out.push_str(&blank_line);
out.push_str(&"\r\n");
}
out
}

@ -105,16 +105,34 @@ impl View for Text {
.skip(self.scroll)
.take(rows - 1);
let mut lines = 0;
for line in iter {
lines += 1;
if line == ".\r" {
continue;
}
let mut line_size = 0;
if !self.wide {
out.push_str(&indent);
line_size += indent.len();
}
out.push_str(line);
line_size += line.len();
// clear rest of line
out.push_str(&" ".repeat(cols - line_size)); // fill line
out.push_str("\r\n");
}
// clear remainder of screen
let blank_line = " ".repeat(cols);
for _ in 0..rows - lines - 1 {
out.push_str(&blank_line);
out.push_str(&"\r\n");
}
out
}
}

@ -72,13 +72,20 @@ impl UI {
let mut out = self.out.borrow_mut();
write!(
out,
"{}{}{}{}{}",
termion::clear::All,
"{}{}{}",
termion::cursor::Goto(1, 1),
termion::cursor::Hide,
screen,
status,
);
if status.len() > 0 {
write!(
out,
"{}{}{}",
termion::cursor::Goto(1, self.rows()),
status,
termion::cursor::Show,
);
}
out.flush();
self.dirty = false;
}

Loading…
Cancel
Save