Added color formatting

This commit is contained in:
Maddox Werts 2024-06-23 15:20:29 -04:00
parent a73c72fa93
commit a33495d27f

View file

@ -2,6 +2,13 @@
use crate::{board, card, manager}; use crate::{board, card, manager};
use std::{io, process::exit}; use std::{io, process::exit};
// Constants
const COLOR_CARD: &str = "\x1b[32m";
const COLOR_TITLE: &str = "\x1b[33m";
const COLOR_DESC: &str = "\x1b[35m";
const COLOR_OPTION: &str = "\x1b[36m";
const COLOR_RESET: &str = "\x1b[0m";
// Structures // Structures
pub struct Interface<'a> { pub struct Interface<'a> {
manager: &'a mut manager::Manager, manager: &'a mut manager::Manager,
@ -21,11 +28,11 @@ impl<'a> Interface<'a> {
fn p_0(&mut self) { fn p_0(&mut self) {
// Showing options // Showing options
println!(" - Tasky - "); println!(" - {}Tasky{} - ", COLOR_TITLE, COLOR_RESET);
println!("1) Open Board"); println!("{}1{}) Open Board", COLOR_OPTION, COLOR_RESET);
println!("2) Create Board"); println!("{}2{}) Create Board", COLOR_OPTION, COLOR_RESET);
println!("3) Exit"); println!("{}3{}) Exit", COLOR_OPTION, COLOR_RESET);
println!("\nSelect option [1-3]: "); println!("\nSelect option [{0}1{1}-{0}3{1}]: ", COLOR_OPTION, COLOR_RESET);
// Listening for option // Listening for option
let mut user_input: String = String::new(); let mut user_input: String = String::new();
@ -44,11 +51,11 @@ impl<'a> Interface<'a> {
} }
fn p_1(&mut self) { fn p_1(&mut self) {
// Showing options // Showing options
println!(" - Open Board - "); println!(" - {}Open Board{} - ", COLOR_TITLE, COLOR_RESET);
for i in 0..self.manager.boards.len() { for i in 0..self.manager.boards.len() {
println!("{}) {}", i+1, self.manager.boards[i].name); println!("{2}{0}{3}) {1}", i+1, self.manager.boards[i].name, COLOR_OPTION, COLOR_RESET);
} }
println!("\nSelect board [1-{}]: ", self.manager.boards.len()); println!("\nSelect board [{1}1{2}-{1}{0}{2}]: ", self.manager.boards.len(), COLOR_OPTION, COLOR_RESET);
// Selecting option // Selecting option
@ -66,20 +73,20 @@ impl<'a> Interface<'a> {
let board: &board::TaskBoard = &self.manager.boards[self.on as usize]; let board: &board::TaskBoard = &self.manager.boards[self.on as usize];
// Title // Title
println!(" - {} - \n", board.name); println!(" - {1}{0}{2} - \n", board.name, COLOR_TITLE, COLOR_RESET);
// Going through cards // Going through cards
for card in &board.cards { for card in &board.cards {
println!("- {} ({})", card.name, card.desc); println!("- {2}{0}{4} ({3}{1}{4})", card.name, card.desc, COLOR_CARD, COLOR_DESC, COLOR_RESET);
} }
// Presenting options // Presenting options
println!("\n1) Create Card"); println!("\n{}1{}) Create Card", COLOR_OPTION, COLOR_RESET);
println!("2) Edit Card"); println!("{}2{}) Edit Card", COLOR_OPTION, COLOR_RESET);
println!("3) Delete Card"); println!("{}3{}) Delete Card", COLOR_OPTION, COLOR_RESET);
println!("4) Delete Board"); println!("{}4{}) Delete Board", COLOR_OPTION, COLOR_RESET);
println!("5) Exit"); println!("{}5{}) Exit", COLOR_OPTION, COLOR_RESET);
println!("\nSelect Option [1-5]: "); println!("\nSelect Option [{0}1{1}-{0}5{1}]: ", COLOR_OPTION, COLOR_RESET);
// Selection option // Selection option
let mut user_input: String = String::new(); let mut user_input: String = String::new();
@ -104,14 +111,14 @@ impl<'a> Interface<'a> {
} }
fn p_3(&mut self){ fn p_3(&mut self){
// Title // Title
println!(" - Create Card - \n"); println!(" - {}Create Card{} - \n", COLOR_TITLE, COLOR_RESET);
// Variables // Variables
let mut user_input: String = String::new(); let mut user_input: String = String::new();
// Asking the user what the name is // Asking the user what the name is
println!("What is your card's name?"); println!("What is your card's name?");
println!("Select name: "); println!("Select name [{}name{}]: ", COLOR_OPTION, COLOR_RESET);
// Reading input // Reading input
io::stdin().read_line(&mut user_input).expect("Failed to read line"); io::stdin().read_line(&mut user_input).expect("Failed to read line");
@ -123,7 +130,7 @@ impl<'a> Interface<'a> {
// Asking the user what the description is // Asking the user what the description is
println!("Give your card a description!"); println!("Give your card a description!");
println!("Select description: "); println!("Select description [{}desc{}]: ", COLOR_OPTION, COLOR_RESET);
// Reading input // Reading input
io::stdin().read_line(&mut user_input).expect("Failed to read line"); io::stdin().read_line(&mut user_input).expect("Failed to read line");
@ -141,18 +148,18 @@ impl<'a> Interface<'a> {
} }
fn p_4(&mut self){ fn p_4(&mut self){
// Title // Title
println!(" - Edit Card - \n"); println!(" - {}Edit Card{} - \n", COLOR_TITLE, COLOR_RESET);
// Getting active board // Getting active board
let _active: &mut board::TaskBoard = &mut self.manager.boards[self.on as usize]; let _active: &mut board::TaskBoard = &mut self.manager.boards[self.on as usize];
// Showing all cards // Showing all cards
for i in 0.._active.cards.len() { for i in 0.._active.cards.len() {
println!("{}) {}", i+1, _active.cards[i].name); println!("{2}{0}{3}) {1}", i+1, _active.cards[i].name, COLOR_OPTION, COLOR_RESET);
} }
// Asking for an option // Asking for an option
println!("\nSelect card[1-{}]: ", _active.cards.len()); println!("\nSelect card[{1}1{2}-{1}{0}{2}]: ", _active.cards.len(), COLOR_OPTION, COLOR_RESET);
// Reading input // Reading input
let mut user_input: String = String::new(); let mut user_input: String = String::new();
@ -165,11 +172,11 @@ impl<'a> Interface<'a> {
let _card: &mut card::TaskCard = &mut _active.cards[_card_index]; let _card: &mut card::TaskCard = &mut _active.cards[_card_index];
// Printing options // Printing options
println!(" - {} - ", _card.name); println!(" - {1}{0}{2} - ", _card.name, COLOR_CARD, COLOR_RESET);
println!("1) Change Name"); println!("{}1{}) Change Name", COLOR_OPTION, COLOR_RESET);
println!("2) Change Description"); println!("{}2{}) Change Description", COLOR_OPTION, COLOR_RESET);
println!("3) Exit"); println!("{}3{}) Exit", COLOR_OPTION, COLOR_RESET);
println!("\nSelect option [1-3]: "); println!("\nSelect option [{0}1{1}-{0}3{1}]: ", COLOR_OPTION, COLOR_RESET);
// Reset input // Reset input
user_input = String::new(); user_input = String::new();
@ -182,7 +189,7 @@ impl<'a> Interface<'a> {
if user_input == "1" { if user_input == "1" {
// Printing prompt // Printing prompt
println!("\nWhat should the new name be?"); println!("\nWhat should the new name be?");
println!("Select name:"); println!("Select name [{}name{}]:", COLOR_OPTION, COLOR_RESET);
// Reset input // Reset input
user_input = String::new(); user_input = String::new();
@ -196,7 +203,7 @@ impl<'a> Interface<'a> {
} else if user_input == "2" { } else if user_input == "2" {
// Printing prompt // Printing prompt
println!("\nWhat should the new description be?"); println!("\nWhat should the new description be?");
println!("Select description:"); println!("Select description [{}desc{}]:", COLOR_OPTION, COLOR_RESET);
// Reset input // Reset input
user_input = String::new(); user_input = String::new();
@ -221,7 +228,7 @@ impl<'a> Interface<'a> {
}); });
// Printing out the title // Printing out the title
println!(" - Delete {} - ", title); println!(" - {1}Delete {0}{2} - ", title, COLOR_TITLE, COLOR_RESET);
// Active board // Active board
let _active: &board::TaskBoard = &self.manager.boards[self.on as usize]; let _active: &board::TaskBoard = &self.manager.boards[self.on as usize];
@ -230,11 +237,11 @@ impl<'a> Interface<'a> {
if self.mode == 0 { if self.mode == 0 {
// Presenting all cards // Presenting all cards
for i in 0.._active.cards.len() { for i in 0.._active.cards.len() {
println!("{}) {}", i+1, _active.cards[i].name); println!("{2}{0}{4}) {3}{1}{4}", i+1, _active.cards[i].name, COLOR_OPTION, COLOR_CARD, COLOR_RESET);
} }
// Displaying prompt // Displaying prompt
println!("\nSelect option [1-{}]: ", _active.cards.len()); println!("\nSelect option [{1}1{2}-{1}{0}{2}]: ", _active.cards.len(), COLOR_OPTION, COLOR_RESET);
// Getting user input // Getting user input
let mut user_input: String = String::new(); let mut user_input: String = String::new();
@ -248,7 +255,7 @@ impl<'a> Interface<'a> {
user_input = String::new(); user_input = String::new();
// Confirming // Confirming
println!("\nAre you sure?\nSelect option [y/n]: "); println!("\nAre you sure?\nSelect option [{0}y{1}/{0}n{1}]: ", COLOR_OPTION, COLOR_RESET);
io::stdin().read_line(&mut user_input).expect("Failed to read line"); io::stdin().read_line(&mut user_input).expect("Failed to read line");
user_input = String::from(user_input.to_lowercase().trim()); user_input = String::from(user_input.to_lowercase().trim());
println!(""); println!("");
@ -267,7 +274,7 @@ impl<'a> Interface<'a> {
} else if self.mode == 1 { } else if self.mode == 1 {
// Confirming // Confirming
let mut user_input: String = String::new(); let mut user_input: String = String::new();
println!("\nAre you sure?\nSelect option [y/n]: "); println!("\nAre you sure?\nSelect option [{0}y{1}/{0}n{1}]: ", COLOR_OPTION, COLOR_RESET);
io::stdin().read_line(&mut user_input).expect("Failed to read line"); io::stdin().read_line(&mut user_input).expect("Failed to read line");
user_input = String::from(user_input.to_lowercase().trim()); user_input = String::from(user_input.to_lowercase().trim());
println!(""); println!("");
@ -288,14 +295,14 @@ impl<'a> Interface<'a> {
} }
fn p_6(&mut self){ fn p_6(&mut self){
// Title // Title
println!(" - Create Board - \n"); println!(" - {}Create Board{} - \n", COLOR_TITLE, COLOR_RESET);
// Variables // Variables
let mut user_input: String = String::new(); let mut user_input: String = String::new();
// Asking the user what the name is // Asking the user what the name is
println!("What is your boards's name?"); println!("What is your boards's name?");
println!("Select name: "); println!("Select name [{}name{}]: ", COLOR_OPTION, COLOR_RESET);
// Reading input // Reading input
io::stdin().read_line(&mut user_input).expect("Failed to read line"); io::stdin().read_line(&mut user_input).expect("Failed to read line");