-- Leo's gemini proxy

-- Connecting to typed-hole.org:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

commit 9013587ae97fc878f6b2bb70798c5bdeeb664a28

Author: Julien Blanchard <julien@sideburns.eu>

Date: Sat Oct 5 18:40:53 2019 +0200


Apply Clippy advices


diff --git a/src/bookmarks.rs b/src/bookmarks.rs

index 796cd2a..ef422a9 100644

--- a/src/bookmarks.rs

+++ b/src/bookmarks.rs

@@ -20,7 +20,6 @@ pub fn content() -> Vec<Url> {


content

.lines()

- .into_iter()

.map(|s| Url::parse(s).unwrap())

.collect()

}

diff --git a/src/main.rs b/src/main.rs

index d271723..fcea5f8 100644

--- a/src/main.rs

+++ b/src/main.rs

@@ -126,21 +126,16 @@ fn goto_url(s: &mut Cursive, url: &str) {


fn go_back(s: &mut Cursive) {

let previous = history::get_previous_url();

-

- match previous {

- Some(url) => goto_url(s, &url.to_string()),

- None => (),

+ if let Some(url) = previous {

+ goto_url(s, &url.to_string())

}

}


fn add_bookmark(s: &mut Cursive) {

let current_url = history::get_current_url();

- match current_url {

- Some(url) => {

- bookmarks::add(&url);

- s.add_layer(Dialog::info("Bookmark added."));

- }

- None => (),

+ if let Some(url) = current_url {

+ bookmarks::add(&url);

+ s.add_layer(Dialog::info("Bookmark added."));

}

}


@@ -245,87 +240,82 @@ fn handle_response_status(

}


fn draw_content(s: &mut Cursive, url: &Url, content: Option<Vec<u8>>) {

- match content {

- Some(data) => {

- let mut main_view = match s.find_id::<SelectView>("main") {

- Some(view) => view,

- None => panic!("Can't find main view."),

- };

-

- // set title and clear old content

- set_title(s, url.as_str());

- main_view.clear();

-

- let content_str = String::from_utf8_lossy(&data).to_string();

-

- // draw new content lines

- for line in content_str.lines() {

- match Link::from_str(line) {

- Ok(link) => match link {

- Link::Http(url, label) => {

- let mut formatted = StyledString::new();

- let www_label = format!("{} [WWW]", label);

- formatted.append(StyledString::styled(

- www_label,

- Style::from(Color::Dark(BaseColor::Green)).combine(Effect::Bold),

- ));

-

- let data = object! {

- "type" => "www",

- "url" => url.to_string()

- };

- main_view.add_item(formatted, json::stringify(data))

- }

- Link::Gopher(url, label) => {

- let mut formatted = StyledString::new();

- let gopher_label = format!("{} [Gopher]", label);

- formatted.append(StyledString::styled(

- gopher_label,

- Style::from(Color::Light(BaseColor::Magenta)).combine(Effect::Bold),

- ));

-

- let data = object! {

- "type" => "gopher",

- "url" => url.to_string()

- };

- main_view.add_item(formatted, json::stringify(data))

- }

- Link::Gemini(url, label) => {

- let mut formatted = StyledString::new();

- formatted.append(StyledString::styled(

- label,

- Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold),

- ));

-

- let data = object! {

- "type" => "gemini",

- "url" => url.to_string()

- };

- main_view.add_item(formatted, json::stringify(data))

- }

- Link::Relative(url, label) => {

- let mut formatted = StyledString::new();

- formatted.append(StyledString::styled(

- label,

- Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold),

- ));

-

- let data = object! {

- "type" => "gemini",

- "url" => url.to_string()

- };

- main_view.add_item(formatted, json::stringify(data))

- }

- Link::Unknown(_, _) => (),

- },

- Err(_) => {

- main_view.add_item(str::replace(line, "\t", " "), String::from("0"))

+ if let Some(data) = content {

+ let mut main_view = match s.find_id::<SelectView>("main") {

+ Some(view) => view,

+ None => panic!("Can't find main view."),

+ };

+

+ // set title and clear old content

+ set_title(s, url.as_str());

+ main_view.clear();

+

+ let content_str = String::from_utf8_lossy(&data).to_string();

+

+ // draw new content lines

+ for line in content_str.lines() {

+ match Link::from_str(line) {

+ Ok(link) => match link {

+ Link::Http(url, label) => {

+ let mut formatted = StyledString::new();

+ let www_label = format!("{} [WWW]", label);

+ formatted.append(StyledString::styled(

+ www_label,

+ Style::from(Color::Dark(BaseColor::Green)).combine(Effect::Bold),

+ ));

+

+ let data = object! {

+ "type" => "www",

+ "url" => url.to_string()

+ };

+ main_view.add_item(formatted, json::stringify(data))

}

- }

+ Link::Gopher(url, label) => {

+ let mut formatted = StyledString::new();

+ let gopher_label = format!("{} [Gopher]", label);

+ formatted.append(StyledString::styled(

+ gopher_label,

+ Style::from(Color::Light(BaseColor::Magenta)).combine(Effect::Bold),

+ ));

+

+ let data = object! {

+ "type" => "gopher",

+ "url" => url.to_string()

+ };

+ main_view.add_item(formatted, json::stringify(data))

+ }

+ Link::Gemini(url, label) => {

+ let mut formatted = StyledString::new();

+ formatted.append(StyledString::styled(

+ label,

+ Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold),

+ ));

+

+ let data = object! {

+ "type" => "gemini",

+ "url" => url.to_string()

+ };

+ main_view.add_item(formatted, json::stringify(data))

+ }

+ Link::Relative(url, label) => {

+ let mut formatted = StyledString::new();

+ formatted.append(StyledString::styled(

+ label,

+ Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold),

+ ));

+

+ let data = object! {

+ "type" => "gemini",

+ "url" => url.to_string()

+ };

+ main_view.add_item(formatted, json::stringify(data))

+ }

+ Link::Unknown(_, _) => (),

+ },

+ Err(_) => main_view.add_item(str::replace(line, "\t", " "), String::from("0")),

}

}

- None => (),

- };

+ }

}


fn set_title(s: &mut Cursive, text: &str) {

@@ -339,16 +329,13 @@ fn set_title(s: &mut Cursive, text: &str) {

fn follow_line(s: &mut Cursive, line: &str) {

let parsed = json::parse(line);


- match parsed {

- Ok(data) => {

- if link::is_gemini(&data) {

- let next_url = absolute::make(&data["url"].to_string()).expect("Not an URL");

- visit_url(s, &next_url)

- } else {

- open::that(data["url"].to_string()).unwrap();

- }

+ if let Ok(data) = parsed {

+ if link::is_gemini(&data) {

+ let next_url = absolute::make(&data["url"].to_string()).expect("Not an URL");

+ visit_url(s, &next_url)

+ } else {

+ open::that(data["url"].to_string()).unwrap();

}

- Err(_) => (),

}

}




---

Served by Pollux Gemini Server.

-- Response ended

-- Page fetched on Sun May 19 12:06:21 2024