git_revise/revise/prompts/
commit_confirm.rs1use colored::Colorize;
2use inquire::CustomType;
3
4use super::Inquire;
5use crate::{
6 error::ReviseResult,
7 revise::{prompts::commit_edit, status::Status, template::Template},
8};
9
10#[derive(Debug, Clone)]
11pub struct Part {
12 pub msg: String,
13 pub ans: Option<String>,
14 pub template: Template,
15}
16
17impl Part {
18 pub fn new(template: Template) -> Self {
19 Self {
20 msg: "Provide a LONGER description of the change (optional):"
21 .to_string(),
22 ans: None,
23 template,
24 }
25 }
26}
27
28impl Inquire for Part {
29 fn inquire(&mut self) -> ReviseResult<()> {
30 let res_msg = format!(
31 "{}{}{}",
32 "\n###--------------------------------------------------------###\n\n"
33 .black()
34 .bold()
35 .italic(),
36 self.template.template(true),
37 "\n\n###--------------------------------------------------------###\n"
38 .black()
39 .bold()
40 .italic()
41 );
42 println!("{res_msg}");
43 let msg = "Are you sure you want to proceed with the commit above?";
44 let ans = CustomType::<Status>::new(msg)
45 .with_placeholder("y|n|e")
46 .with_help_message("y for yes, n for no, e for edit")
47 .with_error_message("Reply with 'y', 'n' or 'e'")
48 .prompt()?;
49
50 match ans {
51 Status::Edit => {
52 let mut cedit =
53 commit_edit::Part::new(self.template.to_string());
54 cedit.inquire().unwrap();
55 self.ans = cedit.ans;
56 }
57 _ => self.ans = Some(self.template.to_string()),
58 };
59 Ok(())
60 }
61}