@@ -553,12 +553,14 @@ pub fn render_static_analysis(state: &mut State, frame: &mut Frame, rect: Rect)
553
553
Row :: new ( items. iter ( ) . enumerate ( ) . map ( |( i, value) | {
554
554
Cell :: from ( Line :: from (
555
555
if value. width ( ) > max_row_width && i == items. len ( ) - 1 {
556
- vec ! [
556
+ let mut spans = highlight_search_result (
557
557
value. chars ( ) . take ( max_row_width) . collect :: < String > ( ) . into ( ) ,
558
- "…" . fg( Color :: Rgb ( 100 , 100 , 100 ) ) ,
559
- ]
558
+ state,
559
+ ) ;
560
+ spans. push ( "…" . fg ( Color :: Rgb ( 100 , 100 , 100 ) ) ) ;
561
+ spans
560
562
} else {
561
- vec ! [ value. to_string( ) . into( ) ]
563
+ highlight_search_result ( value. to_string ( ) . into ( ) , state )
562
564
} ,
563
565
) )
564
566
} ) )
@@ -676,24 +678,25 @@ pub fn render_strings(state: &mut State, frame: &mut Frame, rect: Rect) {
676
678
frame. render_stateful_widget (
677
679
Table :: new (
678
680
items. map ( |items| {
679
- Row :: new ( vec ! [ Cell :: from( Line :: from ( {
681
+ Row :: new ( vec ! [ Cell :: from( {
680
682
let index = format!( "{:>p$}" , items[ 0 ] , p = left_padding) ;
681
683
let value = items[ 1 ] . to_string( ) ;
682
- let mut line = vec![ index. clone( ) . cyan( ) , " " . into( ) ] ;
684
+ let mut spans = vec![ index. clone( ) . cyan( ) , " " . into( ) ] ;
683
685
if index. width( ) + value. width( ) > max_row_width {
684
- line . push (
686
+ spans . extend ( highlight_search_result (
685
687
value
686
688
. chars( )
687
689
. take( max_row_width. saturating_sub( index. width( ) ) )
688
690
. collect:: <String >( )
689
691
. into( ) ,
690
- ) ;
691
- line. push( "…" . fg( Color :: Rgb ( 100 , 100 , 100 ) ) ) ;
692
+ state,
693
+ ) ) ;
694
+ spans. push( "…" . fg( Color :: Rgb ( 100 , 100 , 100 ) ) ) ;
692
695
} else {
693
- line . push ( value. into( ) ) ;
696
+ spans . extend ( highlight_search_result ( value. into( ) , state ) )
694
697
}
695
- line
696
- } ) ) ] )
698
+ Line :: from ( spans )
699
+ } ) ] )
697
700
} ) ,
698
701
& [ Constraint :: Percentage ( 100 ) ] ,
699
702
)
@@ -728,7 +731,7 @@ pub fn render_strings(state: &mut State, frame: &mut Frame, rect: Rect) {
728
731
)
729
732
. title_bottom ( get_input_line ( state) ) ,
730
733
)
731
- . highlight_style ( Style :: default ( ) . add_modifier ( Modifier :: BOLD ) ) ,
734
+ . highlight_style ( Style :: default ( ) . fg ( Color :: Green ) . bold ( ) ) ,
732
735
rect,
733
736
& mut list_state,
734
737
) ;
@@ -856,26 +859,34 @@ pub fn render_dynamic_analysis(state: &mut State, frame: &mut Frame, rect: Rect)
856
859
}
857
860
858
861
frame. render_widget (
859
- Paragraph :: new ( state. analyzer . system_calls . clone ( ) )
860
- . block (
861
- Block :: bordered ( )
862
- . title ( vec ! [
862
+ Paragraph :: new (
863
+ state
864
+ . analyzer
865
+ . system_calls
866
+ . clone ( )
867
+ . into_iter ( )
868
+ . map ( |line| highlight_search_result ( line, state) . into ( ) )
869
+ . collect :: < Vec < Line > > ( ) ,
870
+ )
871
+ . block (
872
+ Block :: bordered ( )
873
+ . title ( vec ! [
874
+ "|" . fg( Color :: Rgb ( 100 , 100 , 100 ) ) ,
875
+ "System Calls" . white( ) . bold( ) ,
876
+ "|" . fg( Color :: Rgb ( 100 , 100 , 100 ) ) ,
877
+ ] )
878
+ . title_bottom (
879
+ Line :: from ( vec ! [
863
880
"|" . fg( Color :: Rgb ( 100 , 100 , 100 ) ) ,
864
- "System Calls" . white( ) . bold( ) ,
881
+ "Total: " . into( ) ,
882
+ state. analyzer. system_calls. len( ) . to_string( ) . white( ) . bold( ) ,
865
883
"|" . fg( Color :: Rgb ( 100 , 100 , 100 ) ) ,
866
884
] )
867
- . title_bottom (
868
- Line :: from ( vec ! [
869
- "|" . fg( Color :: Rgb ( 100 , 100 , 100 ) ) ,
870
- "Total: " . into( ) ,
871
- state. analyzer. system_calls. len( ) . to_string( ) . white( ) . bold( ) ,
872
- "|" . fg( Color :: Rgb ( 100 , 100 , 100 ) ) ,
873
- ] )
874
- . right_aligned ( ) ,
875
- )
876
- . title_bottom ( get_input_line ( state) ) ,
877
- )
878
- . scroll ( ( state. scroll_index as u16 , 0 ) ) ,
885
+ . right_aligned ( ) ,
886
+ )
887
+ . title_bottom ( get_input_line ( state) ) ,
888
+ )
889
+ . scroll ( ( state. scroll_index as u16 , 0 ) ) ,
879
890
rect,
880
891
) ;
881
892
@@ -925,3 +936,19 @@ fn get_input_line<'a>(state: &'a State) -> Line<'a> {
925
936
Line :: default ( )
926
937
}
927
938
}
939
+
940
+ /// Returns the line with the search result highlighted.
941
+ fn highlight_search_result < ' a > ( line : Line < ' a > , state : & ' a State ) -> Vec < Span < ' a > > {
942
+ let line_str = line. to_string ( ) ;
943
+ if line_str. contains ( state. input . value ( ) ) && !state. input . value ( ) . is_empty ( ) {
944
+ let splits = line_str. split ( state. input . value ( ) ) ;
945
+ let chunks = splits. into_iter ( ) . map ( |c| Span :: from ( c. to_owned ( ) ) ) ;
946
+ let pattern = Span :: styled (
947
+ state. input . value ( ) ,
948
+ Style :: new ( ) . bg ( Color :: Yellow ) . fg ( Color :: Black ) ,
949
+ ) ;
950
+ itertools:: intersperse ( chunks, pattern) . collect :: < Vec < Span > > ( )
951
+ } else {
952
+ line. spans . clone ( )
953
+ }
954
+ }
0 commit comments