git_revise/revise/prompts/
commit_breaking.rs

1use inquire::{
2    ui::{Color, RenderConfig, Styled},
3    Editor,
4};
5
6use super::Inquire;
7use crate::error::ReviseResult;
8
9#[derive(Debug, Clone)]
10pub struct Part {
11    pub msg: String,
12    pub ans: Option<String>,
13    pub fg: Color,
14}
15
16impl Part {
17    pub fn new() -> Self {
18        Self {
19            msg: "List any BREAKING CHANGES (optional):".to_string(),
20            ans: None,
21            fg: Color::DarkYellow,
22        }
23    }
24}
25
26impl Default for Part {
27    fn default() -> Self {
28        Self::new()
29    }
30}
31
32impl Inquire for Part {
33    fn inquire(&mut self) -> ReviseResult<()> {
34        let ans = Editor::new(&self.msg)
35            .with_formatter(&|submission| {
36                let char_count = submission.chars().count();
37                if char_count == 0 {
38                    "<skipped>".to_string()
39                } else if char_count <= 20 {
40                    submission.into()
41                } else {
42                    format!("{}...", &submission[..17])
43                }
44            })
45            .with_render_config(
46                RenderConfig::default().with_canceled_prompt_indicator(
47                    Styled::new("<skipped>").with_fg(self.fg),
48                ),
49            )
50            .prompt()?;
51
52        match &*ans {
53            "<skipped>" | "" => {}
54            _ => {
55                self.ans = Some(ans);
56            }
57        }
58
59        Ok(())
60    }
61}