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

refactor: destruct tuples to enhance readability #574

Merged
merged 1 commit into from
Nov 3, 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
6 changes: 3 additions & 3 deletions src/commands/custom_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn custom_search(
.command
.clone();

let current_filenames: Vec<&str> = current_files(app_state).iter().map(|f| f.0).collect();
let current_filenames: Vec<&str> = current_files(app_state).iter().map(|(f, _)| *f).collect();

let text = custom_command.replace("%s", &current_filenames.join(" "));
let text = text.replace(
Expand Down Expand Up @@ -91,8 +91,8 @@ pub fn custom_search(
let position = current_dir_items
.iter()
.enumerate()
.find(|x| x.1.file_name() == path.file_name().unwrap_or_default())
.map(|x| x.0)
.find(|(_, x)| x.file_name() == path.file_name().unwrap_or_default())
.map(|(x, _)| x)
.unwrap_or_default();

cursor_move::cursor_move(app_state, position);
Expand Down
6 changes: 4 additions & 2 deletions src/commands/sub_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ fn execute_sub_process(
) -> std::io::Result<()> {
let current_files = current_files(app_state);
let command_base = if current_files.len() == 1 {
let (file_name, file_path) = current_files[0];

words[0]
.replace("%s", current_files[0].0)
.replace("%p", &current_files[0].1.to_string_lossy())
.replace("%s", file_name)
.replace("%p", &file_path.to_string_lossy())
} else {
words[0].clone()
};
Expand Down
28 changes: 14 additions & 14 deletions src/types/option/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ impl From<DisplayOptionRaw> for DisplayOption {
_ => DisplayMode::Default,
};

let column_ratio = match raw.column_ratio {
let (left, mid, right) = match raw.column_ratio {
Some(s) if s.len() == 3 => (s[0], s[1], s[2]),
Some(s) if s.len() == 2 => (0, s[0], s[1]),
_ => default_column_ratio(),
};

let total = (column_ratio.0 + column_ratio.1 + column_ratio.2) as u32;
let total = (left + mid + right) as u32;

let default_layout = [
Constraint::Ratio(column_ratio.0 as u32, total),
Constraint::Ratio(column_ratio.1 as u32, total),
Constraint::Ratio(column_ratio.2 as u32, total),
Constraint::Ratio(left as u32, total),
Constraint::Ratio(mid as u32, total),
Constraint::Ratio(right as u32, total),
];
let no_preview_layout = [
Constraint::Ratio(column_ratio.0 as u32, total),
Constraint::Ratio(column_ratio.1 as u32 + column_ratio.2 as u32, total),
Constraint::Ratio(left as u32, total),
Constraint::Ratio(mid as u32 + right as u32, total),
Constraint::Ratio(0, total),
];

Expand Down Expand Up @@ -92,17 +92,17 @@ impl DisplayOption {

impl std::default::Default for DisplayOption {
fn default() -> Self {
let column_ratio = default_column_ratio();
let (left, mid, right) = default_column_ratio();

let total = (column_ratio.0 + column_ratio.1 + column_ratio.2) as u32;
let total = (left + mid + right) as u32;
let default_layout = [
Constraint::Ratio(column_ratio.0 as u32, total),
Constraint::Ratio(column_ratio.1 as u32, total),
Constraint::Ratio(column_ratio.2 as u32, total),
Constraint::Ratio(left as u32, total),
Constraint::Ratio(mid as u32, total),
Constraint::Ratio(right as u32, total),
];
let no_preview_layout = [
Constraint::Ratio(column_ratio.0 as u32, total),
Constraint::Ratio(column_ratio.1 as u32 + column_ratio.2 as u32, total),
Constraint::Ratio(left as u32, total),
Constraint::Ratio(mid as u32 + right as u32, total),
Constraint::Ratio(0, total),
];

Expand Down
Loading