git_revise/revise/prompts/
commit_body.rs1use 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: "Provide a LONGER description of the change (optional):"
20 .to_string(),
21 ans: None,
22 fg: Color::DarkYellow,
23 }
24 }
25}
26
27impl Default for Part {
28 fn default() -> Self {
29 Self::new()
30 }
31}
32
33impl Inquire for Part {
34 fn inquire(&mut self) -> ReviseResult<()> {
35 let ans = Editor::new(&self.msg)
36 .with_formatter(&|submission| {
37 let char_count = submission.chars().count();
38 if char_count == 0 {
39 "<skipped>".to_string()
40 } else if char_count <= 20 {
41 submission.into()
42 } else {
43 format!("{}...", &submission[..17])
44 }
45 })
46 .with_render_config(
47 RenderConfig::default().with_canceled_prompt_indicator(
48 Styled::new("<skipped>").with_fg(self.fg),
49 ),
50 )
51 .prompt()?;
52
53 match &*ans {
54 "<skipped>" | "" => {}
55 _ => {
56 self.ans = Some(ans);
57 }
58 }
59
60 Ok(())
61 }
62}