1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use colored::Colorize;
use inquire::CustomType;

use super::Inquire;
use crate::{
    error::ReviseResult,
    revise::{prompts::commit_edit, status::Status, template::Template},
};

#[derive(Debug, Clone)]
pub struct Part {
    pub msg: String,
    pub ans: Option<String>,
    pub template: Template,
}

impl Part {
    pub fn new(template: Template) -> Self {
        Self {
            msg: "Provide a LONGER description of the change (optional):"
                .to_string(),
            ans: None,
            template,
        }
    }
}

// impl Default for Part {
//     fn default() -> Self {
//         Self::new()
//     }
// }

impl Inquire for Part {
    fn inquire(&mut self) -> ReviseResult<()> {
        let res_msg = format!(
            "{}{}{}",
            "\n###--------------------------------------------------------###\n\n"
            .black()
            .bold()
            .italic(),
            self.template.show(),
            "\n\n###--------------------------------------------------------###\n"
            .black()
            .bold()
            .italic()
        );
        println!("{res_msg}");
        let msg = "Are you sure you want to proceed with the commit above?";
        let ans = CustomType::<Status>::new(msg)
            .with_placeholder("y|n|e")
            .with_help_message("y for yes, n for no, e for edit")
            .with_error_message("Reply with 'y', 'n' or 'e'")
            .prompt()?;

        match ans {
            Status::Edit => {
                let mut cedit =
                    commit_edit::Part::new(self.template.to_string());
                cedit.inquire().unwrap();
                self.ans = cedit.ans;
            }
            // inquire_commit_edit(&self.template.to_string()),
            _ => self.ans = Some(self.template.to_string()),
        };
        Ok(())
    }
}