romkatv / powerlevel10k

A Zsh theme
MIT License
46.45k stars 2.19k forks source link

Prompt not updated after zle reset-prompt #851

Closed aviramsegal closed 4 years ago

aviramsegal commented 4 years ago

Hi, I followed some examples and wrote this simple async prompt The prompt only udpate after I hit another enter. Used set -x to see if its even called and all I see is

+my_async_callback:3> zle reset-prompt
+_p9k_on_expand:1> ((  _p9k__expanded && ! 0  ))
+_p9k_on_expand:1> [[ UTF-8 == (utf|UTF)(-|)8 ]]
+_p9k_on_expand:1> return
+my_async_callback:4> zle -R

It seems that after reset-prompt nothing is really done. I played around with the p10k segement params but nothing seems to work. I would love some help, thanks.

function my_async_fun() {
  echo "TESTING"
}

function my_async_callback() {
  MY_P9K_PROMPT_OUTPUT="$3"
  zle reset-prompt
  zle -R
}

async_init
async_start_worker my_async_worker -n
async_register_callback my_async_worker my_async_callback
typeset -g MY_P9K_PROMPT_OUTPUT

prompt_my_prompt() {
  async_job my_async_worker my_async_fun $PWD
  local content="$MY_P9K_PROMPT_OUTPUT"
  p10k segment -e -c "$content" -t "$content"
}
romkatv commented 4 years ago

Change prompt_my_prompt like this:

prompt_my_prompt() {
  async_job my_async_worker my_async_fun $PWD
  p10k segment -e -t '$MY_P9K_PROMPT_OUTPUT'
}

Type p10k help segment for help.