Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: improve how default task looks #114

Merged
merged 7 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rm-config/defaults/keymap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions rm-config/src/keymap/actions/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
}
}

Expand Down
11 changes: 9 additions & 2 deletions rm-config/src/keymap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,13 @@ impl KeymapConfig {
}
}

pub fn get_keys_for_action(&self, action: Action) -> Option<String> {
pub fn get_keys_for_action_joined(&self, action: Action) -> Option<String> {
let keys = self.get_keys_for_action(action)?;

Some(keys.join("/"))
}

pub fn get_keys_for_action(&self, action: Action) -> Option<Vec<String>> {
let mut keys = vec![];

for keybinding in &self.general.keybindings {
Expand All @@ -390,8 +396,9 @@ impl KeymapConfig {
if keys.is_empty() {
None
} else {
Some(keys.join("/"))
Some(keys)
}

}

fn populate_hashmap(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion rm-config/src/main_config/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn default_disk() -> String {
}

fn default_help() -> String {
"󰘥".into()
"".into()
}

fn default_success() -> String {
Expand Down
1 change: 0 additions & 1 deletion rm-main/src/tui/components/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion rm-main/src/tui/tabs/search/bottom_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
8 changes: 4 additions & 4 deletions rm-main/src/tui/tabs/torrents/popups/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
));
Expand All @@ -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(),
));
Expand All @@ -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(),
));
Expand All @@ -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(),
));
Expand Down
4 changes: 2 additions & 2 deletions rm-main/src/tui/tabs/torrents/popups/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "));
}
Expand Down
12 changes: 9 additions & 3 deletions rm-main/src/tui/tabs/torrents/tasks/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion rm-main/src/tui/tabs/torrents/tasks/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
6 changes: 3 additions & 3 deletions rm-main/src/tui/tabs/torrents/tasks/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(" | "));
}
Expand All @@ -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(" | "));
}
Expand Down
Loading