1
- use std:: sync:: { Arc , Mutex } ;
1
+ use std:: sync:: { Arc , Mutex , RwLock } ;
2
2
3
3
use crossterm:: event:: { KeyCode , KeyEvent } ;
4
4
use ratatui:: {
@@ -26,7 +26,7 @@ use crate::{
26
26
27
27
#[ derive( Debug ) ]
28
28
pub struct Inspection {
29
- pub packets : Arc < Mutex < Vec < AppPacket > > > ,
29
+ pub packets : Arc < RwLock < Vec < AppPacket > > > ,
30
30
pub state : TableState ,
31
31
pub fuzzy : Arc < Mutex < Fuzzy > > ,
32
32
pub manuall_scroll : bool ,
@@ -36,7 +36,7 @@ pub struct Inspection {
36
36
}
37
37
38
38
impl Inspection {
39
- pub fn new ( packets : Arc < Mutex < Vec < AppPacket > > > ) -> Self {
39
+ pub fn new ( packets : Arc < RwLock < Vec < AppPacket > > > ) -> Self {
40
40
Self {
41
41
packets : packets. clone ( ) ,
42
42
state : TableState :: default ( ) ,
@@ -49,7 +49,7 @@ impl Inspection {
49
49
}
50
50
51
51
pub fn can_show_popup ( & mut self ) -> bool {
52
- let packets = self . packets . lock ( ) . unwrap ( ) ;
52
+ let packets = self . packets . read ( ) . unwrap ( ) ;
53
53
let fuzzy = self . fuzzy . lock ( ) . unwrap ( ) ;
54
54
55
55
if fuzzy. is_enabled ( ) {
@@ -134,7 +134,7 @@ impl Inspection {
134
134
}
135
135
136
136
KeyCode :: Char ( 's' ) => {
137
- let app_packets = self . packets . lock ( ) . unwrap ( ) ;
137
+ let app_packets = self . packets . read ( ) . unwrap ( ) ;
138
138
if app_packets. is_empty ( ) {
139
139
Notification :: send (
140
140
"There is no packets" . to_string ( ) ,
@@ -168,7 +168,7 @@ impl Inspection {
168
168
}
169
169
170
170
pub fn scroll_up ( & mut self ) {
171
- let app_packets = self . packets . lock ( ) . unwrap ( ) ;
171
+ let app_packets = self . packets . read ( ) . unwrap ( ) ;
172
172
if !self . manuall_scroll {
173
173
self . manuall_scroll = true ;
174
174
// Record the last position. Usefull for selecting the packets to display
@@ -193,7 +193,7 @@ impl Inspection {
193
193
}
194
194
195
195
pub fn scroll_down ( & mut self ) {
196
- let app_packets = self . packets . lock ( ) . unwrap ( ) ;
196
+ let app_packets = self . packets . read ( ) . unwrap ( ) ;
197
197
198
198
if !self . manuall_scroll {
199
199
self . manuall_scroll = true ;
@@ -220,7 +220,7 @@ impl Inspection {
220
220
}
221
221
222
222
pub fn render ( & mut self , frame : & mut Frame , block : Rect ) {
223
- let app_packets = self . packets . lock ( ) . unwrap ( ) ;
223
+ let app_packets = self . packets . read ( ) . unwrap ( ) ;
224
224
let mut fuzzy = self . fuzzy . lock ( ) . unwrap ( ) ;
225
225
let fuzzy_packets = fuzzy. clone ( ) . packets . clone ( ) ;
226
226
@@ -638,7 +638,7 @@ impl Inspection {
638
638
. split ( layout[ 1 ] ) [ 1 ] ;
639
639
640
640
let fuzzy = self . fuzzy . lock ( ) . unwrap ( ) ;
641
- let packets = self . packets . lock ( ) . unwrap ( ) ;
641
+ let packets = self . packets . read ( ) . unwrap ( ) ;
642
642
643
643
let app_packet = if fuzzy. is_enabled ( ) {
644
644
fuzzy. packets [ self . packet_index . unwrap ( ) ]
0 commit comments