aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-07-26 17:48:38 +0000
committerFuwn <[email protected]>2022-07-26 17:48:38 +0000
commitfa92fdfac1a40d2b72bd1eea59d27be216284904 (patch)
tree81eeed0509d7c39e766a0107639fa5f0421e3e0a /src
parentrefactor: docs and format (diff)
downloadsydney-fa92fdfac1a40d2b72bd1eea59d27be216284904.tar.xz
sydney-fa92fdfac1a40d2b72bd1eea59d27be216284904.zip
feat(src): prefix urls everywhere
Diffstat (limited to 'src')
-rw-r--r--src/input.rs6
-rw-r--r--src/main.rs6
-rw-r--r--src/url.rs24
3 files changed, 29 insertions, 7 deletions
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 <https://github.com/gemrest/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 <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+// 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)
+ }
+}