@@ -15,17 +15,18 @@ use default_editor;
15
15
use emoji_commit_type:: CommitType ;
16
16
use log_update:: LogUpdate ;
17
17
use structopt:: StructOpt ;
18
+ use ansi_term:: Colour :: { RGB , Green , Red , White } ;
18
19
19
20
mod commit_rules;
20
21
mod git;
21
22
22
- static PASS : & ' static str = "\u{001b} [32m✔\u{001b} [39m" ;
23
- static FAIL : & ' static str = "\u{001b} [31m✖\u{001b} [39m" ;
24
- static CURSOR : & ' static str = "\u{001b} [4m \u{001b} [24m" ;
25
-
26
23
impl fmt:: Display for commit_rules:: CommitRuleValidationResult {
27
24
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
28
- write ! ( f, "{} {}" , if self . pass { PASS } else { FAIL } , self . description)
25
+ write ! ( f, "{} {}" , if self . pass {
26
+ Green . paint( "✔" )
27
+ } else {
28
+ Red . paint( "✖" )
29
+ } , self . description)
29
30
}
30
31
}
31
32
@@ -73,7 +74,7 @@ fn select_emoji() -> Option<&'static str> {
73
74
if aborted { None } else { Some ( selected. emoji ( ) ) }
74
75
}
75
76
76
- fn collect_commit_message ( selected_emoji : & ' static str ) -> Option < String > {
77
+ fn collect_commit_message ( selected_emoji : & ' static str , launch_editor : & mut bool ) -> Option < String > {
77
78
let mut log_update = LogUpdate :: new ( stderr ( ) ) . unwrap ( ) ;
78
79
let mut raw_output = stderr ( ) . into_raw_mode ( ) . unwrap ( ) ;
79
80
@@ -88,11 +89,12 @@ fn collect_commit_message(selected_emoji: &'static str) -> Option<String> {
88
89
. collect :: < Vec < _ > > ( )
89
90
. join ( "\r \n " ) ;
90
91
let text = format ! (
91
- "\r \n Remember the seven rules of a great Git commit message:\r \n \r \n {}\r \n \r \n {} {}{}" ,
92
+ "\r \n Remember the seven rules of a great Git commit message:\r \n \r \n {}\r \n \r \n {}\r \n {} {}{}" ,
92
93
rule_text,
94
+ RGB ( 105 , 105 , 105 ) . paint( "Enter - finish, Ctrl-C - abort, Ctrl-E - continue editing in $EDITOR" ) ,
93
95
selected_emoji,
94
96
input,
95
- CURSOR ,
97
+ White . underline ( ) . paint ( " " )
96
98
) ;
97
99
98
100
log_update. render ( & text) . unwrap ( ) ;
@@ -102,6 +104,7 @@ fn collect_commit_message(selected_emoji: &'static str) -> Option<String> {
102
104
Key :: Char ( '\n' ) => break ,
103
105
Key :: Char ( c) => input. push ( c) ,
104
106
Key :: Backspace => { input. pop ( ) ; } ,
107
+ Key :: Ctrl ( 'e' ) => { * launch_editor = true ; break } ,
105
108
_ => { } ,
106
109
}
107
110
}
@@ -149,7 +152,8 @@ fn collect_information_and_write_to_file(out_path: PathBuf) {
149
152
}
150
153
151
154
if let Some ( emoji) = maybe_emoji {
152
- let maybe_message = collect_commit_message ( emoji) ;
155
+ let mut launch_editor = false ;
156
+ let maybe_message = collect_commit_message ( emoji, & mut launch_editor) ;
153
157
154
158
if maybe_message == None {
155
159
abort ( ) ;
@@ -158,8 +162,13 @@ fn collect_information_and_write_to_file(out_path: PathBuf) {
158
162
if let Some ( message) = maybe_message {
159
163
let result = format ! ( "{} {}\n " , emoji, message) ;
160
164
161
- let mut f = File :: create ( out_path) . unwrap ( ) ;
165
+ let mut f = File :: create ( out_path. clone ( ) ) . unwrap ( ) ;
162
166
f. write_all ( result. as_bytes ( ) ) . unwrap ( ) ;
167
+ drop ( f) ;
168
+
169
+ if launch_editor {
170
+ launch_default_editor ( out_path) ;
171
+ }
163
172
}
164
173
}
165
174
}
0 commit comments