search shortcut and slightly more DRY code
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -560,7 +560,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "koxinga"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"ming-wm-lib",
|
||||
"reqwest",
|
||||
@@ -604,9 +604,9 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||
|
||||
[[package]]
|
||||
name = "ming-wm-lib"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de20ca223c0e37c8c05a69174ec8544f4c6f024a9d90321bf997882232510a42"
|
||||
checksum = "9d90e1d57dcc9ff559f34d885a0c62e86ef881b4371e3f3b02c909460d3454b5"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "koxinga"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2021"
|
||||
|
||||
[[bin]]
|
||||
@@ -8,5 +8,5 @@ name = "mingInternet_Koxinga_Browser"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
ming-wm-lib = "0.1.4"
|
||||
ming-wm-lib = "0.1.5"
|
||||
reqwest = { version = "0.12", features = [ "blocking" ] }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
A web browser for [ming-wm](https://github.com/stjet/ming-wm), and developed in it, that aims to support two things: text, and links.
|
||||
A web browser for [ming-wm](https://github.com/stjet/ming-wm), and mostly developed in it, that aims to support two things: text, and links.
|
||||
|
||||
Yes, slightly inspired by [Vimium](https://vimium.github.io).
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ Koxinga is a web browser supporting text and links.
|
||||
|
||||
- `u`: URL mode, where a URL can be inputted. Hit enter/return to go to that page.
|
||||
- `l`: Link mode. The page will now show numbers in front of any links. Input the number corresponding to the link to navigate to, then hit enter/return.
|
||||
- `s`: Search mode. Search engine is http://frogfind.de. Frogfind doesn't seem to use a valid HTTPS certificate yet. But all the other search engines block Koxinga, do not work without Javascript, or give horribly mangled invalid HTML. Such is the state of the world...
|
||||
- `j`, `k` to scroll page.
|
||||
- `0`: Go to top of page.
|
||||
- `G`: Go to bottom of page.
|
||||
|
||||
111
src/main.rs
111
src/main.rs
@@ -38,6 +38,7 @@ enum Mode {
|
||||
Normal,
|
||||
Url,
|
||||
Link,
|
||||
Search,
|
||||
}
|
||||
|
||||
impl fmt::Display for Mode {
|
||||
@@ -46,6 +47,7 @@ impl fmt::Display for Mode {
|
||||
Mode::Normal => "NORMAL",
|
||||
Mode::Url => "URL",
|
||||
Mode::Link => "LINK",
|
||||
Mode::Search => "SEARCH",
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -58,8 +60,7 @@ struct KoxingaBrowser {
|
||||
max_lines: usize,
|
||||
top_line_no: usize,
|
||||
url: Option<String>,
|
||||
url_input: String,
|
||||
link_input: String,
|
||||
input: String,
|
||||
links: Vec<String>,
|
||||
top_level_nodes: Vec<Box<Node>>,
|
||||
page: Vec<(usize, usize, String, bool)>, //x, y, text, link colour or not
|
||||
@@ -83,11 +84,15 @@ impl WindowLike for KoxingaBrowser {
|
||||
let max_lines_screen = (self.dimensions[1] - 4) / LINE_HEIGHT - 1;
|
||||
if key_press.key == 'u' {
|
||||
self.mode = Mode::Url;
|
||||
self.input = self.url.clone().unwrap_or(String::new());
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else if key_press.key == 'l' && self.url.is_some() {
|
||||
self.mode = Mode::Link;
|
||||
self.calc_page();
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else if key_press.key == 's' {
|
||||
self.mode = Mode::Search;
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else if key_press.key == 'k' {
|
||||
if self.top_line_no > 0 {
|
||||
self.top_line_no -= 1;
|
||||
@@ -110,65 +115,57 @@ impl WindowLike for KoxingaBrowser {
|
||||
WindowMessageResponse::DoNothing
|
||||
}
|
||||
},
|
||||
Mode::Url => {
|
||||
if key_press.key == '𐘂' { //the enter key
|
||||
if let Some(text) = get(&self.url_input) {
|
||||
self.url = Some(self.url_input.clone());
|
||||
Mode::Url | Mode::Search | Mode::Link => {
|
||||
if key_press.is_enter() && self.input.len() > 0 {
|
||||
let new_url = if self.mode == Mode::Search {
|
||||
"http://frogfind.de/?q=".to_string() + &self.input
|
||||
} else if self.mode == Mode::Link {
|
||||
let link_index = self.input.parse::<usize>().unwrap();
|
||||
let url = self.url.as_ref().unwrap();
|
||||
let mut link;
|
||||
if link_index < self.links.len() {
|
||||
link = self.links[link_index].clone();
|
||||
if link.chars().count() >= 2 {
|
||||
//remove the quotes
|
||||
link = link.substring(1, link.len() - 1).to_string();
|
||||
}
|
||||
if link.starts_with("/") {
|
||||
link = get_base_url(&url) + &link;
|
||||
} else if !link.starts_with("http://") && !link.starts_with("https://") {
|
||||
link = url.clone() + if url.ends_with("/") { "" } else { "/" } + &link;
|
||||
}
|
||||
} else {
|
||||
return WindowMessageResponse::DoNothing
|
||||
}
|
||||
link
|
||||
} else {
|
||||
//if Mode::Url
|
||||
self.input.clone()
|
||||
};
|
||||
if let Some(text) = get(&new_url) {
|
||||
self.url = Some(new_url.clone());
|
||||
self.top_line_no = 0;
|
||||
self.top_level_nodes = parse(&text);
|
||||
self.input = String::new();
|
||||
self.calc_page();
|
||||
self.mode = Mode::Normal;
|
||||
}
|
||||
} else if key_press.key == '𐘃' { //escape key
|
||||
self.mode = Mode::Normal;
|
||||
} else if key_press.key == '𐘁' { //backspace
|
||||
if self.url_input.len() > 0 {
|
||||
self.url_input = self.url_input.remove_last();
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else {
|
||||
return WindowMessageResponse::DoNothing;
|
||||
WindowMessageResponse::DoNothing
|
||||
}
|
||||
} else {
|
||||
self.url_input += &key_press.key.to_string();
|
||||
}
|
||||
WindowMessageResponse::JustRedraw
|
||||
},
|
||||
Mode::Link => {
|
||||
if key_press.key == '𐘂' && self.link_input.len() > 0 { //the enter key
|
||||
let link_index = self.link_input.parse::<usize>().unwrap();
|
||||
let url = self.url.as_ref().unwrap();
|
||||
if link_index < self.links.len() {
|
||||
let mut link = self.links[link_index].clone();
|
||||
if link.chars().count() >= 2 {
|
||||
//remove the quotes
|
||||
link = link.substring(1, link.len() - 1).to_string();
|
||||
}
|
||||
if link.starts_with("/") {
|
||||
link = get_base_url(&url) + &link;
|
||||
} else if !link.starts_with("http://") && !link.starts_with("https://") {
|
||||
link = url.clone() + if url.ends_with("/") { "" } else { "/" } + &link;
|
||||
}
|
||||
if let Some(text) = get(&link) {
|
||||
self.url = Some(link.to_string());
|
||||
self.url_input = link.to_string();
|
||||
self.top_line_no = 0;
|
||||
self.top_level_nodes = parse(&text);
|
||||
self.mode = Mode::Normal;
|
||||
self.calc_page();
|
||||
}
|
||||
self.link_input = String::new();
|
||||
} else if key_press.is_escape() {
|
||||
let is_link_mode = self.mode == Mode::Link;
|
||||
self.mode = Mode::Normal;
|
||||
if is_link_mode {
|
||||
self.calc_page();
|
||||
}
|
||||
self.mode = Mode::Normal;
|
||||
self.input = String::new();
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else if key_press.key == '𐘃' { //escape key'
|
||||
self.link_input = String::new();
|
||||
self.mode = Mode::Normal;
|
||||
self.calc_page();
|
||||
} else if key_press.is_backspace() && self.input.len() > 0 {
|
||||
self.input = self.input.remove_last();
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else if key_press.key == '𐘁' { //backspace
|
||||
self.link_input = self.link_input.remove_last();
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else if key_press.key.is_ascii_digit() && self.link_input.len() < 10 {
|
||||
self.link_input += &key_press.key.to_string();
|
||||
} else if (self.mode == Mode::Link && key_press.key.is_ascii_digit() && self.input.len() < 10) || (self.mode != Mode::Link && key_press.is_regular()) {
|
||||
self.input += &key_press.key.to_string();
|
||||
WindowMessageResponse::JustRedraw
|
||||
} else {
|
||||
WindowMessageResponse::DoNothing
|
||||
@@ -191,15 +188,13 @@ impl WindowLike for KoxingaBrowser {
|
||||
}
|
||||
//mode
|
||||
let mut bottom_text = self.mode.to_string() + ": ";
|
||||
if self.mode == Mode::Url {
|
||||
bottom_text += &self.url_input;
|
||||
} else if self.mode == Mode::Link {
|
||||
bottom_text += &self.link_input;
|
||||
} else if self.mode == Mode::Normal && self.dimensions[0] >= 500 {
|
||||
bottom_text += "u (url)";
|
||||
if self.mode == Mode::Normal && self.dimensions[0] >= 500 {
|
||||
bottom_text += "u (url), s (search)";
|
||||
if self.url.is_some() {
|
||||
bottom_text += ", l (link), j (down), k (up)";
|
||||
}
|
||||
} else {
|
||||
bottom_text += &self.input;
|
||||
}
|
||||
instructions.push(DrawInstructions::Text([0, self.dimensions[1] - LINE_HEIGHT], vec!["nimbus-roman".to_string()], bottom_text, theme_info.text, theme_info.background, Some(1), Some(11)));
|
||||
instructions
|
||||
|
||||
Reference in New Issue
Block a user