Skip to content

Commit 66a1db7

Browse files
committed
Fix helps
1 parent d7f15c3 commit 66a1db7

1 file changed

Lines changed: 83 additions & 16 deletions

File tree

src/view/table.rs

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ enum FilterState {
5656

5757
struct TableViewHelps {
5858
table: Vec<Spans>,
59+
table_filtered: Vec<Spans>,
5960
attr: Vec<Spans>,
6061
table_short: Vec<SpansWithPriority>,
62+
table_filtered_short: Vec<SpansWithPriority>,
6163
attr_short: Vec<SpansWithPriority>,
6264
}
6365

@@ -271,25 +273,33 @@ impl TableView {
271273
if self.attr_expanded {
272274
&self.helps.attr_short
273275
} else {
274-
&self.helps.table_short
276+
match self.filter_state {
277+
FilterState::None => &self.helps.table_short,
278+
FilterState::Filtering | FilterState::Filtered => &self.helps.table_filtered_short,
279+
}
275280
}
276281
}
277282
}
278283

279284
impl TableViewHelps {
280285
fn new(mapper: &UserEventMapper, theme: ColorTheme) -> TableViewHelps {
281-
let (table_helps, attr_helps) = build_helps(mapper, theme);
282-
let (table_short_helps, attr_short_helps) = build_short_helps(mapper);
286+
let (table, table_filtered, attr) = build_helps(mapper, theme);
287+
let (table_short, table_filtered_short, attr_short) = build_short_helps(mapper);
283288
TableViewHelps {
284-
table: table_helps,
285-
attr: attr_helps,
286-
table_short: table_short_helps,
287-
attr_short: attr_short_helps,
289+
table,
290+
table_filtered,
291+
attr,
292+
table_short,
293+
table_filtered_short,
294+
attr_short,
288295
}
289296
}
290297
}
291298

292-
fn build_helps(mapper: &UserEventMapper, theme: ColorTheme) -> (Vec<Spans>, Vec<Spans>) {
299+
fn build_helps(
300+
mapper: &UserEventMapper,
301+
theme: ColorTheme,
302+
) -> (Vec<Spans>, Vec<Spans>, Vec<Spans>) {
293303
#[rustfmt::skip]
294304
let table_helps = vec![
295305
BuildHelpsItem::new(UserEvent::Quit, "Quit app"),
@@ -305,6 +315,30 @@ fn build_helps(mapper: &UserEventMapper, theme: ColorTheme) -> (Vec<Spans>, Vec<
305315
BuildHelpsItem::new(UserEvent::GoToLeft, "Select first column"),
306316
BuildHelpsItem::new(UserEvent::GoToRight, "Select last column"),
307317
BuildHelpsItem::new(UserEvent::Confirm, "Open selected item"),
318+
BuildHelpsItem::new(UserEvent::QuickFilter, "Filter items"),
319+
BuildHelpsItem::new(UserEvent::Expand, "Expand selected attribute"),
320+
BuildHelpsItem::new(UserEvent::Insight, "Open table insight"),
321+
BuildHelpsItem::new(UserEvent::Widen, "Widen selected column"),
322+
BuildHelpsItem::new(UserEvent::Narrow, "Narrow selected column"),
323+
BuildHelpsItem::new(UserEvent::Reload, "Reload table data"),
324+
BuildHelpsItem::new(UserEvent::CopyToClipboard, "Copy selected item"),
325+
];
326+
#[rustfmt::skip]
327+
let table_filtered_helps = vec![
328+
BuildHelpsItem::new(UserEvent::Quit, "Quit app"),
329+
BuildHelpsItem::new(UserEvent::Close, "Back to table list"),
330+
BuildHelpsItem::new(UserEvent::Down, "Select next row"),
331+
BuildHelpsItem::new(UserEvent::Up, "Select previous row"),
332+
BuildHelpsItem::new(UserEvent::Right, "Select next column"),
333+
BuildHelpsItem::new(UserEvent::Left, "Select previous column"),
334+
BuildHelpsItem::new(UserEvent::PageDown, "Select next page"),
335+
BuildHelpsItem::new(UserEvent::PageUp, "Select previous page"),
336+
BuildHelpsItem::new(UserEvent::GoToTop, "Select first row"),
337+
BuildHelpsItem::new(UserEvent::GoToBottom, "Select last row"),
338+
BuildHelpsItem::new(UserEvent::GoToLeft, "Select first column"),
339+
BuildHelpsItem::new(UserEvent::GoToRight, "Select last column"),
340+
BuildHelpsItem::new(UserEvent::Confirm, "Open selected item"),
341+
BuildHelpsItem::new(UserEvent::Reset, "Clear filter"),
308342
BuildHelpsItem::new(UserEvent::Expand, "Expand selected attribute"),
309343
BuildHelpsItem::new(UserEvent::Insight, "Open table insight"),
310344
BuildHelpsItem::new(UserEvent::Widen, "Widen selected column"),
@@ -331,24 +365,48 @@ fn build_helps(mapper: &UserEventMapper, theme: ColorTheme) -> (Vec<Spans>, Vec<
331365
];
332366
(
333367
build_help_spans(table_helps, mapper, theme),
368+
build_help_spans(table_filtered_helps, mapper, theme),
334369
build_help_spans(attr_helps, mapper, theme),
335370
)
336371
}
337372

338-
fn build_short_helps(mapper: &UserEventMapper) -> (Vec<SpansWithPriority>, Vec<SpansWithPriority>) {
373+
fn build_short_helps(
374+
mapper: &UserEventMapper,
375+
) -> (
376+
Vec<SpansWithPriority>,
377+
Vec<SpansWithPriority>,
378+
Vec<SpansWithPriority>,
379+
) {
339380
#[rustfmt::skip]
340381
let table_helps = vec![
341382
BuildShortHelpsItem::single(UserEvent::Quit, "Quit", 0),
342383
BuildShortHelpsItem::single(UserEvent::Close, "Back", 1),
343-
BuildShortHelpsItem::group(vec![UserEvent::Down, UserEvent::Up], "Select row", 5),
344-
BuildShortHelpsItem::group(vec![UserEvent::Left, UserEvent::Right], "Select col", 6),
345-
BuildShortHelpsItem::group(vec![UserEvent::GoToTop, UserEvent::GoToBottom], "Top/Bottom", 10),
384+
BuildShortHelpsItem::group(vec![UserEvent::Down, UserEvent::Up], "Select row", 6),
385+
BuildShortHelpsItem::group(vec![UserEvent::Left, UserEvent::Right], "Select col", 7),
386+
BuildShortHelpsItem::group(vec![UserEvent::GoToTop, UserEvent::GoToBottom], "Top/Bottom", 11),
346387
BuildShortHelpsItem::single(UserEvent::Confirm, "Open", 2),
388+
BuildShortHelpsItem::single(UserEvent::QuickFilter, "Filter", 5),
347389
BuildShortHelpsItem::single(UserEvent::Expand, "Expand", 4),
348390
BuildShortHelpsItem::single(UserEvent::Insight, "Insight", 3),
349-
BuildShortHelpsItem::single(UserEvent::CopyToClipboard, "Copy", 7),
350-
BuildShortHelpsItem::group(vec![UserEvent::Widen, UserEvent::Narrow], "Widen/Narrow", 9),
351-
BuildShortHelpsItem::single(UserEvent::Reload, "Reload", 8),
391+
BuildShortHelpsItem::single(UserEvent::CopyToClipboard, "Copy", 8),
392+
BuildShortHelpsItem::group(vec![UserEvent::Widen, UserEvent::Narrow], "Widen/Narrow", 10),
393+
BuildShortHelpsItem::single(UserEvent::Reload, "Reload", 9),
394+
BuildShortHelpsItem::single(UserEvent::Help, "Help", 0),
395+
];
396+
#[rustfmt::skip]
397+
let table_filtered_helps = vec![
398+
BuildShortHelpsItem::single(UserEvent::Quit, "Quit", 0),
399+
BuildShortHelpsItem::single(UserEvent::Close, "Back", 1),
400+
BuildShortHelpsItem::group(vec![UserEvent::Down, UserEvent::Up], "Select row", 6),
401+
BuildShortHelpsItem::group(vec![UserEvent::Left, UserEvent::Right], "Select col", 7),
402+
BuildShortHelpsItem::group(vec![UserEvent::GoToTop, UserEvent::GoToBottom], "Top/Bottom", 11),
403+
BuildShortHelpsItem::single(UserEvent::Confirm, "Open", 2),
404+
BuildShortHelpsItem::single(UserEvent::Reset, "Clear filter", 5),
405+
BuildShortHelpsItem::single(UserEvent::Expand, "Expand", 4),
406+
BuildShortHelpsItem::single(UserEvent::Insight, "Insight", 3),
407+
BuildShortHelpsItem::single(UserEvent::CopyToClipboard, "Copy", 8),
408+
BuildShortHelpsItem::group(vec![UserEvent::Widen, UserEvent::Narrow], "Widen/Narrow", 10),
409+
BuildShortHelpsItem::single(UserEvent::Reload, "Reload", 9),
352410
BuildShortHelpsItem::single(UserEvent::Help, "Help", 0),
353411
];
354412
#[rustfmt::skip]
@@ -364,6 +422,7 @@ fn build_short_helps(mapper: &UserEventMapper) -> (Vec<SpansWithPriority>, Vec<S
364422
];
365423
(
366424
build_short_help_spans(table_helps, mapper),
425+
build_short_help_spans(table_filtered_helps, mapper),
367426
build_short_help_spans(attr_helps, mapper),
368427
)
369428
}
@@ -565,7 +624,15 @@ impl TableView {
565624
if self.attr_expanded {
566625
self.tx.send(AppEvent::OpenHelp(self.helps.attr.clone()))
567626
} else {
568-
self.tx.send(AppEvent::OpenHelp(self.helps.table.clone()))
627+
match self.filter_state {
628+
FilterState::None => {
629+
self.tx.send(AppEvent::OpenHelp(self.helps.table.clone()));
630+
}
631+
FilterState::Filtering | FilterState::Filtered => {
632+
self.tx
633+
.send(AppEvent::OpenHelp(self.helps.table_filtered.clone()));
634+
}
635+
}
569636
}
570637
}
571638
}

0 commit comments

Comments
 (0)