Auth using TUI
This commit is contained in:
parent
4e6ef75c06
commit
fdcec0f302
15
src/main.rs
15
src/main.rs
@ -1,10 +1,19 @@
|
||||
mod auth;
|
||||
mod tui;
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
use std::io;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let (username, password) = tui::run()?;
|
||||
|
||||
println!("user = {username}");
|
||||
println!("pass = {password}");
|
||||
match auth::authenticate(&username, &password) {
|
||||
Ok(()) => {
|
||||
println!("authentication successful");
|
||||
}
|
||||
Err(_) => {
|
||||
println!("authentication failed");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
11
src/tui.rs
11
src/tui.rs
@ -36,7 +36,7 @@ pub fn run() -> io::Result<(String, String)> {
|
||||
let user = Paragraph::new(username.as_str())
|
||||
.block(Block::default().borders(Borders::ALL).title("User"))
|
||||
.style(if focus == 0 {
|
||||
Style::new().fg(Color::from_u32(0x00235759))
|
||||
Style::new().fg(Color::from_u32(0x00_235759))
|
||||
} else {
|
||||
Style::default()
|
||||
});
|
||||
@ -44,7 +44,7 @@ pub fn run() -> io::Result<(String, String)> {
|
||||
let pass = Paragraph::new(password.as_str())
|
||||
.block(Block::default().borders(Borders::ALL).title("Password"))
|
||||
.style(if focus == 1 {
|
||||
Style::new().fg(Color::from_u32(0x00235759))
|
||||
Style::new().fg(Color::from_u32(0x00_235759))
|
||||
} else {
|
||||
Style::default()
|
||||
});
|
||||
@ -57,7 +57,12 @@ pub fn run() -> io::Result<(String, String)> {
|
||||
match key.code {
|
||||
KeyCode::Esc => break,
|
||||
KeyCode::Tab => focus = (focus + 1) % 2,
|
||||
KeyCode::Enter => break,
|
||||
KeyCode::Enter => {
|
||||
if !username.is_empty() && !password.is_empty() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KeyCode::Backspace => {
|
||||
if focus == 0 {
|
||||
username.pop();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user