pull/6/head
dvkt 5 years ago
parent c2560351d5
commit ba138993d6

@ -14,6 +14,7 @@ use termion::raw::IntoRawMode;
struct App { struct App {
pages: HashMap<String, Page>, pages: HashMap<String, Page>,
cursor: String, cursor: String,
history: Vec<String>,
} }
#[derive(Debug)] #[derive(Debug)]
@ -37,6 +38,7 @@ enum Action {
None, None,
Up, Up,
Down, Down,
Back,
Open, Open,
Quit, Quit,
} }
@ -55,6 +57,14 @@ impl App {
App { App {
pages: HashMap::new(), pages: HashMap::new(),
cursor: String::new(), cursor: String::new(),
history: Vec::new(),
}
}
fn back(&mut self) {
if self.history.len() > 1 {
self.history.pop();
self.cursor = self.history.last().unwrap().to_string();
} }
} }
@ -62,6 +72,7 @@ impl App {
let mut page = self.fetch(host, port, selector); let mut page = self.fetch(host, port, selector);
page.parse_links(); page.parse_links();
self.cursor = page.url.to_string(); self.cursor = page.url.to_string();
self.history.push(self.cursor.to_string());
self.pages.insert(page.url.to_string(), page); self.pages.insert(page.url.to_string(), page);
} }
@ -78,6 +89,7 @@ impl App {
Some(page) => match read_input() { Some(page) => match read_input() {
Action::Up => page.cursor_up(), Action::Up => page.cursor_up(),
Action::Down => page.cursor_down(), Action::Down => page.cursor_down(),
Action::Back => self.back(),
Action::Open => { Action::Open => {
if page.cursor > 0 && page.cursor - 1 < page.links.len() { if page.cursor > 0 && page.cursor - 1 < page.links.len() {
let link = &page.links[page.cursor - 1]; let link = &page.links[page.cursor - 1];
@ -279,7 +291,7 @@ fn read_input() -> Action {
Key::Up | Key::Ctrl('p') => return Action::Up, Key::Up | Key::Ctrl('p') => return Action::Up,
Key::Down | Key::Ctrl('n') => return Action::Down, Key::Down | Key::Ctrl('n') => return Action::Down,
Key::Ctrl(c) => print!("Ctrl-{}", c), Key::Ctrl(c) => print!("Ctrl-{}", c),
Key::Left => print!("<left>"), Key::Left => return Action::Back,az
Key::Right => print!("<right>"), Key::Right => print!("<right>"),
Key::Backspace | Key::Delete => { Key::Backspace | Key::Delete => {
input.pop(); input.pop();

Loading…
Cancel
Save