feature (UI): hiding password in login screen

This commit is contained in:
antifallobst 2023-06-29 13:20:38 +02:00
parent 2c894e895e
commit 124406e475
1 changed files with 15 additions and 9 deletions

View File

@ -3,18 +3,18 @@ use crossterm::{
event::{self, DisableMouseCapture, EnableMouseCapture, Event, read}, event::{self, DisableMouseCapture, EnableMouseCapture, Event, read},
execute, execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
style::{style},
}; };
use anyhow::{Error, Result}; use anyhow::{Error, Result};
use std::io::Stdout; use std::io::Stdout;
use std::io; use std::io;
use crossterm::style::style;
use tui::{backend::CrosstermBackend, layout::{Constraint, Direction, Layout, Rect}, widgets::{Block, Borders, Widget}, Terminal, Frame}; use tui::{backend::CrosstermBackend, layout::{Constraint, Direction, Layout, Rect}, widgets::{Block, Borders, Widget}, Terminal, Frame};
use tui::layout::Alignment; use tui::layout::Alignment;
use tui::style::{Color, Modifier, Style}; use tui::style::{Color, Modifier, Style};
use tui::text::{Spans, Span, Text}; use tui::text::{Spans, Span, Text};
use tui::widgets::{Paragraph, Wrap}; use tui::widgets::{Paragraph, Wrap};
use tui_textarea::{Input, Key, TextArea}; use tui_textarea::{Input, Key, TextArea};
use tui_textarea::Key::Char;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
enum SetupInputPosition { enum SetupInputPosition {
@ -198,6 +198,7 @@ impl UI {
let mut homeserver = TextArea::default(); let mut homeserver = TextArea::default();
let mut username = TextArea::default(); let mut username = TextArea::default();
let mut password = TextArea::default(); let mut password = TextArea::default();
let mut password_data = TextArea::default();
homeserver.set_block( homeserver.set_block(
@ -283,7 +284,7 @@ impl UI {
SetupInputPosition::Ok SetupInputPosition::Ok
}, },
SetupInputPosition::Ok => { SetupInputPosition::Ok => {
if app.accounts_manager.add(&homeserver.lines()[0], &username.lines()[0], &password.lines()[0]).await.is_ok() { if app.accounts_manager.add(&homeserver.lines()[0], &username.lines()[0], &password_data.lines()[0]).await.is_ok() {
return Ok(()) return Ok(())
} }
@ -295,13 +296,18 @@ impl UI {
} }
} }
input => { input => {
let textarea = match input_index { match input_index {
SetupInputPosition::Homeserver => &mut homeserver, SetupInputPosition::Homeserver => { homeserver.input(input); },
SetupInputPosition::Username => &mut username, SetupInputPosition::Username => { username.input(input); },
SetupInputPosition::Password => &mut password, SetupInputPosition::Password => {
password_data.input(input.clone());
match input.key {
Char(_) => { password.input(Input { key: Char('*'), ctrl: false, alt: false }); },
_ => { password.input(input); },
}
},
_ => continue, _ => continue,
}; }
textarea.input(input);
} }
}; };
} }