@@ -153,6 +153,24 @@ impl TaskTable {
153
153
self . scroll . select ( Some ( i) ) ;
154
154
}
155
155
156
+ pub fn selected ( & self ) -> Option < & str > {
157
+ let i = self . scroll . selected ( ) ?;
158
+ if i < self . finished . len ( ) {
159
+ let task = self . finished . get ( i) ?;
160
+ Some ( task. name ( ) )
161
+ } else if i < self . finished . len ( ) + self . running . len ( ) {
162
+ let task = self . running . get ( i - self . finished . len ( ) ) ?;
163
+ Some ( task. name ( ) )
164
+ } else if i < self . finished . len ( ) + self . running . len ( ) + self . planned . len ( ) {
165
+ let task = self
166
+ . planned
167
+ . get ( i - ( self . finished . len ( ) + self . running . len ( ) ) ) ?;
168
+ Some ( task. name ( ) )
169
+ } else {
170
+ None
171
+ }
172
+ }
173
+
156
174
fn finished_rows ( & self , duration_width : u16 ) -> impl Iterator < Item = Row > + ' _ {
157
175
self . finished . iter ( ) . map ( move |task| {
158
176
Row :: new ( vec ! [
@@ -288,12 +306,16 @@ mod test {
288
306
table. next ( ) ;
289
307
table. next ( ) ;
290
308
assert_eq ! ( table. scroll. selected( ) , Some ( 1 ) , "selected b" ) ;
309
+ assert_eq ! ( table. selected( ) , Some ( "b" ) , "selected b" ) ;
291
310
table. start_task ( "b" ) . unwrap ( ) ;
292
311
assert_eq ! ( table. scroll. selected( ) , Some ( 0 ) , "b stays selected" ) ;
312
+ assert_eq ! ( table. selected( ) , Some ( "b" ) , "selected b" ) ;
293
313
table. start_task ( "a" ) . unwrap ( ) ;
294
314
assert_eq ! ( table. scroll. selected( ) , Some ( 0 ) , "b stays selected" ) ;
315
+ assert_eq ! ( table. selected( ) , Some ( "b" ) , "selected b" ) ;
295
316
table. finish_task ( "a" ) . unwrap ( ) ;
296
317
assert_eq ! ( table. scroll. selected( ) , Some ( 1 ) , "b stays selected" ) ;
318
+ assert_eq ! ( table. selected( ) , Some ( "b" ) , "selected b" ) ;
297
319
}
298
320
299
321
#[ test]
@@ -302,22 +324,28 @@ mod test {
302
324
table. next ( ) ;
303
325
table. next ( ) ;
304
326
assert_eq ! ( table. scroll. selected( ) , Some ( 1 ) , "selected b" ) ;
327
+ assert_eq ! ( table. selected( ) , Some ( "b" ) , "selected b" ) ;
305
328
// start c which moves it to "running" which is before "planned"
306
329
table. start_task ( "c" ) . unwrap ( ) ;
307
330
assert_eq ! ( table. scroll. selected( ) , Some ( 2 ) , "selection stays on b" ) ;
331
+ assert_eq ! ( table. selected( ) , Some ( "b" ) , "selected b" ) ;
308
332
table. start_task ( "a" ) . unwrap ( ) ;
309
333
assert_eq ! ( table. scroll. selected( ) , Some ( 2 ) , "selection stays on b" ) ;
334
+ assert_eq ! ( table. selected( ) , Some ( "b" ) , "selected b" ) ;
310
335
// c
311
336
// a
312
337
// b <-
313
338
table. previous ( ) ;
314
339
table. previous ( ) ;
315
340
assert_eq ! ( table. scroll. selected( ) , Some ( 0 ) , "selected c" ) ;
341
+ assert_eq ! ( table. selected( ) , Some ( "c" ) , "selected c" ) ;
316
342
table. finish_task ( "a" ) . unwrap ( ) ;
317
343
assert_eq ! ( table. scroll. selected( ) , Some ( 1 ) , "c stays selected" ) ;
344
+ assert_eq ! ( table. selected( ) , Some ( "c" ) , "selected c" ) ;
318
345
table. previous ( ) ;
319
346
table. finish_task ( "c" ) . unwrap ( ) ;
320
347
assert_eq ! ( table. scroll. selected( ) , Some ( 0 ) , "a stays selected" ) ;
348
+ assert_eq ! ( table. selected( ) , Some ( "a" ) , "selected a" ) ;
321
349
}
322
350
323
351
#[ test]
0 commit comments