Skip to content

Commit

Permalink
refactor(simplify): Search for choices as first char (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
dark0dave authored Apr 14, 2024
2 parents 1b6db40 + 3f1fffb commit eda9fb6
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/weidu_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ const WEIDU_USEFUL_STATUS: [&str; 9] = [
"processing",
];

const WEIDU_CHOICE: [&str; 7] = [
const WEIDU_CHOICE: [&str; 6] = [
"choice",
"choose",
"select",
"do you want",
"would you like",
"enter",
"the full path",
];

const WEIDU_CHOICE_SYMBOL: [char; 2] = ['?', ':'];
Expand Down Expand Up @@ -140,20 +139,12 @@ fn string_looks_like_question(weidu_output: &str) -> bool {
{
return false;
}
// enter.*the full path.*
if comparable_output.contains(WEIDU_CHOICE[WEIDU_CHOICE.len() - 1])
&& comparable_output.starts_with(WEIDU_CHOICE[WEIDU_CHOICE.len() - 2])
{
return true;
}
(WEIDU_CHOICE.contains(&comparable_output.as_str()))
|| WEIDU_CHOICE_SYMBOL.contains(
&comparable_output
.as_str()
.chars()
.last()
.unwrap_or_default(),
)
|| WEIDU_CHOICE_SYMBOL.contains(&comparable_output.chars().last().unwrap_or_default())
|| comparable_output
.split(' ')
.take(1)
.any(|c| WEIDU_CHOICE.contains(&c))
}

fn detect_weidu_finished_state(weidu_output: &str) -> Option<State> {
Expand Down

0 comments on commit eda9fb6

Please sign in to comment.