~julienxx/asuka

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] add secret input capability

Details
Message ID
<20201108152659.4676-1-johann.galle@gmx.net>
DKIM signature
pass
Download raw message
Patch: +17 -12
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
Details
Message ID
<C6YPBR9W9O1P.317ZSNIXYMACC@t495.typed-hole.org>
In-Reply-To
<20201108152659.4676-1-johann.galle@gmx.net> (view parent)
DKIM signature
pass
Download raw message
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:
> 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
Reply to thread Export thread (mbox)