mirror of
https://github.com/xvxx/phetch
synced 2024-11-10 13:10:54 +00:00
u
now allows editing URL
This commit is contained in:
parent
6a4442bcac
commit
83d5c01837
25
src/ui.rs
25
src/ui.rs
@ -345,22 +345,23 @@ impl UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Prompt user for input and return what was entered, if anything.
|
/// Prompt user for input and return what was entered, if anything.
|
||||||
fn prompt(&self, prompt: &str) -> Option<String> {
|
fn prompt(&self, prompt: &str, value: &str) -> Option<String> {
|
||||||
let rows = self.rows();
|
let rows = self.rows();
|
||||||
|
let mut input = value.to_string();
|
||||||
|
|
||||||
let mut out = self.out.borrow_mut();
|
let mut out = self.out.borrow_mut();
|
||||||
write!(
|
write!(
|
||||||
out,
|
out,
|
||||||
"{}{}{}{}{}",
|
"{}{}{}{}{}{}",
|
||||||
color::Fg(color::Reset),
|
color::Fg(color::Reset),
|
||||||
termion::cursor::Goto(1, rows),
|
termion::cursor::Goto(1, rows),
|
||||||
termion::clear::CurrentLine,
|
termion::clear::CurrentLine,
|
||||||
prompt,
|
prompt,
|
||||||
|
input,
|
||||||
termion::cursor::Show,
|
termion::cursor::Show,
|
||||||
);
|
);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
let mut input = String::new();
|
|
||||||
for k in stdin().keys() {
|
for k in stdin().keys() {
|
||||||
if let Ok(key) = k {
|
if let Ok(key) = k {
|
||||||
match key {
|
match key {
|
||||||
@ -453,7 +454,7 @@ impl UI {
|
|||||||
Action::Status(s) => self.set_status(s),
|
Action::Status(s) => self.set_status(s),
|
||||||
Action::Open(title, url) => self.open(&title, &url)?,
|
Action::Open(title, url) => self.open(&title, &url)?,
|
||||||
Action::Prompt(query, fun) => {
|
Action::Prompt(query, fun) => {
|
||||||
if let Some(response) = self.prompt(&query) {
|
if let Some(response) = self.prompt(&query, "") {
|
||||||
self.process_action(fun(response));
|
self.process_action(fun(response));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -473,12 +474,8 @@ impl UI {
|
|||||||
'a' => self.open("History", "gopher://phetch/1/history")?,
|
'a' => self.open("History", "gopher://phetch/1/history")?,
|
||||||
'b' => self.open("Bookmarks", "gopher://phetch/1/bookmarks")?,
|
'b' => self.open("Bookmarks", "gopher://phetch/1/bookmarks")?,
|
||||||
'g' => {
|
'g' => {
|
||||||
if let Some(url) = self.prompt("Go to URL: ") {
|
if let Some(url) = self.prompt("Go to URL: ", "") {
|
||||||
if !url.contains("://") && !url.starts_with("gopher://") {
|
self.open(&url, &url)?;
|
||||||
self.open(&url, &format!("gopher://{}", url))?;
|
|
||||||
} else {
|
|
||||||
self.open(&url, &url)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'h' => self.open("Help", "gopher://phetch/1/help")?,
|
'h' => self.open("Help", "gopher://phetch/1/help")?,
|
||||||
@ -502,8 +499,12 @@ impl UI {
|
|||||||
}
|
}
|
||||||
'u' => {
|
'u' => {
|
||||||
if let Some(page) = self.views.get(self.focused) {
|
if let Some(page) = self.views.get(self.focused) {
|
||||||
let url = page.url();
|
let current_url = page.url();
|
||||||
self.set_status(format!("Current URL: {}", url));
|
if let Some(url) = self.prompt("Current URL: ", ¤t_url) {
|
||||||
|
if url != current_url {
|
||||||
|
self.open(&url, &url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'y' => {
|
'y' => {
|
||||||
|
Loading…
Reference in New Issue
Block a user