Added color formatting
This commit is contained in:
parent
a73c72fa93
commit
a33495d27f
1 changed files with 43 additions and 36 deletions
|
@ -2,6 +2,13 @@
|
|||
use crate::{board, card, manager};
|
||||
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
|
||||
pub struct Interface<'a> {
|
||||
manager: &'a mut manager::Manager,
|
||||
|
@ -21,11 +28,11 @@ impl<'a> Interface<'a> {
|
|||
|
||||
fn p_0(&mut self) {
|
||||
// Showing options
|
||||
println!(" - Tasky - ");
|
||||
println!("1) Open Board");
|
||||
println!("2) Create Board");
|
||||
println!("3) Exit");
|
||||
println!("\nSelect option [1-3]: ");
|
||||
println!(" - {}Tasky{} - ", COLOR_TITLE, COLOR_RESET);
|
||||
println!("{}1{}) Open Board", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}2{}) Create Board", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}3{}) Exit", COLOR_OPTION, COLOR_RESET);
|
||||
println!("\nSelect option [{0}1{1}-{0}3{1}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Listening for option
|
||||
let mut user_input: String = String::new();
|
||||
|
@ -44,11 +51,11 @@ impl<'a> Interface<'a> {
|
|||
}
|
||||
fn p_1(&mut self) {
|
||||
// Showing options
|
||||
println!(" - Open Board - ");
|
||||
println!(" - {}Open Board{} - ", COLOR_TITLE, COLOR_RESET);
|
||||
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
|
||||
|
@ -66,20 +73,20 @@ impl<'a> Interface<'a> {
|
|||
let board: &board::TaskBoard = &self.manager.boards[self.on as usize];
|
||||
|
||||
// Title
|
||||
println!(" - {} - \n", board.name);
|
||||
println!(" - {1}{0}{2} - \n", board.name, COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// Going through 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
|
||||
println!("\n1) Create Card");
|
||||
println!("2) Edit Card");
|
||||
println!("3) Delete Card");
|
||||
println!("4) Delete Board");
|
||||
println!("5) Exit");
|
||||
println!("\nSelect Option [1-5]: ");
|
||||
println!("\n{}1{}) Create Card", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}2{}) Edit Card", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}3{}) Delete Card", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}4{}) Delete Board", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}5{}) Exit", COLOR_OPTION, COLOR_RESET);
|
||||
println!("\nSelect Option [{0}1{1}-{0}5{1}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Selection option
|
||||
let mut user_input: String = String::new();
|
||||
|
@ -104,14 +111,14 @@ impl<'a> Interface<'a> {
|
|||
}
|
||||
fn p_3(&mut self){
|
||||
// Title
|
||||
println!(" - Create Card - \n");
|
||||
println!(" - {}Create Card{} - \n", COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// Variables
|
||||
let mut user_input: String = String::new();
|
||||
|
||||
// Asking the user what the name is
|
||||
println!("What is your card's name?");
|
||||
println!("Select name: ");
|
||||
println!("Select name [{}name{}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reading input
|
||||
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
|
||||
println!("Give your card a description!");
|
||||
println!("Select description: ");
|
||||
println!("Select description [{}desc{}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reading input
|
||||
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){
|
||||
// Title
|
||||
println!(" - Edit Card - \n");
|
||||
println!(" - {}Edit Card{} - \n", COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// Getting active board
|
||||
let _active: &mut board::TaskBoard = &mut self.manager.boards[self.on as usize];
|
||||
|
||||
// Showing all cards
|
||||
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
|
||||
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
|
||||
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];
|
||||
|
||||
// Printing options
|
||||
println!(" - {} - ", _card.name);
|
||||
println!("1) Change Name");
|
||||
println!("2) Change Description");
|
||||
println!("3) Exit");
|
||||
println!("\nSelect option [1-3]: ");
|
||||
println!(" - {1}{0}{2} - ", _card.name, COLOR_CARD, COLOR_RESET);
|
||||
println!("{}1{}) Change Name", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}2{}) Change Description", COLOR_OPTION, COLOR_RESET);
|
||||
println!("{}3{}) Exit", COLOR_OPTION, COLOR_RESET);
|
||||
println!("\nSelect option [{0}1{1}-{0}3{1}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reset input
|
||||
user_input = String::new();
|
||||
|
@ -182,7 +189,7 @@ impl<'a> Interface<'a> {
|
|||
if user_input == "1" {
|
||||
// Printing prompt
|
||||
println!("\nWhat should the new name be?");
|
||||
println!("Select name:");
|
||||
println!("Select name [{}name{}]:", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reset input
|
||||
user_input = String::new();
|
||||
|
@ -196,7 +203,7 @@ impl<'a> Interface<'a> {
|
|||
} else if user_input == "2" {
|
||||
// Printing prompt
|
||||
println!("\nWhat should the new description be?");
|
||||
println!("Select description:");
|
||||
println!("Select description [{}desc{}]:", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reset input
|
||||
user_input = String::new();
|
||||
|
@ -221,7 +228,7 @@ impl<'a> Interface<'a> {
|
|||
});
|
||||
|
||||
// Printing out the title
|
||||
println!(" - Delete {} - ", title);
|
||||
println!(" - {1}Delete {0}{2} - ", title, COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// Active board
|
||||
let _active: &board::TaskBoard = &self.manager.boards[self.on as usize];
|
||||
|
@ -230,11 +237,11 @@ impl<'a> Interface<'a> {
|
|||
if self.mode == 0 {
|
||||
// Presenting all cards
|
||||
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
|
||||
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
|
||||
let mut user_input: String = String::new();
|
||||
|
@ -248,7 +255,7 @@ impl<'a> Interface<'a> {
|
|||
user_input = String::new();
|
||||
|
||||
// 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");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
println!("");
|
||||
|
@ -267,7 +274,7 @@ impl<'a> Interface<'a> {
|
|||
} else if self.mode == 1 {
|
||||
// Confirming
|
||||
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");
|
||||
user_input = String::from(user_input.to_lowercase().trim());
|
||||
println!("");
|
||||
|
@ -288,14 +295,14 @@ impl<'a> Interface<'a> {
|
|||
}
|
||||
fn p_6(&mut self){
|
||||
// Title
|
||||
println!(" - Create Board - \n");
|
||||
println!(" - {}Create Board{} - \n", COLOR_TITLE, COLOR_RESET);
|
||||
|
||||
// Variables
|
||||
let mut user_input: String = String::new();
|
||||
|
||||
// Asking the user what the name is
|
||||
println!("What is your boards's name?");
|
||||
println!("Select name: ");
|
||||
println!("Select name [{}name{}]: ", COLOR_OPTION, COLOR_RESET);
|
||||
|
||||
// Reading input
|
||||
io::stdin().read_line(&mut user_input).expect("Failed to read line");
|
||||
|
|
Loading…
Reference in a new issue