Initial async prompt utility wrapper

This commit is contained in:
Marc Cornellà 2024-05-30 19:51:35 +02:00
commit c4a126c2ac
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B
4 changed files with 39 additions and 26 deletions

View file

@ -26,7 +26,6 @@ autoload -Uz is-at-least
# This API is subject to change and optimization. Rely on it at your own risk.
function _omz_register_handler {
setopt localoptions noksharrays
typeset -ga _omz_async_functions
# we want to do nothing if there's no $1 function or we already set it up
if [[ -z "$1" ]] || (( ! ${+functions[$1]} )) \
@ -42,6 +41,25 @@ function _omz_register_handler {
fi
}
function _omz_make_async_function {
local sync_func=$1
# Check if the sync function has already been made async
if (( ${+functions[${sync_func}_async]} )); then
return
fi
# Register the sync function as a handler
_omz_register_handler ${sync_func}
# Redefine the original function to output the async result
eval "function ${sync_func}_async {
if [[ -n \"\${_OMZ_ASYNC_OUTPUT[${sync_func}]}\" ]]; then
echo -n \"\${_OMZ_ASYNC_OUTPUT[${sync_func}]}\"
fi
}"
}
# Set up async handlers and callbacks
function _omz_async_request {
local -i ret=$?