~julienxx/asuka

add secret input capability v1 NEEDS REVISION

Johann150: 1
 add secret input capability

 2 files changed, 17 insertions(+), 12 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~julienxx/asuka/patches/14806/mbox | git am -3
Learn more about email & git

[PATCH] 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.

 src/main.rs   | 24 ++++++++++++++----------
 src/status.rs |  5 +++--
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index a8c2087..2f67844 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -98,20 +98,24 @@ fn prompt_for_url(s: &mut Cursive) {
    );
}

fn prompt_for_answer(s: &mut Cursive, url: Url, message: String) {
fn prompt_for_answer(s: &mut Cursive, url: Url, message: String, secret: bool) {
    s.add_layer(
        Dialog::new()
            .title(message)
            // Padding is (left, right, top, bottom)
            .padding((1, 1, 1, 0))
            .content(
                EditView::new()
                    .on_submit(move |s, response| {
                        let link = format!("{}?{}", url.to_string(), response);
                        s.pop_layer();
                        follow_link(s, &link);
                    })
                    .fixed_width(60),
                if secret {
                    EditView::new().secret()
                } else {
                    EditView::new()
                }
                .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"),
    );
@@ -239,8 +243,8 @@ fn handle_response_status(
                ));
                None
            }
            Status::Input(message) => {
                prompt_for_answer(s, url_copy, message);
            Status::Input(message, secret) => {
                prompt_for_answer(s, url_copy, message, secret);
                None
            }
            other_status => {
diff --git a/src/status.rs b/src/status.rs
index 2b70940..d6aad96 100644
--- a/src/status.rs
+++ b/src/status.rs
@@ -5,7 +5,7 @@ use std::str::FromStr;

#[derive(Debug)]
pub enum Status {
    Input(String),
    Input(String, bool),
    Success(String),
    SuccessEndOfClientCertificateSession(String),
    RedirectTemporary(String),
@@ -58,7 +58,8 @@ impl FromStr for Status {

fn make_status(code: i16, meta: String) -> Status {
    match code {
        10 => Status::Input(meta),
        10 => Status::Input(meta, false),
        11 => Status::Input(meta, true),
        20 => Status::Success(meta),
        21 => Status::SuccessEndOfClientCertificateSession(meta),
        30 => Status::RedirectTemporary(meta),
--
2.20.1
Thanks for the patch! How about creating a new Status::Secret that would
be using a prompt_for_secret_answer method?

On Sun Nov 8, 2020 at 4:27 PM CET, Johann150 wrote: