From e67e36b23af38436ecc9b6200c3f8c9e9ce0636b Mon Sep 17 00:00:00 2001 From: nyx Date: Tue, 1 Oct 2024 22:46:00 -0400 Subject: [PATCH] implement some changes proposed by adam Co-authored-by: Adam Perkowski --- tui/src/hint.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tui/src/hint.rs b/tui/src/hint.rs index 331d3359..b5f096ca 100644 --- a/tui/src/hint.rs +++ b/tui/src/hint.rs @@ -42,16 +42,17 @@ pub fn create_shortcut_list( let mut lines: Vec> = Vec::new(); for row in 0..rows { - let mut row_spans = Vec::new(); - for col in 0..columns { - let index = row * columns + col; - if index < shortcut_spans.len() { - let mut span = shortcut_spans[index].clone(); - let padding = max_shortcut_width - span_vec_len(&span); - span.push(Span::raw(" ".repeat(padding))); - row_spans.push(span); - } - } + let row_spans: Vec<_> = (0..columns) + .filter_map(|col| { + let index = row * columns + col; + shortcut_spans.get(index).map(|span| { + let padding = max_shortcut_width - span_vec_len(span); + let mut span_clone = span.clone(); + span_clone.push(Span::raw(" ".repeat(padding))); + span_clone + }) + }) + .collect(); lines.push(add_spacing(row_spans)); }