use title when opening

pull/6/head
dvkt 5 years ago
parent 155a20c1b9
commit 326248d711

@ -28,6 +28,8 @@
phetch -h # Show help.
phetch -v # Show version.
Once you've launched phetch, use `ctrl-h` to view the on-line help.
## installation
Binaries for Linux and Mac are available at https://github.com/dvkt/phetch/releases
@ -48,19 +50,17 @@ Just unzip/untar the `phetch` program into your $PATH and get going!
## todo
- [ ] history help file
- [ ] new screenshots
- [ ] little GIF screencast in README
- [ ] telnet: gopher://bitreich.org/1/lawn/bbs
## bugs
- [ ] history is only saved for Menu links, not ctrl-g or cmdline.
- [ ] gopher://1436.ninja/1/twit.cgi ("iWritten and performed by Nathaniel" weirdness)
## future features
- [ ] Incremental search in Text views
- [ ] Linked gopher and http links in Text views
- [ ] Linked gopher and http URLs in Text views
- [ ] TLS -- https://dataswamp.org/~solene/2019-03-07-gopher-server-tls.html
- [ ] Fuzzy Find incremental search

@ -39,5 +39,5 @@ pub fn as_raw_menu() -> String {
// save a single bookmark entry
pub fn save(label: &str, url: &str) -> Result<()> {
config::append(BOOKMARKS_FILE, label, url)
config::append(BOOKMARKS_FILE, label.trim_start_matches("gopher://"), url)
}

@ -40,7 +40,7 @@ fn main() {
}
let mut ui = UI::new();
if let Err(e) = ui.open(url) {
if let Err(e) = ui.open(url, url) {
eprintln!("{}", e);
exit(1);
}

@ -1,11 +1,9 @@
use std::fmt;
use std::io::stdout;
use std::io::Write;
use std::thread;
use gopher;
use gopher::Type;
use history;
use ui;
use ui::{Action, Key, View, MAX_COLS, SCROLL_LINES};
@ -470,26 +468,21 @@ impl Menu {
self.input.clear();
if let Some(line) = self.link(self.link) {
let url = line.url.to_string();
let (typ, host, _, _) = gopher::parse_url(&url);
let (typ, _, _, _) = gopher::parse_url(&url);
match typ {
Type::Search => {
if let Some(query) = ui::prompt(&format!("{}> ", line.name)) {
Action::Open(format!("{}?{}", url, query))
Action::Open(
format!("{}> {}", line.name, query),
format!("{}?{}", url, query),
)
} else {
Action::None
}
}
Type::Error => Action::Error(line.name.to_string()),
Type::Telnet => Action::Error("Telnet support coming soon".into()),
_ => {
// don't record internal urls
if host != "phetch" && (typ == Type::Text || typ == Type::Menu) {
let hurl = url.to_string();
let hname = line.name.clone();
thread::spawn(move || history::save(&hname, &hurl));
}
Action::Open(url)
}
_ => Action::Open(line.name.to_string(), url),
}
} else {
Action::None

@ -18,6 +18,7 @@ use bookmarks;
use gopher;
use gopher::Type;
use help;
use history;
use menu::Menu;
use text::Text;
use utils;
@ -83,7 +84,7 @@ impl UI {
}
}
pub fn open(&mut self, url: &str) -> Result<()> {
pub fn open(&mut self, title: &str, url: &str) -> Result<()> {
// no open loops
if let Some(page) = self.views.get(self.focused) {
if page.url() == url {
@ -112,7 +113,7 @@ impl UI {
};
}
self.fetch(url).and_then(|page| {
self.fetch(title, url).and_then(|page| {
self.add_page(page);
Ok(())
})
@ -134,11 +135,15 @@ impl UI {
})
}
fn fetch(&mut self, url: &str) -> Result<Page> {
fn fetch(&mut self, title: &str, url: &str) -> Result<Page> {
// on-line help
if url.starts_with("gopher://phetch/") {
return self.fetch_internal(url);
}
// record history urls
let hurl = url.to_string();
let hname = title.to_string();
thread::spawn(move || history::save(&hname, &hurl));
// request thread
let thread_url = url.to_string();
let res = self.spinner("", move || gopher::fetch_url(&thread_url))??;
@ -292,7 +297,7 @@ impl UI {
Action::Keypress(Key::Ctrl('q')) => self.running = false,
Action::Error(e) => return Err(error!(e)),
Action::Redraw => self.dirty = true,
Action::Open(url) => self.open(&url)?,
Action::Open(title, url) => self.open(&title, &url)?,
Action::Keypress(Key::Left) | Action::Keypress(Key::Backspace) => {
if self.focused > 0 {
self.dirty = true;
@ -317,15 +322,19 @@ impl UI {
Action::Keypress(Key::Ctrl('g')) => {
if let Some(url) = prompt("Go to URL: ") {
if !url.contains("://") && !url.starts_with("gopher://") {
self.open(&format!("gopher://{}", url))?;
self.open(&url, &format!("gopher://{}", url))?;
} else {
self.open(&url)?;
self.open(&url, &url)?;
}
}
}
Action::Keypress(Key::Ctrl('h')) => self.open("gopher://phetch/1/help")?,
Action::Keypress(Key::Ctrl('a')) => self.open("gopher://phetch/1/history")?,
Action::Keypress(Key::Ctrl('b')) => self.open("gopher://phetch/1/bookmarks")?,
Action::Keypress(Key::Ctrl('h')) => self.open("Help", "gopher://phetch/1/help")?,
Action::Keypress(Key::Ctrl('a')) => {
self.open("History", "gopher://phetch/1/history")?
}
Action::Keypress(Key::Ctrl('b')) => {
self.open("Bookmarks", "gopher://phetch/1/bookmarks")?
}
Action::Keypress(Key::Ctrl('s')) => {
if let Some(page) = self.views.get(self.focused) {
let url = page.url();

@ -2,9 +2,9 @@ use ui::Key;
#[derive(Debug)]
pub enum Action {
None, // do nothing
Open(String), // open url
Keypress(Key), // unknown keypress
Redraw, // redraw everything
Error(String), // error message
None, // do nothing
Open(String, String), // open(title, url)
Keypress(Key), // unknown keypress
Redraw, // redraw everything
Error(String), // error message
}

Loading…
Cancel
Save