mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-06 02:51:32 +01:00
Initial async prompt utility wrapper
This commit is contained in:
parent
a4424dfefd
commit
c4a126c2ac
4 changed files with 39 additions and 26 deletions
|
|
@ -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=$?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue