During command substitution, the command being substituted has no indication whether it is being run directly or as a command substitution (there is a special ZSH_EVAL_CONTEXT variable though exporting that only indicates toplevel regardless), and writing to the terminal then restoring the cursor position will be complicated.:
% echocat $(awkward #!/bin/zsh echo -ne "\e7\n -- warning: lo0lp0 on fire\e8"fire\e[F\e8" >/dev/tty; echo blat % ./awkward blat % echo $(./awkward)█ ... though that's the simple case of direct ZSH code running inside the shell itself (and it's buggyhardly perfect, as if the prompt is ondown at the last linebottom of the window); as a child process, wellscreen, good luckhorrible buggy things happen:
% cat awkward #!/bin/zsh echo -ne "\e7\n -- warning: lp0 on fire\e[F\e8" >/dev/tty; echo blat"\e[$LINES;0H" ... % ./awkward blatwarning: lp0 on fire % echo $(./awkward ) -- warblat█warblat fire A more complicated program would need to deal properly with being at the bottom of the terminal, or even use ncurses for portability, and will need to somehow indicate to zsh that any custom line(s) written (may) need to be cleared so the display does not risk being mucked up with the output of a subsequent command. But that's more work.
The zsh code in Src/exec.c does not look like it does anything special for a cmdsubst job, and the preexec hook function is not called for command substitution, either. So I'm really not seeing anything readily viablesimple for custom below-the-prompt terminal messaging during the execution of a command substitution in zsh.