1
1
use cidr:: Ipv4Cidr ;
2
2
use color_eyre:: eyre:: Result ;
3
+ use color_eyre:: owo_colors:: OwoColorize ;
3
4
use dns_lookup:: { lookup_addr, lookup_host} ;
4
5
use futures:: future:: join_all;
5
6
@@ -105,12 +106,10 @@ impl Discovery {
105
106
let active_interface = self . active_interface . clone ( ) . unwrap ( ) ;
106
107
107
108
let ipv4 = active_interface
108
- . clone ( )
109
109
. ips
110
110
. iter ( )
111
111
. find ( |f| f. is_ipv4 ( ) )
112
- . unwrap ( )
113
- . clone ( ) ;
112
+ . unwrap ( ) ;
114
113
let source_ip: Ipv4Addr = ipv4. ip ( ) . to_string ( ) . parse ( ) . unwrap ( ) ;
115
114
116
115
let ( mut sender, _) = match pnet:: datalink:: channel ( & active_interface, Default :: default ( ) ) {
@@ -278,7 +277,9 @@ impl Discovery {
278
277
}
279
278
280
279
fn set_scrollbar_height ( & mut self ) {
281
- self . scrollbar_state . content_length ( self . scanned_ips . len ( ) - 1 ) ;
280
+ self . scrollbar_state = self
281
+ . scrollbar_state
282
+ . content_length ( self . scanned_ips . len ( ) - 1 ) ;
282
283
}
283
284
284
285
fn previous_in_table ( & mut self ) {
@@ -293,7 +294,7 @@ impl Discovery {
293
294
None => 0 ,
294
295
} ;
295
296
self . table_state . select ( Some ( index) ) ;
296
- // self.
297
+ self . scrollbar_state = self . scrollbar_state . position ( index ) ;
297
298
}
298
299
299
300
fn next_in_table ( & mut self ) {
@@ -308,7 +309,7 @@ impl Discovery {
308
309
None => 0 ,
309
310
} ;
310
311
self . table_state . select ( Some ( index) ) ;
311
- // self.
312
+ self . scrollbar_state = self . scrollbar_state . position ( index ) ;
312
313
}
313
314
314
315
fn make_table ( scanned_ips : Vec < ScannedIp > , ip_num : i32 ) -> Table < ' static > {
@@ -357,20 +358,34 @@ impl Discovery {
357
358
. position ( ratatui:: widgets:: block:: Position :: Top )
358
359
. alignment ( Alignment :: Left ) ,
359
360
)
361
+ . title (
362
+ ratatui:: widgets:: block:: Title :: from ( Line :: from ( vec ! [
363
+ Span :: styled( "|" , Style :: default ( ) . fg( Color :: Yellow ) ) ,
364
+ String :: from( char :: from_u32( 0x25b2 ) . unwrap_or( '>' ) ) . red( ) ,
365
+ String :: from( char :: from_u32( 0x25bc ) . unwrap_or( '>' ) ) . red( ) ,
366
+ Span :: styled( "Select|" , Style :: default ( ) . fg( Color :: Yellow ) ) ,
367
+ ] ) )
368
+ . position ( ratatui:: widgets:: block:: Position :: Bottom )
369
+ . alignment ( Alignment :: Right ) ,
370
+ )
360
371
. border_style ( Style :: default ( ) . fg ( Color :: Rgb ( 100 , 100 , 100 ) ) )
361
- . borders ( Borders :: ALL )
362
- . padding ( Padding :: new ( 1 , 0 , 2 , 0 ) ) ,
372
+ . borders ( Borders :: ALL ) , // .padding(Padding::new(1, 0, 2, 0)),
363
373
)
364
374
. highlight_symbol ( String :: from ( char:: from_u32 ( 0x25b7 ) . unwrap_or ( '>' ) ) . red ( ) )
365
375
. column_spacing ( 1 ) ;
366
376
table
367
377
}
368
378
369
- fn make_scrollbar ( & mut self ) -> Scrollbar {
379
+ pub fn make_scrollbar < ' a > ( ) -> Scrollbar < ' a > {
380
+ // let s_start = String::from(char::from_u32(0x25b2).unwrap_or('#'));
381
+ // let s_end = String::from(char::from_u32(0x25bc).unwrap_or('#'));
370
382
let scrollbar = Scrollbar :: default ( )
371
383
. orientation ( ScrollbarOrientation :: VerticalRight )
384
+ . style ( Style :: default ( ) . fg ( Color :: Rgb ( 100 , 100 , 100 ) ) )
372
385
. begin_symbol ( None )
373
386
. end_symbol ( None ) ;
387
+ // .begin_symbol(Some(s_start))
388
+ // .end_symbol(Some(s_end));
374
389
scrollbar
375
390
}
376
391
@@ -421,7 +436,7 @@ impl Discovery {
421
436
422
437
impl Component for Discovery {
423
438
fn init ( & mut self , area : Rect ) -> Result < ( ) > {
424
- if self . cidr == None {
439
+ if self . cidr . is_none ( ) {
425
440
let cidr_range = "192.168.1.0/24" ;
426
441
self . set_cidr ( String :: from ( cidr_range) , false ) ;
427
442
}
@@ -480,7 +495,7 @@ impl Component for Discovery {
480
495
if let Action :: ActiveInterface ( ref interface) = action {
481
496
let intf = interface. clone ( ) ;
482
497
// -- first time scan after setting of interface
483
- if self . active_interface == None {
498
+ if self . active_interface . is_none ( ) {
484
499
self . scan ( ) ;
485
500
}
486
501
self . active_interface = Some ( intf) ;
@@ -518,7 +533,18 @@ impl Component for Discovery {
518
533
f. render_stateful_widget ( table, table_rect, & mut self . table_state . clone ( ) ) ;
519
534
520
535
// -- SCROLLBAR
521
- // let scrollbar = self.make_scrollbar();
536
+ let scrollbar = Self :: make_scrollbar ( ) ;
537
+ let mut scroll_rect = table_rect;
538
+ scroll_rect. y += 3 ;
539
+ scroll_rect. height -= 3 ;
540
+ f. render_stateful_widget (
541
+ scrollbar,
542
+ scroll_rect. inner ( & Margin {
543
+ vertical : 1 ,
544
+ horizontal : 1 ,
545
+ } ) ,
546
+ & mut self . scrollbar_state ,
547
+ ) ;
522
548
523
549
// -- ERROR
524
550
if self . cidr_error {
0 commit comments