From 98359c4d8b5c4582b2902006ad1fbed724893b48 Mon Sep 17 00:00:00 2001 From: Remigiusz Micielski Date: Sat, 7 Sep 2024 12:39:19 +0200 Subject: [PATCH 1/5] fix: being stuck in filtering bar --- rm-main/src/tui/components/table.rs | 2 +- rm-main/src/tui/tabs/torrents/mod.rs | 2 +- rm-main/src/tui/tabs/torrents/table_manager.rs | 5 +++++ rm-main/src/tui/tabs/torrents/task_manager.rs | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/rm-main/src/tui/components/table.rs b/rm-main/src/tui/components/table.rs index 7917205..8db48f1 100644 --- a/rm-main/src/tui/components/table.rs +++ b/rm-main/src/tui/components/table.rs @@ -83,7 +83,7 @@ impl GenericTable { let new_selection = state.selected().unwrap_or_default() + amount; if new_selection > self.get_len() { - state.select(Some(self.get_len() - 1)); + state.select(Some(self.get_len().saturating_sub(1))); } else { state.select(Some(new_selection)); }; diff --git a/rm-main/src/tui/tabs/torrents/mod.rs b/rm-main/src/tui/tabs/torrents/mod.rs index a07abce..52e7930 100644 --- a/rm-main/src/tui/tabs/torrents/mod.rs +++ b/rm-main/src/tui/tabs/torrents/mod.rs @@ -226,7 +226,7 @@ impl Component for TorrentsTab { self.popup_manager.handle_update_action(action) } UpdateAction::CancelTorrentTask => { - if !self.task_manager.is_finished_status_task() { + if self.task_manager.is_status_task_in_progress() { return; } diff --git a/rm-main/src/tui/tabs/torrents/table_manager.rs b/rm-main/src/tui/tabs/torrents/table_manager.rs index 5845205..7f6ddd3 100644 --- a/rm-main/src/tui/tabs/torrents/table_manager.rs +++ b/rm-main/src/tui/tabs/torrents/table_manager.rs @@ -276,6 +276,11 @@ impl TableManager { self.widths = self.header_widths(&self.table.items); self.update_rows_number(); self.sort(); + + // let mut state = self.table.state.borrow_mut(); + // if state.selected().is_none() && !self.table.items.is_empty() { + // state.select(Some(0)); + // } } pub fn set_filter(&mut self, filter: String) { diff --git a/rm-main/src/tui/tabs/torrents/task_manager.rs b/rm-main/src/tui/tabs/torrents/task_manager.rs index 6eacca3..e11a515 100644 --- a/rm-main/src/tui/tabs/torrents/task_manager.rs +++ b/rm-main/src/tui/tabs/torrents/task_manager.rs @@ -206,9 +206,9 @@ impl TaskManager { self.ctx.send_update_action(UpdateAction::CancelTorrentTask); } - pub fn is_finished_status_task(&self) -> bool { + pub fn is_status_task_in_progress(&self) -> bool { if let CurrentTask::Status(task) = &self.current_task { - !matches!(task.task_status, CurrentTaskState::Loading(_)) + matches!(task.task_status, CurrentTaskState::Loading(_)) } else { false } From df96d4e49c92c96624a39b17909041747df196f2 Mon Sep 17 00:00:00 2001 From: Remigiusz Micielski Date: Sat, 7 Sep 2024 12:40:36 +0200 Subject: [PATCH 2/5] uncomment change --- rm-main/src/tui/tabs/torrents/table_manager.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rm-main/src/tui/tabs/torrents/table_manager.rs b/rm-main/src/tui/tabs/torrents/table_manager.rs index 7f6ddd3..009708d 100644 --- a/rm-main/src/tui/tabs/torrents/table_manager.rs +++ b/rm-main/src/tui/tabs/torrents/table_manager.rs @@ -277,10 +277,10 @@ impl TableManager { self.update_rows_number(); self.sort(); - // let mut state = self.table.state.borrow_mut(); - // if state.selected().is_none() && !self.table.items.is_empty() { - // state.select(Some(0)); - // } + let mut state = self.table.state.borrow_mut(); + if state.selected().is_none() && !self.table.items.is_empty() { + state.select(Some(0)); + } } pub fn set_filter(&mut self, filter: String) { From c6edcd14203b0b16ec4218e00fa50ca85b5bdaf8 Mon Sep 17 00:00:00 2001 From: Remigiusz Micielski Date: Sun, 8 Sep 2024 08:52:23 +0200 Subject: [PATCH 3/5] fix deletion in default keymap --- rm-config/defaults/keymap.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rm-config/defaults/keymap.toml b/rm-config/defaults/keymap.toml index 73f7b95..83500ad 100644 --- a/rm-config/defaults/keymap.toml +++ b/rm-config/defaults/keymap.toml @@ -44,8 +44,7 @@ keybindings = [ { on = "f", action = "ShowFiles" }, { on = "s", action = "ShowStats" }, - { on = "d", action = "DeleteWithoutFiles" }, - { on = "D", action = "DeleteWithFiles" }, + { on = "d", action = "Delete" }, ] [search_tab] From 7a22269459efa4d351363d815fe252258b7651a3 Mon Sep 17 00:00:00 2001 From: Remigiusz Micielski Date: Sun, 8 Sep 2024 10:15:42 +0200 Subject: [PATCH 4/5] ui: improve how default task looks --- rm-config/src/keymap/mod.rs | 11 +++++++++-- rm-config/src/main_config/icons.rs | 2 +- rm-main/src/tui/components/misc.rs | 1 - rm-main/src/tui/tabs/search/bottom_bar.rs | 2 +- rm-main/src/tui/tabs/torrents/popups/details.rs | 8 ++++---- rm-main/src/tui/tabs/torrents/popups/files.rs | 4 ++-- rm-main/src/tui/tabs/torrents/tasks/default.rs | 12 +++++++++--- rm-main/src/tui/tabs/torrents/tasks/selection.rs | 2 +- rm-main/src/tui/tabs/torrents/tasks/sort.rs | 6 +++--- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/rm-config/src/keymap/mod.rs b/rm-config/src/keymap/mod.rs index 8502b8f..3469305 100644 --- a/rm-config/src/keymap/mod.rs +++ b/rm-config/src/keymap/mod.rs @@ -367,7 +367,13 @@ impl KeymapConfig { } } - pub fn get_keys_for_action(&self, action: Action) -> Option { + pub fn get_keys_for_action_joined(&self, action: Action) -> Option { + let keys = self.get_keys_for_action(action)?; + + Some(keys.join("/")) + } + + pub fn get_keys_for_action(&self, action: Action) -> Option> { let mut keys = vec![]; for keybinding in &self.general.keybindings { @@ -390,8 +396,9 @@ impl KeymapConfig { if keys.is_empty() { None } else { - Some(keys.join("/")) + Some(keys) } + } fn populate_hashmap(&mut self) { diff --git a/rm-config/src/main_config/icons.rs b/rm-config/src/main_config/icons.rs index 39716ce..872f48f 100644 --- a/rm-config/src/main_config/icons.rs +++ b/rm-config/src/main_config/icons.rs @@ -123,7 +123,7 @@ fn default_disk() -> String { } fn default_help() -> String { - "󰘥".into() + "".into() } fn default_success() -> String { diff --git a/rm-main/src/tui/components/misc.rs b/rm-main/src/tui/components/misc.rs index 5197ddb..bda4f54 100644 --- a/rm-main/src/tui/components/misc.rs +++ b/rm-main/src/tui/components/misc.rs @@ -42,7 +42,6 @@ pub fn popup_rects(rect: Rect, percent_x: u16, percent_y: u16) -> (Rect, Rect, R pub fn keybinding_style() -> Style { Style::default() - .fg(CONFIG.general.accent_color) .underlined() .underline_color(CONFIG.general.accent_color) } diff --git a/rm-main/src/tui/tabs/search/bottom_bar.rs b/rm-main/src/tui/tabs/search/bottom_bar.rs index d6ba9cb..a7e7710 100644 --- a/rm-main/src/tui/tabs/search/bottom_bar.rs +++ b/rm-main/src/tui/tabs/search/bottom_bar.rs @@ -137,7 +137,7 @@ impl Component for SearchState { let append_key_info = |line: &mut Line| { let providers_key = CONFIG .keybindings - .get_keys_for_action(Action::ShowProvidersInfo); + .get_keys_for_action_joined(Action::ShowProvidersInfo); if let Some(key) = providers_key { line.push_span(Span::raw("Press ")); line.push_span(Span::styled(key, keybinding_style())); diff --git a/rm-main/src/tui/tabs/torrents/popups/details.rs b/rm-main/src/tui/tabs/torrents/popups/details.rs index 66ebe0b..016964e 100644 --- a/rm-main/src/tui/tabs/torrents/popups/details.rs +++ b/rm-main/src/tui/tabs/torrents/popups/details.rs @@ -86,7 +86,7 @@ impl Component for DetailsPopup { show_files_line.push_span(Span::styled( CONFIG .keybindings - .get_keys_for_action(Action::ShowFiles) + .get_keys_for_action_joined(Action::ShowFiles) .unwrap_or_default(), keybinding_style(), )); @@ -96,7 +96,7 @@ impl Component for DetailsPopup { move_location_line.push_span(Span::styled( CONFIG .keybindings - .get_keys_for_action(Action::MoveTorrent) + .get_keys_for_action_joined(Action::MoveTorrent) .unwrap_or_default(), keybinding_style(), )); @@ -106,7 +106,7 @@ impl Component for DetailsPopup { delete_line.push_span(Span::styled( CONFIG .keybindings - .get_keys_for_action(Action::Delete) + .get_keys_for_action_joined(Action::Delete) .unwrap_or_default(), keybinding_style(), )); @@ -116,7 +116,7 @@ impl Component for DetailsPopup { change_category_line.push_span(Span::styled( CONFIG .keybindings - .get_keys_for_action(Action::ChangeCategory) + .get_keys_for_action_joined(Action::ChangeCategory) .unwrap_or_default(), keybinding_style(), )); diff --git a/rm-main/src/tui/tabs/torrents/popups/files.rs b/rm-main/src/tui/tabs/torrents/popups/files.rs index 6e843e1..bdbfc86 100644 --- a/rm-main/src/tui/tabs/torrents/popups/files.rs +++ b/rm-main/src/tui/tabs/torrents/popups/files.rs @@ -285,13 +285,13 @@ impl Component for FilesPopup { if CONFIG.general.beginner_mode { let mut keys = vec![]; - if let Some(key) = CONFIG.keybindings.get_keys_for_action(Action::Select) { + if let Some(key) = CONFIG.keybindings.get_keys_for_action_joined(Action::Select) { keys.push(Span::raw(" ")); keys.push(Span::styled(key, keybinding_style())); keys.push(Span::raw(" - toggle | ")); } - if let Some(key) = CONFIG.keybindings.get_keys_for_action(Action::XdgOpen) { + if let Some(key) = CONFIG.keybindings.get_keys_for_action_joined(Action::XdgOpen) { keys.push(Span::styled(key, keybinding_style())); keys.push(Span::raw(" - xdg_open ")); } diff --git a/rm-main/src/tui/tabs/torrents/tasks/default.rs b/rm-main/src/tui/tabs/torrents/tasks/default.rs index 403cf68..0af668c 100644 --- a/rm-main/src/tui/tabs/torrents/tasks/default.rs +++ b/rm-main/src/tui/tabs/torrents/tasks/default.rs @@ -19,12 +19,18 @@ impl Component for Default { if CONFIG.general.beginner_mode { if let Some(keys) = CONFIG.keybindings.get_keys_for_action(Action::ShowHelp) { + line.push_span(Span::raw(format!("{} ", CONFIG.icons.help))); line_is_empty = false; - line.push_span(Span::raw(format!("{} ", CONFIG.icons.help))); - line.push_span(Span::styled(keys, keybinding_style())); + let keys_len = keys.len(); + for (idx, key) in keys.into_iter().enumerate() { + line.push_span(Span::styled(key, keybinding_style())); + if idx != keys_len - 1 { + line.push_span(Span::raw(" / ")); + } + } line.push_span(Span::raw(" - help")); } - if let Some(keys) = CONFIG.keybindings.get_keys_for_action(Action::Confirm) { + if let Some(keys) = CONFIG.keybindings.get_keys_for_action_joined(Action::Confirm) { if !line_is_empty { line.push_span(Span::raw(" | ")); } else { diff --git a/rm-main/src/tui/tabs/torrents/tasks/selection.rs b/rm-main/src/tui/tabs/torrents/tasks/selection.rs index 003eaf0..8fbf523 100644 --- a/rm-main/src/tui/tabs/torrents/tasks/selection.rs +++ b/rm-main/src/tui/tabs/torrents/tasks/selection.rs @@ -19,7 +19,7 @@ impl Component for Selection { let mut line = Line::default(); let mut line_is_empty = true; - if let Some(keys) = CONFIG.keybindings.get_keys_for_action(Action::Close) { + if let Some(keys) = CONFIG.keybindings.get_keys_for_action_joined(Action::Close) { line_is_empty = false; line.push_span(Span::styled(keys, keybinding_style())); line.push_span(Span::raw(" - clear selection")); diff --git a/rm-main/src/tui/tabs/torrents/tasks/sort.rs b/rm-main/src/tui/tabs/torrents/tasks/sort.rs index 68bc261..382014a 100644 --- a/rm-main/src/tui/tabs/torrents/tasks/sort.rs +++ b/rm-main/src/tui/tabs/torrents/tasks/sort.rs @@ -18,13 +18,13 @@ impl Component for Sort { let mut line = Line::default(); let mut line_is_empty = true; - if let Some(keys) = CONFIG.keybindings.get_keys_for_action(Action::Close) { + if let Some(keys) = CONFIG.keybindings.get_keys_for_action_joined(Action::Close) { line_is_empty = false; line.push_span(Span::styled(keys, keybinding_style())); line.push_span(Span::raw(" - reset & exit")); } - if let Some(keys) = CONFIG.keybindings.get_keys_for_action(Action::Confirm) { + if let Some(keys) = CONFIG.keybindings.get_keys_for_action_joined(Action::Confirm) { if !line_is_empty { line.push_span(Span::raw(" | ")); } @@ -33,7 +33,7 @@ impl Component for Sort { line.push_span(Span::raw(" - apply")); } - if let Some(keys) = CONFIG.keybindings.get_keys_for_action(Action::Down) { + if let Some(keys) = CONFIG.keybindings.get_keys_for_action_joined(Action::Down) { if !line_is_empty { line.push_span(Span::raw(" | ")); } From 181cf518463532aa8f69755d1cf956bab40154fd Mon Sep 17 00:00:00 2001 From: Remigiusz Micielski Date: Sun, 8 Sep 2024 10:22:48 +0200 Subject: [PATCH 5/5] add missing keys for sorting --- rm-config/defaults/keymap.toml | 4 ++++ rm-config/src/keymap/actions/general.rs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rm-config/defaults/keymap.toml b/rm-config/defaults/keymap.toml index 83500ad..a873e3c 100644 --- a/rm-config/defaults/keymap.toml +++ b/rm-config/defaults/keymap.toml @@ -33,6 +33,10 @@ keybindings = [ { on = "l", action = "Right" }, { on = "k", action = "Up" }, { on = "j", action = "Down" }, + + # Sorting + { on = "H", action = "MoveToColumnLeft"}, + { on = "L", action = "MoveToColumnRight"}, ] [torrents_tab] diff --git a/rm-config/src/keymap/actions/general.rs b/rm-config/src/keymap/actions/general.rs index 5307047..d659fde 100644 --- a/rm-config/src/keymap/actions/general.rs +++ b/rm-config/src/keymap/actions/general.rs @@ -75,8 +75,8 @@ impl UserAction for GeneralAction { GeneralAction::GoToBeginning => "scroll to beginning", GeneralAction::GoToEnd => "scroll to end", GeneralAction::XdgOpen => "open with xdg-open", - GeneralAction::MoveToColumnRight => "move to right column", - GeneralAction::MoveToColumnLeft => "move to left column", + GeneralAction::MoveToColumnRight => "move to right column (sorting)", + GeneralAction::MoveToColumnLeft => "move to left column (sorting)", } }