Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] A better approach to do an async feature to RPROMPT #448

Closed
sinetoami opened this issue Dec 1, 2018 · 2 comments
Closed

[Question] A better approach to do an async feature to RPROMPT #448

sinetoami opened this issue Dec 1, 2018 · 2 comments

Comments

@sinetoami
Copy link

I'm trying to implement an asynchronous feature to put in the RPROMPT. In short, I'm trying to get language versions and set them up in RPROMPT as alien-minimal does. I did. But I'm not sure if I did it in the best way. So, I want some advice about how doing this.

I coded something like:

# pure/pure.zsh
prompt_pure_preprompt_render() {
  ....
  PROMPT="${(j..)ps1}"
  RPROMPT="${pure_langs}"
  ....
}

prompt_pure_precmd() {
  ...
  prompt_pure_async_langs_task
}

prompt_pure_async_langs() {
  setopt localoptions noshwordsplit
  command echo ${#PURE_LANG_VERSION[*]}
}

prompt_pure_async_langs_task() {
  setopt localoptions noshwordsplit
  if [[ -n ${#PURE_LANG_VERSION[@]} ]]; then
    async_start_worker "prompt_pure_langs" -n
    async_register_callback "prompt_pure_langs" prompt_pure_async_langs_callback
  fi

  async_job "prompt_pure_langs" prompt_pure_async_langs
}

prompt_pure_async_langs_callback() {
  setopt localoptions noshwordsplit
  local job=$1 code=$2 output=$3 exec_time=$4 next_pending=$6

  if [[ -n $output ]]; then
    typeset -g purien_langs=$(prompt_pure_langs_compose)
    prompt_pure_preprompt_render
    zle reset-prompt
  fi
}

# ~/.zshrc
export PURE_LANG_VERSION=( ruby python )

It's a brief of what I did. But, what can I do to make this code better?

Thanks!

@mafredri
Copy link
Collaborator

Hi, sorry for the long delay. We can't really provide support in modifying Pure / using zsh-async here. But mostly I'd say you're on the right path. I would, however, move prompt_pure_langs_compose out of the callback and into the function that's running asynchronously. I'm assuming that's the one that might take a while and as the code is now, it's not really taking advantage of the async behavior.

@sinetoami
Copy link
Author

@mafredri , thanks for your answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants