git_revise/revise/prompts/
commit_issue.rs

1use inquire::Text;
2
3use super::Inquire;
4use crate::error::ReviseResult;
5
6#[derive(Debug, Clone)]
7pub struct Part {
8    pub msg: String,
9    pub ans: Option<String>,
10}
11
12impl Part {
13    pub fn new() -> Self {
14        Self {
15            msg: "List any ISSUES by this change. E.g.= #31, #34:".to_string(),
16            ans: None,
17        }
18    }
19}
20
21impl Default for Part {
22    fn default() -> Self {
23        Self::new()
24    }
25}
26
27impl Inquire for Part {
28    fn inquire(&mut self) -> ReviseResult<()> {
29        let ans = Text::new(&self.msg)
30            .with_formatter(&|submission| {
31                let char_count = submission.chars().count();
32                if char_count == 0 {
33                    "<skipped>".to_string()
34                } else if char_count <= 20 {
35                    submission.into()
36                } else {
37                    format!("{}...", &submission[..17])
38                }
39            })
40            .prompt()?;
41        match &*ans {
42            "<skipped>" | "" => {}
43            _ => self.ans = Some(ans),
44        };
45        Ok(())
46    }
47}