fit content to terminal

pull/6/head
dvkt 5 years ago
parent 6c241e9b79
commit e9f42d8574

@ -58,14 +58,10 @@ fn main() {
impl App { impl App {
fn new() -> App { fn new() -> App {
let (cols, rows) = termion::terminal_size().expect("can't get terminal size");
App { App {
pages: HashMap::new(), pages: HashMap::new(),
pos: 0, pos: 0,
history: Vec::new(), history: Vec::new(),
status: String::new(),
height: rows,
width: cols,
} }
} }
@ -274,12 +270,17 @@ impl Page {
} }
fn draw(&self) -> String { fn draw(&self) -> String {
let (_cols, rows) = termion::terminal_size().expect("can't get terminal size");
let mut line = 0;
let mut start = true; let mut start = true;
let mut skip_to_end = false; let mut skip_to_end = false;
let mut links = 0; let mut links = 0;
let mut out = String::with_capacity(self.body.len() * 2); let mut out = String::with_capacity(self.body.len() * 2);
let mut prefix = ""; let mut prefix = "";
for (i, c) in self.body.chars().enumerate() { for (i, c) in self.body.chars().enumerate() {
if line >= rows as usize {
return out;
}
let mut is_link = false; let mut is_link = false;
if start { if start {
match c { match c {
@ -311,7 +312,10 @@ impl Page {
} }
} }
'\r' => continue, '\r' => continue,
'\n' => continue, '\n' => {
line += 1;
continue;
}
_ => prefix = "", _ => prefix = "",
} }
if is_link && self.link > 0 && self.link == links { if is_link && self.link > 0 && self.link == links {
@ -338,6 +342,7 @@ impl Page {
if c == '\n' { if c == '\n' {
out.push_str("\r\n\x1B[0m"); out.push_str("\r\n\x1B[0m");
start = true; start = true;
line += 1;
skip_to_end = false; skip_to_end = false;
} }
} else if c == '\t' { } else if c == '\t' {
@ -346,6 +351,7 @@ impl Page {
out.push(c); out.push(c);
if c == '\n' { if c == '\n' {
out.push_str("\x1B[0m"); out.push_str("\x1B[0m");
line += 1;
start = true; start = true;
} }
} }

Loading…
Cancel
Save