#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum PromptKind {
Command,
UnverifiedCommand,
Continuation,
Other,
}
impl PromptKind {
pub(super) fn is_command(self) -> bool {
matches!(self, Self::Command | Self::UnverifiedCommand)
}
pub(super) fn is_verified_command(self) -> bool {
matches!(self, Self::Command)
}
pub(super) fn is_continuation(self) -> bool {
matches!(self, Self::Continuation)
}
pub(super) fn is_other(self) -> bool {
matches!(self, Self::Other)
}
}
pub(super) fn classify_prompt(prompt: &str, is_continuation: bool) -> PromptKind {
if is_continuation {
return PromptKind::Continuation;
}
match arf_harp::r_n_frame() {
Ok(0) => PromptKind::Command,
Ok(_) => PromptKind::Other,
Err(_) => {
if prompt.ends_with("> ") {
PromptKind::UnverifiedCommand
} else {
PromptKind::Other
}
}
}
}
pub(super) fn formatter_failure_updates_lifecycle(prompt_kind: PromptKind) -> bool {
prompt_kind.is_command()
}
pub(super) fn should_process_pending_help_requests(
prompt_kind: PromptKind,
shell_enabled: bool,
) -> bool {
prompt_kind.is_verified_command() && !shell_enabled
}
pub(super) fn should_warn_prompt_ambiguity(was_ambiguous: &mut bool, is_ambiguous: bool) -> bool {
let should_warn = is_ambiguous && !*was_ambiguous;
*was_ambiguous = is_ambiguous;
should_warn
}