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

implemented interactive reorder #53

Merged
merged 2 commits into from
Jan 13, 2025
Merged
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
40 changes: 34 additions & 6 deletions src/ocd/mrn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,42 @@ fn apply_delete(filename: &str, from_idx: usize, to: &Position) -> String {
s
}

fn apply_interactive_reorder(_filename: &str) -> String {
// split filename into substrings
fn apply_interactive_reorder(filename: &str) -> String {
// split filename into fields
let fields: Vec<_> = filename.split(' ').collect();

// print each substring with its index below
// read user input
let _input = crate::ocd::user_input();
// process input into a series of indices
let mut idx_line = String::new();
for (idx, field) in fields.iter().enumerate() {
let w = field.len() + 1;
let w = if idx < 10 { w } else { w - 1 };
idx_line.push_str(format!("{1:<0$}", w, idx + 1).as_str());
}
println!(" {}", filename);
println!(" {}", idx_line);

// read user input & process into a series of indices
let input = crate::ocd::user_input();
let input = input.split(' ').map(str::parse::<usize>);

// all the integers must be parseable and also valid indexes into fields.
if input
.clone()
.any(|e| e.is_err() || e.as_ref().unwrap() > &fields.len())
{
panic!("Unable to parse user input or invalid index.")
}
let input: Vec<_> = input.map(|e| e.unwrap()).collect();

// generate new string
todo!("Interactive reorder instruction not implemented yet!")
let mut result = String::new();
for i in input.iter().take(input.len() - 1) {
result.push_str(fields[i - 1]);
result.push(' ');
}
result.push_str(fields[*input.last().unwrap() - 1]);

result
}

#[cfg(test)]
Expand Down
Loading