Skip to content

Commit

Permalink
Merge pull request #574 from Integral-Tech/destruct-tuple
Browse files Browse the repository at this point in the history
refactor: destruct tuples to enhance readability
  • Loading branch information
kamiyaa authored Nov 3, 2024
2 parents 42f3519 + ed62922 commit 2c23a69
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
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

0 comments on commit 2c23a69

Please sign in to comment.