@@ -10,7 +10,7 @@ use human_bytes::human_bytes;
10
10
use itertools:: Itertools ;
11
11
use ratatui:: {
12
12
buffer:: Buffer ,
13
- layout:: { Constraint , Flex , Layout , Margin , Rect } ,
13
+ layout:: { Constraint , Flex , Layout , Margin , Position , Rect } ,
14
14
prelude:: CrosstermBackend ,
15
15
style:: { Color , Modifier , Style , Stylize } ,
16
16
symbols:: border,
@@ -140,6 +140,8 @@ enum AdminPrompt {
140
140
struct AdminState {
141
141
// Reference to the server for collecting data and interacting with user keys.
142
142
server : Arc < SandholeServer > ,
143
+ // Whether data should be rendered to the terminal.
144
+ enabled : bool ,
143
145
// Whether this is rendered in a pseudo-terminal or not.
144
146
is_pty : bool ,
145
147
// Currently selected tab.
@@ -568,6 +570,7 @@ impl AdminInterface {
568
570
terminal : Terminal :: with_options ( backend, options) . unwrap ( ) ,
569
571
state : AdminState {
570
572
server,
573
+ enabled : true ,
571
574
tab : TabData { tabs, current : 0 } ,
572
575
is_pty : false ,
573
576
table_state : Default :: default ( ) ,
@@ -582,14 +585,17 @@ impl AdminInterface {
582
585
{
583
586
let mut interface = interface. lock ( ) . unwrap ( ) ;
584
587
let AdminTerminal { terminal, state } = interface. deref_mut ( ) ;
585
- terminal
586
- . draw ( |frame| {
587
- // Render the terminal
588
- state. render ( frame. area ( ) , frame. buffer_mut ( ) ) ;
589
- // Update the cursor position (avoids cursor from disappearing on disconnect)
590
- frame. set_cursor_position ( ( 0 , 0 ) ) ;
591
- } )
592
- . unwrap ( ) ;
588
+ if state. enabled {
589
+ if terminal
590
+ . draw ( |frame| {
591
+ // Render the terminal
592
+ state. render ( frame. area ( ) , frame. buffer_mut ( ) ) ;
593
+ } )
594
+ . is_err ( )
595
+ {
596
+ break ;
597
+ }
598
+ }
593
599
}
594
600
// Wait one second or for an user-generated event to refresh the interface
595
601
tokio:: select! {
@@ -906,4 +912,13 @@ impl AdminInterface {
906
912
let _ = self . change_notifier . send ( ( ) ) ;
907
913
}
908
914
}
915
+
916
+ // Disable updates to the terminal for shutdown
917
+ pub ( crate ) fn disable ( & mut self ) {
918
+ let mut interface = self . interface . lock ( ) . unwrap ( ) ;
919
+ let _ = interface. terminal . show_cursor ( ) ;
920
+ let _ = interface. terminal . set_cursor_position ( Position :: ORIGIN ) ;
921
+ let _ = interface. terminal . flush ( ) ;
922
+ interface. state . enabled = false ;
923
+ }
909
924
}
0 commit comments