@@ -19,6 +19,7 @@ pub struct HostSection {
19
19
pub actions : Vec < ActionSection > ,
20
20
pub scroll : u16 ,
21
21
pub success : Option < bool > ,
22
+ pub start_failed : Option < String > ,
22
23
}
23
24
24
25
impl HostSection {
@@ -42,6 +43,19 @@ impl HostSection {
42
43
43
44
let mut y = 0 ;
44
45
46
+ if let Some ( reason) = & self . start_failed {
47
+ render_line (
48
+ area,
49
+ buf,
50
+ & mut y,
51
+ self . scroll ,
52
+ & format ! ( "host start failed: {reason}" ) ,
53
+ Some ( Color :: Red ) ,
54
+ None ,
55
+ ) ;
56
+ y += 1 ;
57
+ }
58
+
45
59
for action in & self . actions {
46
60
action. render ( area, buf, & mut y, self . scroll ) ;
47
61
y += 1 ;
@@ -106,8 +120,14 @@ impl RunPanel {
106
120
}
107
121
}
108
122
123
+ fn get_active_host ( & self ) -> Result < & HostSection > {
124
+ let active = self . active . min ( self . hosts . len ( ) . saturating_sub ( 1 ) ) ;
125
+ let host = self . hosts . get ( active) . ok_or_else ( || anyhow ! ( "no host" ) ) ?;
126
+ Ok ( host)
127
+ }
128
+
109
129
pub fn render ( & self , area : Rect , buf : & mut Buffer ) {
110
- if let Some ( host) = self . hosts . first ( ) {
130
+ if let Ok ( host) = self . get_active_host ( ) {
111
131
host. render ( area, buf) ;
112
132
}
113
133
}
@@ -146,6 +166,7 @@ impl HostSection {
146
166
actions,
147
167
scroll : 0 ,
148
168
success : None ,
169
+ start_failed : None ,
149
170
}
150
171
}
151
172
}
@@ -172,7 +193,7 @@ impl ActionSection {
172
193
} else {
173
194
Color :: Gray
174
195
} ;
175
- self . render_line ( area, buf, y, scroll, & self . name , None , Some ( bg) ) ;
196
+ render_line ( area, buf, y, scroll, & self . name , None , Some ( bg) ) ;
176
197
* y += 1 ;
177
198
if self . folded {
178
199
return ;
@@ -186,71 +207,70 @@ impl ActionSection {
186
207
ActionOutputLevel :: Warn => Some ( Color :: Yellow ) ,
187
208
ActionOutputLevel :: Error => Some ( Color :: Red ) ,
188
209
} ;
189
- self . render_line ( area, buf, y, scroll, & line. content , fg, None ) ;
210
+ render_line ( area, buf, y, scroll, & line. content , fg, None ) ;
190
211
if * y >= area. height + scroll {
191
212
return ;
192
213
}
193
214
}
194
215
}
216
+ }
195
217
196
- #[ allow( clippy:: too_many_arguments) ]
197
- fn render_line (
198
- & self ,
199
- area : Rect ,
200
- buf : & mut Buffer ,
201
- y : & mut u16 ,
202
- scroll : u16 ,
203
- line : & str ,
204
- fg : Option < Color > ,
205
- bg : Option < Color > ,
206
- ) {
207
- let style = Style :: default ( ) ;
208
- let style = if let Some ( fg) = fg {
209
- style. fg ( fg)
210
- } else {
211
- style
212
- } ;
213
- let mut line_composer = WordWrapper :: new (
214
- vec ! [ (
215
- line. graphemes( true )
216
- . map( move |g| StyledGrapheme { symbol: g, style } ) ,
217
- Alignment :: Left ,
218
- ) ]
219
- . into_iter ( ) ,
220
- area. width ,
221
- false ,
222
- ) ;
218
+ #[ allow( clippy:: too_many_arguments) ]
219
+ fn render_line (
220
+ area : Rect ,
221
+ buf : & mut Buffer ,
222
+ y : & mut u16 ,
223
+ scroll : u16 ,
224
+ line : & str ,
225
+ fg : Option < Color > ,
226
+ bg : Option < Color > ,
227
+ ) {
228
+ let style = Style :: default ( ) ;
229
+ let style = if let Some ( fg) = fg {
230
+ style. fg ( fg)
231
+ } else {
232
+ style
233
+ } ;
234
+ let mut line_composer = WordWrapper :: new (
235
+ vec ! [ (
236
+ line. graphemes( true )
237
+ . map( move |g| StyledGrapheme { symbol: g, style } ) ,
238
+ Alignment :: Left ,
239
+ ) ]
240
+ . into_iter ( ) ,
241
+ area. width ,
242
+ false ,
243
+ ) ;
223
244
224
- while let Some ( WrappedLine {
225
- line : current_line,
226
- width : current_line_width,
227
- alignment : current_line_alignment,
228
- } ) = line_composer. next_line ( )
229
- {
230
- if * y >= scroll {
231
- if let Some ( bg) = bg {
232
- let area = Rect :: new ( area. left ( ) , area. top ( ) + * y - scroll, area. width , 1 ) ;
233
- buf. set_style ( area, Style :: default ( ) . bg ( bg) ) ;
234
- }
235
- let mut x = get_line_offset ( current_line_width, area. width , current_line_alignment) ;
236
- for StyledGrapheme { symbol, style } in current_line {
237
- let width = symbol. width ( ) ;
238
- if width == 0 {
239
- continue ;
240
- }
241
- // If the symbol is empty, the last char which rendered last time will
242
- // leave on the line. It's a quick fix.
243
- let symbol = if symbol. is_empty ( ) { " " } else { symbol } ;
244
- buf. get_mut ( area. left ( ) + x, area. top ( ) + * y - scroll)
245
- . set_symbol ( symbol)
246
- . set_style ( * style) ;
247
- x += width as u16 ;
248
- }
245
+ while let Some ( WrappedLine {
246
+ line : current_line,
247
+ width : current_line_width,
248
+ alignment : current_line_alignment,
249
+ } ) = line_composer. next_line ( )
250
+ {
251
+ if * y >= scroll {
252
+ if let Some ( bg) = bg {
253
+ let area = Rect :: new ( area. left ( ) , area. top ( ) + * y - scroll, area. width , 1 ) ;
254
+ buf. set_style ( area, Style :: default ( ) . bg ( bg) ) ;
249
255
}
250
- * y += 1 ;
251
- if * y >= area. height + scroll {
252
- break ;
256
+ let mut x = get_line_offset ( current_line_width, area. width , current_line_alignment) ;
257
+ for StyledGrapheme { symbol, style } in current_line {
258
+ let width = symbol. width ( ) ;
259
+ if width == 0 {
260
+ continue ;
261
+ }
262
+ // If the symbol is empty, the last char which rendered last time will
263
+ // leave on the line. It's a quick fix.
264
+ let symbol = if symbol. is_empty ( ) { " " } else { symbol } ;
265
+ buf. get_mut ( area. left ( ) + x, area. top ( ) + * y - scroll)
266
+ . set_symbol ( symbol)
267
+ . set_style ( * style) ;
268
+ x += width as u16 ;
253
269
}
254
270
}
271
+ * y += 1 ;
272
+ if * y >= area. height + scroll {
273
+ break ;
274
+ }
255
275
}
256
276
}
0 commit comments