1
+ use crate :: input:: InputState ;
1
2
use crate :: {
2
3
accessors,
3
4
cmdbar:: CommandBar ,
@@ -18,6 +19,7 @@ use anyhow::{anyhow, Result};
18
19
use asyncgit:: { sync, AsyncNotification , CWD } ;
19
20
use crossbeam_channel:: Sender ;
20
21
use crossterm:: event:: { Event , KeyEvent } ;
22
+ use std:: cell:: Cell ;
21
23
use std:: { cell:: RefCell , rc:: Rc } ;
22
24
use strings:: { commands, order} ;
23
25
use tui:: {
@@ -28,6 +30,7 @@ use tui::{
28
30
widgets:: { Block , Borders , Tabs } ,
29
31
Frame ,
30
32
} ;
33
+
31
34
///
32
35
pub struct App {
33
36
do_quit : bool ,
@@ -45,6 +48,10 @@ pub struct App {
45
48
stashlist_tab : StashList ,
46
49
queue : Queue ,
47
50
theme : SharedTheme ,
51
+
52
+ // "Flags"
53
+ requires_redraw : Cell < bool > ,
54
+ set_polling : bool ,
48
55
}
49
56
50
57
// public interface
@@ -85,6 +92,8 @@ impl App {
85
92
stashlist_tab : StashList :: new ( & queue, theme. clone ( ) ) ,
86
93
queue,
87
94
theme,
95
+ requires_redraw : Cell :: new ( false ) ,
96
+ set_polling : true ,
88
97
}
89
98
}
90
99
@@ -182,6 +191,17 @@ impl App {
182
191
if flags. contains ( NeedsUpdate :: COMMANDS ) {
183
192
self . update_commands ( ) ;
184
193
}
194
+ } else if let InputEvent :: State ( polling_state) = ev {
195
+ if let InputState :: Paused = polling_state {
196
+ if let Err ( e) = self . commit . show_editor ( ) {
197
+ let msg =
198
+ format ! ( "failed to launch editor:\n {}" , e) ;
199
+ log:: error!( "{}" , msg. as_str( ) ) ;
200
+ self . msg . show_msg ( msg. as_str ( ) ) ?;
201
+ }
202
+ self . requires_redraw . set ( true ) ;
203
+ self . set_polling = true ;
204
+ }
185
205
}
186
206
187
207
Ok ( ( ) )
@@ -230,6 +250,21 @@ impl App {
230
250
|| self . stashing_tab . anything_pending ( )
231
251
|| self . inspect_commit_popup . any_work_pending ( )
232
252
}
253
+
254
+ ///
255
+ pub fn requires_redraw ( & self ) -> bool {
256
+ if self . requires_redraw . get ( ) {
257
+ self . requires_redraw . set ( false ) ;
258
+ true
259
+ } else {
260
+ false
261
+ }
262
+ }
263
+
264
+ ///
265
+ pub const fn set_polling ( & self ) -> bool {
266
+ self . set_polling
267
+ }
233
268
}
234
269
235
270
// private impls
@@ -314,6 +349,7 @@ impl App {
314
349
315
350
fn process_queue ( & mut self ) -> Result < NeedsUpdate > {
316
351
let mut flags = NeedsUpdate :: empty ( ) ;
352
+
317
353
loop {
318
354
let front = self . queue . borrow_mut ( ) . pop_front ( ) ;
319
355
if let Some ( e) = front {
@@ -369,6 +405,9 @@ impl App {
369
405
self . inspect_commit_popup . open ( id) ?;
370
406
flags. insert ( NeedsUpdate :: ALL | NeedsUpdate :: COMMANDS )
371
407
}
408
+ InternalEvent :: SuspendPolling => {
409
+ self . set_polling = false ;
410
+ }
372
411
} ;
373
412
374
413
Ok ( flags)
0 commit comments