git_revise/revise/prompts/
commit_edit.rs

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
use inquire::{
    ui::{Color, RenderConfig, Styled},
    Editor,
};

use super::Inquire;
use crate::error::ReviseResult;

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

impl Part {
    pub fn new(commit: String) -> Self {
        Self {
            msg: "You really want to edit this commit manually?".to_string(),
            ans: None,
            commit,
            fg: Color::LightRed,
        }
    }
}

impl Inquire for Part {
    fn inquire(&mut self) -> ReviseResult<()> {
        let ans = Editor::new("")
            .with_predefined_text(&self.commit)
            .with_render_config(RenderConfig::default().with_prompt_prefix(
                Styled::new(self.msg.as_str()).with_fg(self.fg),
            ))
            .prompt()?;
        self.ans = Some(ans);
        Ok(())
    }
}