From fa92fdfac1a40d2b72bd1eea59d27be216284904 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 26 Jul 2022 17:48:38 +0000 Subject: feat(src): prefix urls everywhere --- src/input.rs | 6 +----- src/main.rs | 6 ++++-- src/url.rs | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/url.rs (limited to 'src') diff --git a/src/input.rs b/src/input.rs index 1fac12a..252c114 100644 --- a/src/input.rs +++ b/src/input.rs @@ -173,11 +173,7 @@ fn handle_editing_input( Command::Quit => return true, Command::Open(to) => if let Some(to) = to { - match Url::parse(&if to.starts_with("gemini://") { - to - } else { - format!("gemini://{}", to) - }) { + match Url::parse(&crate::url::prefix_gemini(&to)) { Ok(url) => { app.set_url(url); app.make_request(); diff --git a/src/main.rs b/src/main.rs index ab628f8..625f402 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,9 @@ mod command; mod input; mod stateful_list; mod ui; +mod url; +use ::url::Url; use app::App; use crossterm::{event, execute, terminal}; @@ -68,7 +70,7 @@ Report bugs to https://github.com/gemrest/sydney/issues"#, return Ok(()); } _ => { - app.url = url::Url::parse(&arg)?; + app.url = Url::parse(&url::prefix_gemini(&arg))?; app.make_request(); } @@ -80,7 +82,7 @@ Report bugs to https://github.com/gemrest/sydney/issues"#, let mut stdout = std::io::stdout(); match germ::request::request( - &url::Url::parse("gemini://fuwn.me/api/sydney/version").unwrap(), + &Url::parse("gemini://fuwn.me/api/sydney/version").unwrap(), ) { Ok(response) => if let Some(content) = response.content() { diff --git a/src/url.rs b/src/url.rs new file mode 100644 index 0000000..6f92084 --- /dev/null +++ b/src/url.rs @@ -0,0 +1,24 @@ +// This file is part of Sydney . +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// Copyright (C) 2022-2022 Fuwn +// SPDX-License-Identifier: GPL-3.0-only + +pub fn prefix_gemini(url: &str) -> String { + if url.starts_with("gemini://") { + url.to_string() + } else { + format!("gemini://{}", url) + } +} -- cgit v1.2.3