mirror of
https://github.com/xvxx/phetch
synced 2024-11-10 13:10:54 +00:00
match ctrl or keypress
This commit is contained in:
parent
bb19994e2e
commit
d06b73f142
26
src/ui.rs
26
src/ui.rs
@ -398,11 +398,10 @@ impl UI {
|
||||
self.focused += 1;
|
||||
}
|
||||
}
|
||||
_ if action.key_or_ctrl('a') => self.open("History", "gopher://phetch/1/history")?,
|
||||
_ if action.key_or_ctrl('b') => {
|
||||
self.open("Bookmarks", "gopher://phetch/1/bookmarks")?
|
||||
}
|
||||
_ if action.key_or_ctrl('g') => {
|
||||
Action::Keypress(Key::Char(key)) | Action::Keypress(Key::Ctrl(key)) => match key {
|
||||
'a' => self.open("History", "gopher://phetch/1/history")?,
|
||||
'b' => self.open("Bookmarks", "gopher://phetch/1/bookmarks")?,
|
||||
'g' => {
|
||||
if let Some(url) = self.prompt("Go to URL: ") {
|
||||
if !url.contains("://") && !url.starts_with("gopher://") {
|
||||
self.open(&url, &format!("gopher://{}", url))?;
|
||||
@ -411,8 +410,8 @@ impl UI {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ if action.key_or_ctrl('h') => self.open("Help", "gopher://phetch/1/help")?,
|
||||
_ if action.key_or_ctrl('r') => {
|
||||
'h' => self.open("Help", "gopher://phetch/1/help")?,
|
||||
'r' => {
|
||||
if let Some(page) = self.views.get(self.focused) {
|
||||
let url = page.url();
|
||||
let raw = page.raw();
|
||||
@ -421,7 +420,7 @@ impl UI {
|
||||
self.add_page(Box::new(text));
|
||||
}
|
||||
}
|
||||
_ if action.key_or_ctrl('s') => {
|
||||
's' => {
|
||||
if let Some(page) = self.views.get(self.focused) {
|
||||
let url = page.url();
|
||||
match bookmarks::save(&url, &url) {
|
||||
@ -430,23 +429,22 @@ impl UI {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ if action.key_or_ctrl('u') => {
|
||||
'u' => {
|
||||
if let Some(page) = self.views.get(self.focused) {
|
||||
let url = page.url();
|
||||
self.set_status(format!("Current URL: {}", url));
|
||||
}
|
||||
}
|
||||
_ if action.key_or_ctrl('y') => {
|
||||
'y' => {
|
||||
if let Some(page) = self.views.get(self.focused) {
|
||||
let url = page.url();
|
||||
copy_to_clipboard(&url)?;
|
||||
self.set_status(format!("Copied {} to clipboard.", url));
|
||||
}
|
||||
}
|
||||
_ if action.key_or_ctrl('q') => self.running = false,
|
||||
Action::Keypress(key) => {
|
||||
return Err(error!("Unknown keypress: {:?}", key));
|
||||
}
|
||||
'q' => self.running = false,
|
||||
c => return Err(error!("Unknown keypress: {}", c)),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
Ok(())
|
||||
|
@ -8,13 +8,3 @@ pub enum Action {
|
||||
Prompt(String, Box<dyn FnOnce(String) -> Action>), // query string, callback on success
|
||||
Error(String), // error message
|
||||
}
|
||||
|
||||
impl Action {
|
||||
pub fn key_or_ctrl(&self, target: char) -> bool {
|
||||
if let Action::Keypress(Key::Ctrl(c)) | Action::Keypress(Key::Char(c)) = self {
|
||||
*c == target
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user