fix: Password prompt is broken
Some checks are pending
Linux / build (push) Waiting to run
MacOS / build (push) Waiting to run
Windows / build (push) Waiting to run

This commit is contained in:
veeso
2024-10-06 11:11:03 +02:00
parent cc6c4a8bda
commit 418b132f7e
4 changed files with 30 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
# Changelog
- [Changelog](#changelog)
- [0.16.0](#0160)
- [0.15.0](#0150)
- [0.14.0](#0140)
- [0.13.0](#0130)
@@ -37,6 +38,12 @@
---
## 0.16.0
Released on
- [Issue 290](https://github.com/veeso/termscp/issues/290): Password prompt was broken
## 0.15.0
Released on 03/10/2024

View File

@@ -111,8 +111,10 @@ impl ActivityManager {
}
/// Prompt user for password to set into params.
fn prompt_password(&self, params: &mut FileTransferParams) -> Result<(), String> {
match tty::read_secret_from_tty("Password: ") {
fn prompt_password(&mut self, params: &mut FileTransferParams) -> Result<(), String> {
let ctx = self.context.as_mut().unwrap();
match tty::read_secret_from_tty(ctx.terminal(), "Password: ") {
Err(err) => Err(format!("Could not read password: {err}")),
Ok(Some(secret)) => {
debug!(

View File

@@ -20,9 +20,11 @@ pub enum Task {
#[derive(FromArgs)]
#[argh(description = "
where positional can be:
- [address] [local-wrkdir]
- [address_a] [address_b] [local-wrkdir]
OR
- [bookmark-Name] [local-wrkdir]
- -b [bookmark-name_1] -b [bookmark-name_2] [local-wrkdir]
and any combination of the above
Address syntax can be:

View File

@@ -2,11 +2,23 @@
//!
//! `Utils` implements utilities functions to work with layouts
use tuirealm::terminal::TerminalBridge;
/// Read a secret from tty with customisable prompt
pub fn read_secret_from_tty(prompt: &str) -> std::io::Result<Option<String>> {
match rpassword::prompt_password(prompt) {
pub fn read_secret_from_tty(
terminal_bridge: &mut TerminalBridge,
prompt: &str,
) -> std::io::Result<Option<String>> {
let _ = terminal_bridge.disable_raw_mode();
let _ = terminal_bridge.leave_alternate_screen();
let res = match rpassword::prompt_password(prompt) {
Ok(p) if p.is_empty() => Ok(None),
Ok(p) => Ok(Some(p)),
Err(err) => Err(err),
}
};
let _ = terminal_bridge.enter_alternate_screen();
let _ = terminal_bridge.enable_raw_mode();
res
}