File tree Expand file tree Collapse file tree 4 files changed +29
-10
lines changed
Expand file tree Collapse file tree 4 files changed +29
-10
lines changed Original file line number Diff line number Diff line change @@ -25,12 +25,14 @@ pub struct Connection {
2525}
2626
2727impl Connection {
28- pub fn push_status ( & mut self , code : Status ) {
28+ pub fn push_status ( & mut self , status : Status ) {
2929 if self . log . len ( ) == MAX_STATUSES {
3030 self . log . pop_back ( ) ;
3131 }
3232
33- self . log . push_front ( code) ;
33+ let status = status. id ( self . log . front ( ) . map ( |st| st. id . wrapping_add ( 1 ) ) . unwrap_or_default ( ) ) ;
34+
35+ self . log . push_front ( status) ;
3436 }
3537
3638 pub const fn log ( & self ) -> & VecDeque < Status > {
Original file line number Diff line number Diff line change @@ -9,14 +9,25 @@ pub struct Status {
99 code : Code ,
1010 msg : Option < String > ,
1111 time : Timestamp ,
12+ pub id : u32 ,
1213}
1314
1415impl Status {
15- pub fn new ( code : Code ) -> Self {
16+ pub fn new ( code : Code , id : u32 ) -> Self {
1617 Self {
1718 code,
1819 time : chrono:: Local :: now ( ) ,
1920 msg : None ,
21+ id,
22+ }
23+ }
24+
25+ pub fn id ( self , id : u32 ) -> Self {
26+ Self {
27+ id,
28+ msg : self . msg ,
29+ code : self . code ,
30+ time : self . time ,
2031 }
2132 }
2233
@@ -25,6 +36,7 @@ impl Status {
2536 msg : Some ( msg) ,
2637 code : self . code ,
2738 time : self . time ,
39+ id : self . id ,
2840 }
2941 }
3042
@@ -59,6 +71,6 @@ impl Status {
5971
6072impl From < Code > for Status {
6173 fn from ( value : Code ) -> Self {
62- Self :: new ( value)
74+ Self :: new ( value, 0 )
6375 }
6476}
Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ fn test_conn(conns: &Arc<Mutex<Vec<Connection>>>, idx: usize) {
182182 100
183183 } ;
184184
185- Status :: new ( Ok ( code) ) . set_msg ( val)
185+ Status :: new ( Ok ( code) , 0 ) . set_msg ( val)
186186 }
187187 Err ( e) => Err ( e. to_string ( ) ) . into ( ) ,
188188 }
Original file line number Diff line number Diff line change @@ -83,8 +83,7 @@ pub fn render_tab_log(f: &mut Frame, app: &App) {
8383 let log_txt: Vec < Line > = log_conn
8484 . log ( )
8585 . iter ( )
86- . enumerate ( )
87- . map ( |( j, status) | {
86+ . map ( |status| {
8887 let desc = match ( status. code ( ) , & log_conn. addr ) {
8988 ( Ok ( code) , Address :: Remote { .. } ) => code. to_string ( ) ,
9089 ( Ok ( _) , Address :: Json { .. } ) => status. msg ( ) . unwrap ( ) ,
@@ -109,9 +108,15 @@ pub fn render_tab_log(f: &mut Frame, app: &App) {
109108
110109 let guide = {
111110 let min_desc_len: usize = 16 ;
112-
113- let mid = if j > 0 && j. saturating_add ( 1 ) % 3 == 0 { "." } else { " " }
114- . repeat ( min_desc_len. saturating_sub ( desc. len ( ) ) ) ;
111+ let interval = 3 ;
112+ let id = status. id ;
113+
114+ let mid = if id > 0 && id. saturating_add ( 1 ) % interval == 0 {
115+ "."
116+ } else {
117+ " "
118+ }
119+ . repeat ( min_desc_len. saturating_sub ( desc. len ( ) ) ) ;
115120
116121 format ! ( " {mid} " )
117122 } ;
You can’t perform that action at this time.
0 commit comments