11use super :: {
22 textinput:: TextInputComponent , visibility_blocking,
33 CommandBlocking , CommandInfo , Component , DrawableComponent ,
4+ ExternalEditorComponent ,
45} ;
56use crate :: {
67 get_app_config_path, keys,
@@ -13,15 +14,10 @@ use asyncgit::{
1314 sync:: { self , CommitId , HookResult } ,
1415 CWD ,
1516} ;
16- use crossterm:: {
17- event:: Event ,
18- terminal:: { EnterAlternateScreen , LeaveAlternateScreen } ,
19- ExecutableCommand ,
20- } ;
21- use scopeguard:: defer;
17+ use crossterm:: event:: Event ;
2218use std:: {
2319 fs:: File ,
24- io:: { self , Read , Write } ,
20+ io:: { Read , Write } ,
2521 path:: PathBuf ,
2622} ;
2723use tui:: { backend:: Backend , layout:: Rect , Frame } ;
@@ -144,11 +140,11 @@ impl CommitComponent {
144140
145141 pub fn show_editor ( & mut self ) -> Result < ( ) > {
146142 const COMMIT_MSG_FILE_NAME : & str = "COMMITMSG_EDITOR" ;
143+ //TODO: use a tmpfile here
147144 let mut config_path: PathBuf = get_app_config_path ( ) ?;
148145 config_path. push ( COMMIT_MSG_FILE_NAME ) ;
149146
150147 {
151- //TODO: use a tmpfile here
152148 let mut file = File :: create ( & config_path) ?;
153149 file. write_fmt ( format_args ! (
154150 "{}\n " ,
@@ -157,16 +153,10 @@ impl CommitComponent {
157153 file. write_all ( strings:: COMMIT_EDITOR_MSG . as_bytes ( ) ) ?;
158154 }
159155
160- io:: stdout ( ) . execute ( LeaveAlternateScreen ) ?;
161- defer ! {
162- io:: stdout( ) . execute( EnterAlternateScreen ) . expect( "reset terminal" ) ;
163- }
164-
165- crate :: open_file_in_editor ( & config_path) ?;
156+ ExternalEditorComponent :: open_file_in_editor ( & config_path) ?;
166157
167158 let mut message = String :: new ( ) ;
168159
169- //TODO: see above
170160 let mut file = File :: open ( & config_path) ?;
171161 file. read_to_string ( & mut message) ?;
172162 drop ( file) ;
0 commit comments