1
1
const ITEM_HEIGHT : usize = 6 ;
2
2
const INFO_TEXT : [ & str ; 1 ] = [ "(Esc|q) quit | (↑) move up | (↓) move down" ] ;
3
3
4
- use crate :: balancer:: upstream_peer:: UpstreamPeer ;
5
- use crate :: balancer:: upstream_peer_pool:: UpstreamPeerPool ;
6
- use crate :: errors:: result:: Result ;
7
4
use chrono:: { DateTime , Utc } ;
8
5
use io:: Result as ioResult;
9
- use ratatui:: layout:: { Constraint , Layout , Margin , Rect } ;
10
- use ratatui:: style:: { Modifier , Style , Stylize } ;
11
- use ratatui:: text:: Text ;
12
- use ratatui:: widgets:: {
13
- Block , BorderType , Cell , HighlightSpacing , Paragraph , Row , Scrollbar , ScrollbarOrientation ,
14
- ScrollbarState , Table , TableState ,
6
+ use ratatui:: {
7
+ layout:: { Constraint , Layout , Margin , Rect } ,
8
+ style:: { Modifier , Style , Stylize } ,
9
+ text:: Text ,
10
+ widgets:: {
11
+ Cell , HighlightSpacing , Paragraph , Row , Scrollbar , ScrollbarOrientation ,
12
+ ScrollbarState , Table , TableState ,
13
+ } ,
14
+ Frame ,
15
15
} ;
16
- use ratatui:: Frame ;
17
16
use std:: {
18
17
io,
19
18
time:: { SystemTime , UNIX_EPOCH } ,
20
19
} ;
21
20
22
21
use super :: ui:: TableColors ;
23
22
23
+ use crate :: {
24
+ balancer:: {
25
+ upstream_peer:: UpstreamPeer ,
26
+ upstream_peer_pool:: UpstreamPeerPool ,
27
+ } ,
28
+ errors:: result:: Result ,
29
+ } ;
30
+
24
31
pub struct App {
25
32
pub colors : TableColors ,
26
33
pub is_initial_load : bool ,
27
34
pub items : Option < Vec < UpstreamPeer > > ,
28
- pub longest_item_lens : ( u16 , u16 , u16 , u16 , u16 , u16 ) ,
29
35
pub scroll_state : ScrollbarState ,
30
36
pub state : TableState ,
31
37
pub ticks : u128 ,
@@ -38,7 +44,6 @@ impl App {
38
44
colors : TableColors :: new ( ) ,
39
45
is_initial_load : true ,
40
46
items : None ,
41
- longest_item_lens : ( 0 , 0 , 0 , 0 , 0 , 0 ) ,
42
47
scroll_state : ScrollbarState :: new ( 0 ) ,
43
48
state : TableState :: default ( ) . with_selected ( 0 ) ,
44
49
ticks : 0 ,
@@ -93,8 +98,8 @@ impl App {
93
98
pub fn draw ( & mut self , frame : & mut Frame ) -> ioResult < ( ) > {
94
99
let vertical = & Layout :: vertical ( [
95
100
Constraint :: Min ( 5 ) ,
96
- Constraint :: Length ( 3 ) ,
97
- Constraint :: Length ( 3 ) ,
101
+ Constraint :: Length ( 1 ) ,
102
+ Constraint :: Length ( 1 ) ,
98
103
] ) ;
99
104
let rects = vertical. split ( frame. area ( ) ) ;
100
105
@@ -116,12 +121,7 @@ impl App {
116
121
. bg ( self . colors . buffer_bg )
117
122
. white ( ) ,
118
123
)
119
- . centered ( )
120
- . block (
121
- Block :: bordered ( )
122
- . border_type ( BorderType :: Double )
123
- . border_style ( Style :: new ( ) . fg ( self . colors . footer_border_color ) ) ,
124
- ) ;
124
+ . centered ( ) ;
125
125
frame. render_widget ( info_footer, area) ;
126
126
}
127
127
@@ -133,7 +133,7 @@ impl App {
133
133
134
134
frame. render_widget ( t, area) ;
135
135
} else {
136
- match self . items . clone ( ) {
136
+ match & self . items {
137
137
Some ( items) => match items. is_empty ( ) {
138
138
true => {
139
139
let t = Paragraph :: new ( "There are no agents registered. If agents are running, please give them a few seconds to register." . to_string ( ) . white ( ) )
@@ -177,35 +177,22 @@ impl App {
177
177
items
178
178
. into_iter ( )
179
179
. map ( |content| {
180
- Cell :: from ( Text :: from ( format ! ( " \n { content} \n " ) ) . white ( ) )
180
+ Cell :: from ( Text :: from ( content) . white ( ) )
181
181
} )
182
182
. collect :: < Row > ( )
183
183
. style ( Style :: new ( ) . fg ( self . colors . row_fg ) . bg ( color) )
184
- . height ( 4 )
184
+ . height ( 1 )
185
185
} ) ;
186
186
187
- self . longest_item_lens = constraint_len_calculator ( items. clone ( ) )
188
- . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: Other , e. to_string ( ) ) ) ?;
189
-
190
187
let bar = " █ " ;
191
188
let t = Table :: new (
192
189
rows,
193
- [
194
- Constraint :: Min ( self . longest_item_lens . 0 ) ,
195
- Constraint :: Min ( self . longest_item_lens . 1 ) ,
196
- Constraint :: Min ( self . longest_item_lens . 2 ) ,
197
- Constraint :: Min ( self . longest_item_lens . 3 ) ,
198
- Constraint :: Min ( self . longest_item_lens . 4 ) ,
199
- Constraint :: Min ( self . longest_item_lens . 5 ) ,
200
- ] ,
190
+ [ Constraint :: Ratio ( 1 , 6 ) ; 6 ] ,
201
191
)
202
192
. header ( header)
203
193
. row_highlight_style ( selected_row_style)
204
194
. highlight_symbol ( Text :: from ( vec ! [
205
- "" . into( ) ,
206
- bar. into( ) ,
207
195
bar. into( ) ,
208
- "" . into( ) ,
209
196
] ) )
210
197
. bg ( self . colors . buffer_bg )
211
198
. highlight_spacing ( HighlightSpacing :: Always )
@@ -254,12 +241,7 @@ impl App {
254
241
. bg ( self . colors . buffer_bg )
255
242
. white ( ) ,
256
243
)
257
- . centered ( )
258
- . block (
259
- Block :: bordered ( )
260
- . border_type ( BorderType :: Double )
261
- . border_style ( Style :: new ( ) . fg ( self . colors . footer_border_color ) ) ,
262
- ) ;
244
+ . centered ( ) ;
263
245
frame. render_widget ( info_footer, area) ;
264
246
}
265
247
@@ -278,64 +260,6 @@ impl App {
278
260
}
279
261
}
280
262
281
- fn constraint_len_calculator ( items : Vec < UpstreamPeer > ) -> Result < ( u16 , u16 , u16 , u16 , u16 , u16 ) > {
282
- let mut name = 0 ;
283
- for item in & items {
284
- if let Some ( agent_name) = item. agent_name . clone ( ) {
285
- if agent_name. len ( ) > name {
286
- name += agent_name. len ( )
287
- }
288
- }
289
- }
290
-
291
- let mut error = 0 ;
292
- for item in & items {
293
- if let Some ( agent_error) = item. error . clone ( ) {
294
- if agent_error. len ( ) > error {
295
- error += agent_error. len ( )
296
- }
297
- }
298
- }
299
-
300
- let mut addr = 0 ;
301
- for item in & items {
302
- if item. external_llamacpp_addr . to_string ( ) . len ( ) > addr {
303
- addr += item. external_llamacpp_addr . to_string ( ) . len ( )
304
- }
305
- }
306
-
307
- let mut slots_idle = 0 ;
308
- for item in & items {
309
- if item. slots_idle . to_string ( ) . len ( ) > slots_idle {
310
- slots_idle += item. slots_idle . to_string ( ) . len ( )
311
- }
312
- }
313
-
314
- let mut slots_processing = 0 ;
315
- for item in & items {
316
- if item. slots_processing . to_string ( ) . len ( ) > slots_processing {
317
- slots_processing += item. slots_processing . to_string ( ) . len ( )
318
- }
319
- }
320
-
321
- let mut last_update = 0 ;
322
- for item in & items {
323
- if systemtime_strftime ( item. last_update ) ?. len ( ) > last_update {
324
- last_update += systemtime_strftime ( item. last_update ) ?. len ( )
325
- }
326
- }
327
-
328
- #[ allow( clippy:: cast_possible_truncation) ]
329
- Ok ( (
330
- name as u16 ,
331
- error as u16 ,
332
- addr as u16 ,
333
- last_update as u16 ,
334
- slots_idle as u16 ,
335
- slots_processing as u16 ,
336
- ) )
337
- }
338
-
339
263
fn ref_array ( peer : UpstreamPeer ) -> Result < [ String ; 6 ] > {
340
264
let has_issue = match peer. error . clone ( ) {
341
265
Some ( issue) => issue,
0 commit comments