mafredri / zsh-async

Because your terminal should be able to perform tasks asynchronously without external tools!
MIT License
766 stars 34 forks source link

Safe way to print output from callback fn #51

Open Gautham opened 3 years ago

Gautham commented 3 years ago

First of all, thanks for this library! This awesome 🥇

This is not strictly a zsh-async qn but it might be helpful to others so asking here: What would be the recommended way to display output from the callback fn?

  1. Using normal echo can result in a messy output since the echo output could mess with the current BUFFER making both the output and the command being typed unreadable.
  2. I use powerlevel10k which has a feature called transient prompt. The tl:dr; is that it triggers a zle reset-prompt as a preexec function which basically clears any printed text from the (now-)previous-line prompt.

Do you have any suggestions on how I can safely show my output given the above two constraints?

Cyberbeni commented 2 years ago

Generally you want to start async jobs in precmd hooks to get information for prompt segments and then reset-prompt when you get them. If you want to run scripts manually, you really should just be using regular foreground/background jobs. Or if you want to have something similar to background jobs but the output is written to files and then you see in one of the prompt segments how many unread outputs you have, I guess that is also doable.