[PATCH v2] add secret input capability
Export this patch
From: Johann150 <johann.galle@protonmail.com>
This adds the secret input capability as specified for status code 11.
---
Tested.
With the previous version I tried to keep code duplication minimal by not
duplicating the code for the input prompt. The status code should have been
separate but I still think it would be better to use prompt_for_answer with
a "secret" parameter instead of duplicating the code.
src/main.rs | 24 ++++++++++++++++++++++++
src/status.rs | 2 ++
2 files changed, 26 insertions(+)
diff --git a/src/main.rs b/src/main.rs
index a8c2087..b1f1534 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -117,6 +117,26 @@ fn prompt_for_answer(s: &mut Cursive, url: Url, message: String) {
);
}
+fn prompt_for_secret_answer(s: &mut Cursive, url: Url, message: String) {
+ s.add_layer(
+ Dialog::new()
+ .title(message)
+ // Padding is (left, right, top, bottom)
+ .padding((1, 1, 1, 0))
+ .content(
+ EditView::new()
+ .secret()
+ .on_submit(move |s, response| {
+ let link = format!("{}?{}", url.to_string(), response);
+ s.pop_layer();
+ follow_link(s, &link);
+ })
+ .fixed_width(60),
+ )
+ .with_id("url_query"),
+ );
+}
+
fn goto_url(s: &mut Cursive, url: &str) {
// Prepend gemini scheme if needed
if url.starts_with("gemini://") {
@@ -243,6 +263,10 @@ fn handle_response_status(
prompt_for_answer(s, url_copy, message);
None
}
+ Status::Secret(message) => {
+ prompt_for_secret_answer(s, url_copy, message);
+ None
+ }
other_status => {
s.add_layer(Dialog::info(format!("ERROR: {:?}", other_status)));
None
diff --git a/src/status.rs b/src/status.rs
index 2b70940..37039fd 100644
--- a/src/status.rs
+++ b/src/status.rs
@@ -6,6 +6,7 @@ use std::str::FromStr;
#[derive(Debug)]
pub enum Status {
Input(String),
+ Secret(String),
Success(String),
SuccessEndOfClientCertificateSession(String),
RedirectTemporary(String),
@@ -59,6 +60,7 @@ impl FromStr for Status {
fn make_status(code: i16, meta: String) -> Status {
match code {
10 => Status::Input(meta),
+ 11 => Status::Secret(meta),
20 => Status::Success(meta),
21 => Status::SuccessEndOfClientCertificateSession(meta),
30 => Status::RedirectTemporary(meta),
--
2.20.1
I still prefer some duplication instead of adding flags to existing
methods. Thanks again!