From 0330cea7f5f69de7254187a8798c288df6cf5472 Mon Sep 17 00:00:00 2001 From: OBJNULL Date: Sat, 15 Jun 2024 15:47:50 -0400 Subject: [PATCH] Cleaned up UI --- src/interface.rs | 58 ++++++++++++++++++++++++++++-------------------- src/main.rs | 8 +++---- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/interface.rs b/src/interface.rs index cf14d13..c9a301b 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -2,6 +2,14 @@ use std::{io, process::exit}; use crate::manager; +// Constants +pub const COLOR_RESET: &str = "\x1B[0m"; +pub const COLOR_RED: &str = "\x1B[31m"; +pub const COLOR_GREEN: &str = "\x1B[32m"; +pub const COLOR_YELLOW: &str = "\x1B[33m"; +pub const COLOR_MAGENTA: &str = "\x1B[35m"; +pub const COLOR_CYAN: &str = "\x1B[36m"; + // Functions fn get_credentials() -> (String, String) { // Variables @@ -21,12 +29,12 @@ fn get_credentials() -> (String, String) { return (username, password); } pub fn int_auth() -> (String, String) { - println!(" - LOGIN - "); + println!(" - {} LOGIN {} - ", COLOR_YELLOW, COLOR_RESET); return get_credentials(); } pub fn int_reg() -> (String, String) { // Register form - println!(" - REGISTER - "); + println!(" - {} REGISTER {} - ", COLOR_YELLOW, COLOR_RESET); let (username, password) = get_credentials(); // Confirming password @@ -49,13 +57,13 @@ pub fn int_welcome(username: &String) -> String { let mut user_input: String = String::new(); // Welcome message - println!("\n - RUSTYPASS - "); - println!("Welcome, {}!", username); + println!("\n - {} RUSTYPASS {} - ", COLOR_YELLOW, COLOR_RESET); + println!("Welcome, {}{}{}!", COLOR_CYAN, username, COLOR_RESET); println!("Please select one of the following options: "); - println!("\n1) View a Password"); - println!("2) Create a Password"); - println!("3) Generate a Password"); - println!("4) Quit"); + println!("\n{}1{}) View a Password", COLOR_GREEN, COLOR_RESET); + println!("{}2{}) Create a Password", COLOR_GREEN, COLOR_RESET); + println!("{}3{}) Generate a Password", COLOR_GREEN, COLOR_RESET); + println!("{}4{}) Quit", COLOR_GREEN, COLOR_RESET); io::stdin().read_line(&mut user_input).expect("Failed to read line"); // Returning what the user said @@ -68,16 +76,16 @@ pub fn int_gen() -> (u32, bool, bool) { let mut raw_pass_spe: String = String::new(); // Asking the user the big questions - println!("\n - Password Generator - "); + println!("\n - {} Password Generator {} - ", COLOR_YELLOW, COLOR_RESET); println!("Before we give you a password, just a few questions!"); println!("How long should your password be?"); - println!("Select size[number]: "); + println!("Select size[{}number{}]: ", COLOR_CYAN, COLOR_RESET); io::stdin().read_line(&mut raw_pass_len).expect("Failed to read line."); println!("\nWould you like numbers to be included in your password?"); - println!("Select option[y/n]: "); + println!("Select option[{0}y{1}/{0}n{1}]: ", COLOR_CYAN, COLOR_RESET); io::stdin().read_line(&mut raw_pass_num).expect("Failed to read line."); println!("\nWould you like special characters to be included in your password?"); - println!("Select option[y/n]: "); + println!("Select option[{0}y{1}/{0}n{1}]: ", COLOR_CYAN, COLOR_RESET); io::stdin().read_line(&mut raw_pass_spe).expect("Failed to read line."); // Converting the stuff @@ -97,6 +105,8 @@ pub fn int_gen() -> (u32, bool, bool) { false }; + println!(""); + // Returning all of the values return (pass_len, pass_num, pass_spe); } @@ -108,16 +118,16 @@ pub fn int_create() -> (String, String, String) { let mut raw_pass_phrase: String = String::new(); // Asking the user some questions - println!(" - Create a Password - "); + println!(" - {} Create a Password {} - ", COLOR_YELLOW, COLOR_RESET); println!("To create a password, we need to ask you a few simple questions."); println!("First, what would you like to call your Password?"); - println!("Select Name: "); + println!("Select {}Name{}: ", COLOR_CYAN, COLOR_RESET); io::stdin().read_line(&mut raw_pass_name).expect("Failed to read line"); println!("\nNext, What is the username for this password?"); - println!("Select User: "); + println!("Select {}User{}: ", COLOR_CYAN, COLOR_RESET); io::stdin().read_line(&mut raw_pass_user).expect("Failed to read line"); println!("\nFinally, Would you like to use your own passphrase or a generated one?"); - println!("Select passphrase [generate, custom]: "); + println!("Select passphrase [{0}generate{1}/{0}custom{1}]: ", COLOR_CYAN, COLOR_RESET); io::stdin().read_line(&mut raw_pass_type).expect("Failed to read line"); // Formatting inputs @@ -131,8 +141,8 @@ pub fn int_create() -> (String, String, String) { let (pass_len, pass_num, pass_spe) = int_gen(); pass_phrase = manager::Manager::password_generate(pass_len, pass_num, pass_spe); } else if pass_type == "custom" { - println!("Enter your custom password"); - println!("Select Passphrase: "); + println!("\nEnter your custom password"); + println!("Select {}Passphrase{}: ", COLOR_CYAN, COLOR_RESET); io::stdin().read_line(&mut raw_pass_phrase).expect("Failed to read line"); pass_phrase = String::from(raw_pass_phrase.trim()); } else { @@ -148,9 +158,9 @@ pub fn int_view(manager: &mut manager::Manager) { let mut pass_name: String = String::new(); // Asking the user some questions - println!(" - Password View - "); + println!(" - {} Password View {} - ", COLOR_YELLOW, COLOR_RESET); println!("What is your passwords name?"); - println!("Select Name: "); + println!("Select {}Name{}: ", COLOR_CYAN, COLOR_RESET); io::stdin().read_line(&mut pass_name).expect("Failed to read line"); // Query password @@ -158,13 +168,13 @@ pub fn int_view(manager: &mut manager::Manager) { // Was it successful? if !success { - println!("Failed to get password of name {}!", pass_name); + println!("{}Failed to get password of name {}!{}", COLOR_RED, pass_name, COLOR_RESET); return; } // Show us that beautiful password! - println!("\n - Password: {} - ", pass_obj.name); - println!("Username: {}", pass_obj.user); - println!("Passphrase: {}", pass_obj.phrase); + println!("\n - {0}Password{3}: {1}{2}{3} - ", COLOR_YELLOW, COLOR_CYAN, pass_obj.name, COLOR_RESET); + println!("Username:\t{}{}{}", COLOR_MAGENTA, pass_obj.user, COLOR_RESET); + println!("Passphrase:\t{}{}{}", COLOR_GREEN, pass_obj.phrase, COLOR_RESET); println!(""); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index af1a9bc..be50593 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,16 +36,16 @@ fn stage_manager(auth_profile: &mut auth::Auth) { // Deciding what page we are on if page == "4" { - println!("Goodbye, {}!", auth_profile.username); + println!("Goodbye, {}{}{}!", interface::COLOR_CYAN, auth_profile.username, interface::COLOR_RESET); break; } else if page == "3" { let (pass_len, pass_num, pass_spe) = interface::int_gen(); let gen_pass: String = manager::Manager::password_generate(pass_len, pass_num, pass_spe); - println!("Your password is: {}", gen_pass); + println!("Your password is: {}{}{}", interface::COLOR_GREEN, gen_pass, interface::COLOR_RESET); } else if page == "2" { let (pass_name, pass_user, pass_phrase) = interface::int_create(); manager.password_create(pass_name.clone(), pass_user, pass_phrase); - println!("\nSuccessfully added {}!", pass_name); + println!("\nSuccessfully added {}{}{}!", interface::COLOR_GREEN, pass_name, interface::COLOR_RESET); } else if page == "1" { interface::int_view(&mut manager); } else { @@ -63,7 +63,7 @@ fn main() { // Before going to the accounts page, check if the auth failed if !auth_profile.verified { - println!("\nPlease try again!\n"); + println!("\n{}Invalid Credentials{}, Please try again!\n", interface::COLOR_RED, interface::COLOR_RESET); } else {break;} }