use crate::ported::exec_hooks::dispatch_function_call;
use crate::ported::modules::zutil::lookupstyle;
use crate::ported::params::getsparam;
use crate::ported::zle::compcore::set_compstate_str;
use crate::ported::zle::complete::bin_compset;
use crate::ported::zsh_h::{isset, options, MAGICEQUALSUBST, MAX_OPS};
fn make_ops() -> options {
options {
ind: [0u8; MAX_OPS],
args: Vec::new(),
argscount: 0,
argsalloc: 0,
}
}
pub fn _default(args: &[String]) -> i32 {
let curcontext = getsparam("curcontext").unwrap_or_default();
let ctl = lookupstyle(&format!(":completion:{}:", curcontext), "use-compctl")
.first()
.cloned()
.unwrap_or_default();
if !ctl.is_empty() && !matches!(ctl.as_str(), "no" | "false" | "0" | "off") {
let mut opt: Vec<String> = Vec::new();
if ctl.contains("first") {
opt.push("-T".to_string());
}
if ctl.contains("default") {
opt.push("-D".to_string());
}
if dispatch_function_call("compcall", &opt).unwrap_or(1) == 0 {
return 0;
}
}
if dispatch_function_call("_files", args).unwrap_or(1) == 0 {
return 0;
}
let prefix = getsparam("PREFIX").unwrap_or_default();
if isset(MAGICEQUALSUBST) && prefix.contains('=') {
let param = prefix.splitn(2, '=').next().unwrap_or("").to_string();
set_compstate_str("parameter", ¶m);
let _ = bin_compset(
"compset",
&["-P".to_string(), "1".to_string(), "*=".to_string()],
&make_ops(),
0,
);
dispatch_function_call("_value", args).unwrap_or(1)
} else {
1
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn returns_one_without_executor() {
let _g = crate::test_util::global_state_lock();
assert_eq!(_default(&[]), 1);
}
}