From ed37b8ccc875a34ad91b9198ec6a24eb7fd4efa6 Mon Sep 17 00:00:00 2001 From: itsscb Date: Mon, 12 Aug 2024 15:08:47 +0200 Subject: [PATCH] feat: adds prompts --- src/ui/prompts.rs | 56 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/src/ui/prompts.rs b/src/ui/prompts.rs index 2119945..2eabb5a 100644 --- a/src/ui/prompts.rs +++ b/src/ui/prompts.rs @@ -1,41 +1,77 @@ -use crate::{models::{Epic, Story, Status}, io_utils::get_user_input}; +use crate::{ + io_utils::get_user_input, + models::{Epic, Status, Story}, +}; + +static DELIMITER: &str = "----------------------------"; pub struct Prompts { pub create_epic: Box Epic>, pub create_story: Box Story>, pub delete_epic: Box bool>, pub delete_story: Box bool>, - pub update_status: Box Option> + pub update_status: Box Option>, } impl Prompts { pub fn new() -> Self { - Self { + Self { create_epic: Box::new(create_epic_prompt), create_story: Box::new(create_story_prompt), delete_epic: Box::new(delete_epic_prompt), delete_story: Box::new(delete_story_prompt), - update_status: Box::new(update_status_prompt) + update_status: Box::new(update_status_prompt), } } } fn create_epic_prompt() -> Epic { - todo!(); + println!("{DELIMITER}"); + println!("Epic Name:"); + let name = get_user_input(); + println!("Epic Description:"); + let description = get_user_input(); + Epic::new(name, description) } fn create_story_prompt() -> Story { - todo!(); + println!("{DELIMITER}"); + println!("Story Name:"); + let name = get_user_input(); + println!("Story Description:"); + let description = get_user_input(); + Story::new(name, description) } fn delete_epic_prompt() -> bool { - todo!(); + static QUESTION: &str = "Are you sure you want to delete this epic? All stories in this epic will also be deleted [Y/n]:"; + println!("{DELIMITER}"); + print!("{QUESTION}"); + let decision = matches!(get_user_input().as_str(), "y" | "Y"); + println!(); + decision } fn delete_story_prompt() -> bool { - todo!(); + static QUESTION: &str = "Are you sure you want to delete this story? [Y/n]:"; + println!("{DELIMITER}"); + print!("{QUESTION}"); + let decision = matches!(get_user_input().as_str(), "y" | "Y"); + println!(); + decision } fn update_status_prompt() -> Option { - todo!(); -} \ No newline at end of file + static QUESTION: &str = "New Status (1 - OPEN, 2 - IN-PROGRESS, 3 - RESOLVED, 4 - CLOSED):"; + println!("{DELIMITER}"); + print!("{QUESTION}"); + let decision = match get_user_input().as_str() { + "1" => Some(Status::Open), + "2" => Some(Status::InProgress), + "3" => Some(Status::Resolved), + "4" => Some(Status::Closed), + _ => None, + }; + println!(); + decision +}