mirror of
https://github.com/nushell/nushell.git
synced 2025-05-01 00:24:29 +02:00
REFACTOR: make input list
a tiny bit tighter (#9115)
related to #8963 cc/ @melMass # Description just a little refactoring attempt for `input list` 😌 i wanted to refactor even more, but `Select`, `MultiSelect` and `FuzzySelect` do not share a common trait, i could not find a nice way to reduce the big `if` block... # User-Facing Changes ``` $nothing ``` # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - ⚫ `toolkit test` - ⚫ `toolkit test stdlib` # After Submitting ``` $nothing ```
This commit is contained in:
parent
a5d02a0737
commit
fe9f732c5f
@ -127,6 +127,13 @@ impl Command for InputList {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if call.has_flag("multi") && call.has_flag("fuzzy") {
|
||||||
|
return Err(ShellError::TypeMismatch {
|
||||||
|
err_message: "Fuzzy search is not supported for multi select".to_string(),
|
||||||
|
span: head,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// could potentially be used to map the use theme colors at some point
|
// could potentially be used to map the use theme colors at some point
|
||||||
// let theme = dialoguer::theme::ColorfulTheme {
|
// let theme = dialoguer::theme::ColorfulTheme {
|
||||||
// active_item_style: Style::new().fg(Color::Cyan).bold(),
|
// active_item_style: Style::new().fg(Color::Cyan).bold(),
|
||||||
@ -134,12 +141,6 @@ impl Command for InputList {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
let ans: InteractMode = if call.has_flag("multi") {
|
let ans: InteractMode = if call.has_flag("multi") {
|
||||||
if call.has_flag("fuzzy") {
|
|
||||||
return Err(ShellError::TypeMismatch {
|
|
||||||
err_message: "Fuzzy search is not supported for multi select".to_string(),
|
|
||||||
span: head,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
let mut multi_select = MultiSelect::new(); //::with_theme(&theme);
|
let mut multi_select = MultiSelect::new(); //::with_theme(&theme);
|
||||||
|
|
||||||
InteractMode::Multi(
|
InteractMode::Multi(
|
||||||
@ -153,7 +154,6 @@ impl Command for InputList {
|
|||||||
.interact_on_opt(&Term::stderr())
|
.interact_on_opt(&Term::stderr())
|
||||||
.map_err(|err| ShellError::IOError(format!("{}: {}", INTERACT_ERROR, err)))?,
|
.map_err(|err| ShellError::IOError(format!("{}: {}", INTERACT_ERROR, err)))?,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
} else if call.has_flag("fuzzy") {
|
} else if call.has_flag("fuzzy") {
|
||||||
let mut fuzzy_select = FuzzySelect::new(); //::with_theme(&theme);
|
let mut fuzzy_select = FuzzySelect::new(); //::with_theme(&theme);
|
||||||
|
|
||||||
@ -185,9 +185,8 @@ impl Command for InputList {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
match ans {
|
Ok(match ans {
|
||||||
InteractMode::Multi(res) => Ok({
|
InteractMode::Multi(res) => match res {
|
||||||
match res {
|
|
||||||
Some(opts) => Value::List {
|
Some(opts) => Value::List {
|
||||||
vals: opts.iter().map(|s| options[*s].value.clone()).collect(),
|
vals: opts.iter().map(|s| options[*s].value.clone()).collect(),
|
||||||
span: head,
|
span: head,
|
||||||
@ -196,21 +195,16 @@ impl Command for InputList {
|
|||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: head,
|
span: head,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
}
|
InteractMode::Single(res) => match res {
|
||||||
.into_pipeline_data()),
|
|
||||||
InteractMode::Single(res) => Ok({
|
|
||||||
match res {
|
|
||||||
Some(opt) => options[opt].value.clone(),
|
Some(opt) => options[opt].value.clone(),
|
||||||
|
|
||||||
None => Value::String {
|
None => Value::String {
|
||||||
val: "".to_string(),
|
val: "".to_string(),
|
||||||
span: head,
|
span: head,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
.into_pipeline_data())
|
||||||
.into_pipeline_data()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
Loading…
Reference in New Issue
Block a user