From f79014235e85554e3661b3f2a02b8fa88bc192ff Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 21 Nov 2024 16:53:17 +0000 Subject: feat(login): overhaul login experience * simplify login menu, making it more accessable to newcomers and easier to select remote signer options * enable `ngit login` to work from anywhere (not just a git repo) * assume fresh login details saved to global git config but fallback to local repository * maintain local repository login via `ngit login --local` * maintain login via CLI arguments eg `ngit send --nsec nsec123` * nudge users to remember nsec when pasting in ncryptsec for a better UX, whilst maintaining the option to be prompted for password everytime * create placeholder menu items for help menu and create account --- src/lib/cli_interactor.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/lib/cli_interactor.rs') diff --git a/src/lib/cli_interactor.rs b/src/lib/cli_interactor.rs index dcaccf1..7d67961 100644 --- a/src/lib/cli_interactor.rs +++ b/src/lib/cli_interactor.rs @@ -24,11 +24,13 @@ impl InteractorPrompt for Interactor { if !parms.default.is_empty() { input.default(parms.default); } + input.report(parms.report); Ok(input.interact_text()?) } fn password(&self, parms: PromptPasswordParms) -> Result { let mut p = Password::with_theme(&self.theme); p.with_prompt(parms.prompt); + p.report(parms.report); if parms.confirm { p.with_confirmation("confirm password", "passwords didnt match..."); } @@ -44,10 +46,10 @@ impl InteractorPrompt for Interactor { } fn choice(&self, parms: PromptChoiceParms) -> Result { let mut choice = dialoguer::Select::with_theme(&self.theme); - choice - .with_prompt(parms.prompt) - .report(parms.report) - .items(&parms.choices); + if !parms.prompt.is_empty() { + choice.with_prompt(parms.prompt); + } + choice.report(parms.report).items(&parms.choices); if let Some(default) = parms.default { if std::env::var("NGITTEST").is_err() { choice.default(default); @@ -73,6 +75,7 @@ impl InteractorPrompt for Interactor { pub struct PromptInputParms { pub prompt: String, pub default: String, + pub report: bool, pub optional: bool, } @@ -89,12 +92,18 @@ impl PromptInputParms { self.optional = true; self } + + pub fn dont_report(mut self) -> Self { + self.report = false; + self + } } #[derive(Default)] pub struct PromptPasswordParms { pub prompt: String, pub confirm: bool, + pub report: bool, } impl PromptPasswordParms { @@ -106,6 +115,10 @@ impl PromptPasswordParms { self.confirm = true; self } + pub fn dont_report(mut self) -> Self { + self.report = false; + self + } } #[derive(Default)] @@ -140,10 +153,11 @@ impl PromptChoiceParms { self } - // pub fn dont_report(mut self) -> Self { - // self.report = false; - // self - // } + pub fn dont_report(mut self) -> Self { + self.report = false; + self + } + pub fn with_choices(mut self, choices: Vec) -> Self { self.choices = choices; self -- cgit v1.2.3