Auth using TUI

This commit is contained in:
Candifloss 2026-01-19 22:13:22 +05:30
parent 4e6ef75c06
commit fdcec0f302
2 changed files with 20 additions and 6 deletions

View File

@ -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(())
}

View File

@ -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();