wide mode

pull/6/head
dvkt 5 years ago
parent 7514399227
commit 4657dafc09

@ -20,6 +20,7 @@ ictrl-g go to gopher url
ictrl-u show current gopher url
ictrl-y copy url to clipboard
ictrl-r view raw version of page
ictrl-w toggle wide mode
i
i ~ * ~
i

@ -15,6 +15,7 @@ pub struct Menu {
pub link: usize, // selected link
pub scroll: usize, // scrolling offset
pub size: (usize, usize), // cols, rows
pub wide: bool, // in wide mode?
}
pub struct Line {
@ -114,7 +115,9 @@ impl Menu {
};
for line in iter {
out.push_str(&indent);
if !self.wide {
out.push_str(&indent);
}
if line.typ == Type::Info {
out.push_str(" ");
} else {
@ -150,10 +153,6 @@ impl Menu {
}
out.push('\n');
}
if self.lines.len() < rows {
// fill in empty space
out.push_str(&" \r\n".repeat(rows - 1 - self.lines.len()).to_string());
}
out.push_str(&format!(
"{}{}{}",
termion::cursor::Goto(1, self.size.1 as u16),
@ -384,6 +383,10 @@ impl Menu {
Key::Char('\n') => self.action_open(),
Key::Up | Key::Ctrl('p') => self.action_up(),
Key::Down | Key::Ctrl('n') => self.action_down(),
Key::Ctrl('w') => {
self.wide = !self.wide;
Action::Redraw
}
Key::Backspace | Key::Delete => {
if self.input.is_empty() {
Action::Back
@ -580,6 +583,7 @@ impl Menu {
link: 0,
scroll: 0,
size: (0, 0),
wide: false,
}
}
}

@ -1,3 +1,4 @@
use ui;
use ui::{Action, Key, View, MAX_COLS, SCROLL_LINES};
pub struct Text {
@ -7,6 +8,7 @@ pub struct Text {
lines: usize, // # of lines
longest: usize, // longest line
size: (usize, usize), // cols, rows
wide: bool, // in wide mode? turns off margins
}
impl View for Text {
@ -36,6 +38,10 @@ impl View for Text {
Action::None
}
}
Key::Ctrl('w') => {
self.wide = !self.wide;
Action::Redraw
}
Key::Down | Key::Ctrl('n') | Key::Char('j') => {
if self.lines > SCROLL_LINES && self.scroll < (self.lines - SCROLL_LINES) {
self.scroll += 1;
@ -108,7 +114,9 @@ impl View for Text {
if line == ".\r" {
continue;
}
out.push_str(&indent);
if !self.wide {
out.push_str(&indent);
}
out.push_str(line);
out.push('\n');
}
@ -134,6 +142,7 @@ impl Text {
lines,
longest,
size: (0, 0),
wide: false,
}
}
}

Loading…
Cancel
Save