diff options
Diffstat (limited to 'src/interactive')
-rw-r--r-- | src/interactive/app/eventloop.rs | 9 | ||||
-rw-r--r-- | src/interactive/app/handlers.rs | 9 | ||||
-rw-r--r-- | src/interactive/app_test.rs | 10 | ||||
-rw-r--r-- | src/interactive/widgets/entries.rs | 22 | ||||
-rw-r--r-- | src/interactive/widgets/help.rs | 2 |
5 files changed, 28 insertions, 24 deletions
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs index c89113e..b209009 100644 --- a/src/interactive/app/eventloop.rs +++ b/src/interactive/app/eventloop.rs @@ -8,7 +8,7 @@ use dua::{ WalkOptions, WalkResult, }; use failure::Error; -use std::{io, path::PathBuf}; +use std::{collections::BTreeMap, io, path::PathBuf}; use termion::input::{Keys, TermReadEventsAndRaw}; use tui::backend::Backend; use tui_react::Terminal; @@ -25,9 +25,8 @@ impl Default for FocussedPane { } } -pub struct EntryMark { - pub index: TreeIndex, -} +pub type EntryMarkMap = BTreeMap<TreeIndex, EntryMark>; +pub struct EntryMark {} #[derive(Default)] pub struct AppState { @@ -37,7 +36,7 @@ pub struct AppState { pub sorting: SortMode, pub message: Option<String>, pub focussed: FocussedPane, - pub marked: Vec<EntryMark>, + pub marked: EntryMarkMap, } /// State and methods representing the interactive disk usage analyser for the terminal diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs index af5a3b2..ad96e3f 100644 --- a/src/interactive/app/handlers.rs +++ b/src/interactive/app/handlers.rs @@ -123,12 +123,11 @@ impl TerminalApp { pub fn mark_entry(&mut self, advance_cursor: bool) { if let Some(index) = self.state.selected { - if let Some((existing, _)) = - self.state.marked.iter().find_position(|e| e.index == index) - { - self.state.marked.remove(existing); + // TODO: consider using the Entry::Occupied/Vacant API to remove things + if self.state.marked.get(&index).is_some() { + self.state.marked.remove(&index); } else { - self.state.marked.push(EntryMark { index }); + self.state.marked.insert(index, EntryMark {}); } if advance_cursor { self.change_entry_selection(CursorDirection::Down) diff --git a/src/interactive/app_test.rs b/src/interactive/app_test.rs index a321719..fb413e6 100644 --- a/src/interactive/app_test.rs +++ b/src/interactive/app_test.rs @@ -225,9 +225,8 @@ fn simple_user_journey() -> Result<(), Error> { app.process_events(&mut terminal, b"d".keys())?; { assert_eq!(1, app.state.marked.len(), "it marks only a single node",); - assert_eq!( - node_by_index(&app, previously_selected_index), - node_by_index(&app, app.state.marked[0].index), + assert!( + app.state.marked.contains_key(&previously_selected_index), "it marks the selected node" ); assert_eq!( @@ -264,9 +263,8 @@ fn simple_user_journey() -> Result<(), Error> { "it toggled the previous selected entry off", ); - assert_eq!( - node_by_index(&app, previously_selected_index), - node_by_index(&app, app.state.marked[0].index), + assert!( + app.state.marked.contains_key(&previously_selected_index), "it leaves the first selected entry marked" ); } diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs index f364110..5f793a0 100644 --- a/src/interactive/widgets/entries.rs +++ b/src/interactive/widgets/entries.rs @@ -1,4 +1,4 @@ -use crate::interactive::{DisplayOptions, EntryDataBundle, EntryMark}; +use crate::interactive::{DisplayOptions, EntryDataBundle, EntryMarkMap}; use dua::traverse::{Tree, TreeIndex}; use itertools::Itertools; use std::{borrow::Borrow, path::Path}; @@ -16,7 +16,7 @@ pub struct EntriesProps<'a> { pub display: DisplayOptions, pub selected: Option<TreeIndex>, pub entries: &'a [EntryDataBundle], - pub marked: &'a [EntryMark], + pub marked: &'a EntryMarkMap, pub border_style: Style, pub is_focussed: bool, } @@ -39,7 +39,7 @@ impl Entries { display, entries, selected, - marked: _, + marked, border_style, is_focussed, } = props.borrow(); @@ -131,6 +131,7 @@ impl Entries { style, ); + let dark_yellow = Color::Rgb(176, 126, 0); let name = Text::Styled( fill_background_to_right( format!( @@ -142,11 +143,16 @@ impl Entries { ) .into(), Style { - fg: match (!is_dir, exists) { - (true, true) if !is_selected => Color::DarkGray, - (true, true) => style.fg, - (_, false) => Color::Red, - (false, true) => style.fg, + fg: match (!is_dir, exists, marked.contains_key(node_idx)) { + (true, true, false) if !is_selected => Color::DarkGray, + (true, true, false) => style.fg, + (false, true, false) => style.fg, + + (true, true, true) => dark_yellow, + (false, true, true) => Color::Yellow, + + // non-existing - always red! + (_, false, _) => Color::Red, }, ..style }, diff --git a/src/interactive/widgets/help.rs b/src/interactive/widgets/help.rs index aad6f93..bb39448 100644 --- a/src/interactive/widgets/help.rs +++ b/src/interactive/widgets/help.rs @@ -88,6 +88,8 @@ impl ToplevelComponent for HelpPane { title("Keys for entry operations"); { hotkey("Shift + o", "Open the entry with the associated program"); + hotkey("d", "Toggle the currently selected entry and move down"); + hotkey("<space bar>", "Toggle the currently selected entry"); spacer(); } title("Keys for application control"); |