@@ -2,21 +2,21 @@ use crate::file_watcher::FileWatcher;
22use crate :: sed:: debugger:: { Debugger , DebuggingState } ;
33use crate :: ui:: generic:: { ApplicationExitReason , UiAgent } ;
44use anyhow:: { Context , Result } ;
5- use crossterm:: event:: { self , Event , KeyCode , KeyEvent , MouseEvent , MouseEventKind } ;
6- use crossterm:: execute;
5+ use ratatui:: backend:: CrosstermBackend ;
6+ use ratatui:: crossterm:: event:: { self , Event , KeyCode , KeyEvent , MouseEvent , MouseEventKind } ;
7+ use ratatui:: crossterm:: execute;
8+ use ratatui:: layout:: { Constraint , Direction , Layout , Rect } ;
9+ use ratatui:: style:: { Color , Modifier , Style } ;
10+ use ratatui:: text:: { Line , Span } ;
11+ use ratatui:: widgets:: { Block , Borders , Paragraph , Wrap } ;
12+ use ratatui:: Frame ;
13+ use ratatui:: Terminal ;
714use std:: cmp:: { max, min} ;
815use std:: collections:: HashSet ;
916use std:: io;
1017use std:: sync:: mpsc;
1118use std:: thread;
1219use std:: time:: { Duration , Instant } ;
13- use tui:: backend:: CrosstermBackend ;
14- use tui:: layout:: { Constraint , Direction , Layout , Rect } ;
15- use tui:: style:: { Color , Modifier , Style } ;
16- use tui:: Frame ;
17- use tui:: text:: { Line , Span } ;
18- use tui:: widgets:: { Block , Borders , Paragraph , Wrap } ;
19- use tui:: Terminal ;
2020
2121pub struct Tui < ' a > {
2222 debugger : & ' a Debugger ,
@@ -49,13 +49,17 @@ impl<'a> Tui<'a> {
4949 #[ allow( unused_must_use) ]
5050 // NOTE: We don't care that some actions here fail (for example mouse handling),
5151 // as some features that we're trying to enable here are not necessary for desed.
52- pub fn new ( debugger : & ' a Debugger , file_watcher : FileWatcher , current_state : usize ) -> Result < Self > {
52+ pub fn new (
53+ debugger : & ' a Debugger ,
54+ file_watcher : FileWatcher ,
55+ current_state : usize ,
56+ ) -> Result < Self > {
5357 let mut stdout = io:: stdout ( ) ;
5458 execute ! ( stdout, event:: EnableMouseCapture ) ;
5559 let backend = CrosstermBackend :: new ( stdout) ;
5660 let mut terminal = Terminal :: new ( backend)
5761 . with_context ( || "Failed to initialize terminal with crossterm backend." ) ?;
58- crossterm:: terminal:: enable_raw_mode ( ) ?;
62+ ratatui :: crossterm:: terminal:: enable_raw_mode ( ) ?;
5963 terminal. hide_cursor ( ) ;
6064 Ok ( Tui {
6165 debugger,
@@ -65,7 +69,7 @@ impl<'a> Tui<'a> {
6569 cursor : 0 ,
6670 forced_refresh_rate : 200 ,
6771 pressed_keys_buffer : String :: new ( ) ,
68- current_state
72+ current_state,
6973 } )
7074 }
7175
@@ -246,9 +250,10 @@ impl<'a> Tui<'a> {
246250 ) ,
247251 if let Some ( source) = source_code. get( line_number) {
248252 Span :: raw( source)
249- } else { Span :: raw( "" ) }
253+ } else {
254+ Span :: raw( "" )
255+ } ,
250256 ] ) ) ;
251-
252257 } ;
253258 for number in display_start..source_code. len ( ) {
254259 add_new_line ( number) ;
@@ -279,9 +284,10 @@ impl<'a> Tui<'a> {
279284 for ( i, m) in regex_space. iter ( ) . enumerate ( ) {
280285 text. push ( Line :: from ( vec ! [
281286 Span :: styled(
282- format!( "\n \\ {} " , i) ,
283- Style :: default ( ) . fg( Color :: DarkGray ) ) ,
284- Span :: raw( m)
287+ format!( "\n \\ {} " , i) ,
288+ Style :: default ( ) . fg( Color :: DarkGray ) ,
289+ ) ,
290+ Span :: raw( m) ,
285291 ] ) ) ;
286292 }
287293 }
@@ -292,19 +298,16 @@ impl<'a> Tui<'a> {
292298 }
293299
294300 /// Draw simple text in area, wrapping, with light blue fg color. Do nothing else.
295- fn draw_text (
296- f : & mut Frame ,
297- heading : String ,
298- text_to_write : Option < & String > ,
299- area : Rect ,
300- ) {
301+ fn draw_text ( f : & mut Frame , heading : String , text_to_write : Option < & String > , area : Rect ) {
301302 let block = Block :: default ( ) . title ( heading) . borders ( Borders :: ALL ) ;
302303 let default_string = String :: new ( ) ;
303304 let text = [ Span :: styled (
304305 format ! ( "\n {}" , text_to_write. unwrap_or( & default_string) ) ,
305306 Style :: default ( ) . fg ( Color :: LightBlue ) ,
306307 ) ] ;
307- let paragraph = Paragraph :: new ( Line :: from ( text. to_vec ( ) ) ) . block ( block) . wrap ( Wrap { trim : false } ) ;
308+ let paragraph = Paragraph :: new ( Line :: from ( text. to_vec ( ) ) )
309+ . block ( block)
310+ . wrap ( Wrap { trim : false } ) ;
308311 f. render_widget ( paragraph, area) ;
309312 }
310313
@@ -321,7 +324,7 @@ impl<'a> Tui<'a> {
321324 execute ! ( stdout, event:: DisableMouseCapture ) ;
322325
323326 // Disable raw mode that messes up with user's terminal
324- crossterm:: terminal:: disable_raw_mode ( ) ;
327+ ratatui :: crossterm:: terminal:: disable_raw_mode ( ) ;
325328 let backend = CrosstermBackend :: new ( stdout) ;
326329 let mut terminal = Terminal :: new ( backend) ?;
327330
@@ -366,7 +369,9 @@ impl<'a> UiAgent for Tui<'a> {
366369 }
367370 }
368371 }
369- if file_watcher. any_events ( ) . ok ( ) . unwrap_or ( false ) && tx. send ( Interrupt :: FileChanged ) . is_err ( ) {
372+ if file_watcher. any_events ( ) . ok ( ) . unwrap_or ( false )
373+ && tx. send ( Interrupt :: FileChanged ) . is_err ( )
374+ {
370375 return ;
371376 }
372377 if last_tick. elapsed ( ) > tick_rate {
@@ -482,22 +487,34 @@ impl<'a> UiAgent for Tui<'a> {
482487 self . pressed_keys_buffer . clear ( ) ;
483488 while self . current_state < debugger. count_of_states ( ) - 1 {
484489 self . current_state += 1 ;
485- if self . breakpoints . contains ( & self . debugger . peek_at_state ( self . current_state ) . unwrap ( ) . current_line ) {
490+ if self . breakpoints . contains (
491+ & self
492+ . debugger
493+ . peek_at_state ( self . current_state )
494+ . unwrap ( )
495+ . current_line ,
496+ ) {
486497 break ;
487498 }
488499 }
489- } ,
500+ }
490501 // Same as 'r', but backwards
491502 KeyCode :: Char ( 'R' ) => {
492503 use_execution_pointer_as_focus_line = true ;
493504 self . pressed_keys_buffer . clear ( ) ;
494505 while self . current_state > 0 {
495506 self . current_state -= 1 ;
496- if self . breakpoints . contains ( & self . debugger . peek_at_state ( self . current_state ) . unwrap ( ) . current_line ) {
507+ if self . breakpoints . contains (
508+ & self
509+ . debugger
510+ . peek_at_state ( self . current_state )
511+ . unwrap ( )
512+ . current_line ,
513+ ) {
497514 break ;
498515 }
499516 }
500- } ,
517+ }
501518 // Reload source code and try to enter current state again
502519 KeyCode :: Char ( 'l' ) => {
503520 return Ok ( ApplicationExitReason :: Reload ( self . current_state ) ) ;
@@ -518,7 +535,8 @@ impl<'a> UiAgent for Tui<'a> {
518535 Interrupt :: MouseEvent ( event) => match event. kind {
519536 // Button pressed, mark current line as breakpoint
520537 MouseEventKind :: Up ( _button) => {
521- let target_breakpoint = ( event. row - 1 ) as usize + draw_memory. current_startline ;
538+ let target_breakpoint =
539+ ( event. row - 1 ) as usize + draw_memory. current_startline ;
522540 if self . breakpoints . contains ( & target_breakpoint) {
523541 self . breakpoints . remove ( & target_breakpoint) ;
524542 } else {
0 commit comments