save history if we can

pull/6/head
dvkt 5 years ago
parent 78c6d46730
commit 378658fc15

@ -54,11 +54,11 @@ Just unzip/untar the `phetch` program into your $PATH and get going!
### basics
- [ ] download to ~/Downloads
gopher://zaibatsu.circumlunar.space/1/~cardboard64/
- [ ] `?` to show all keyboard shortcuts
- [ ] save history to file
- [ ] load history from file
- [ ] load most recent URL when opening without args
- [ ] ipv6
- [ ] flesh out help
### bonus
- [ ] TLS
- [ ] fuzzy find search links

@ -66,6 +66,7 @@ impl UI {
self.draw();
self.update();
}
self.shutdown();
}
pub fn draw(&mut self) {
@ -157,6 +158,36 @@ impl UI {
}
}
fn shutdown(&self) {
self.save_history();
}
fn save_history(&self) {
use std::fs::OpenOptions;
use std::path::Path;
let homevar = std::env::var("HOME");
if homevar.is_err() {
return;
}
let dotdir = "~/.config/phetch".replace('~', &homevar.unwrap());
let dotdir = Path::new(&dotdir);
if !dotdir.exists() {
return;
}
let mut out = String::new();
for page in &self.pages {
out.push_str(&page.url());
out.push('\n');
}
let history = dotdir.join("history");
if let Ok(mut file) = OpenOptions::new().append(true).create(true).open(history) {
file.write_all(out.as_ref());
}
}
fn term_size(&mut self, cols: usize, rows: usize) {
self.size = (cols, rows);
}

Loading…
Cancel
Save