Skip to content

Instantly share code, notes, and snippets.

@romkatv
Created March 3, 2024 15:21
Show Gist options
  • Save romkatv/f07538b46cec054d0a3a2d38499c4d2a to your computer and use it in GitHub Desktop.
Save romkatv/f07538b46cec054d0a3a2d38499c4d2a to your computer and use it in GitHub Desktop.
function prompt_my_msa() {
p10k segment -e -t '$my_msa_content' -b black -f white
(( $+my_msa_content )) && return
typeset -g my_msa_content
local -r msa=~/minimal_spectrum_analyzer/build/analyzer
[[ -x $msa ]] || return
local fd
exec {fd}< <("$msa" --line_feed LF -a off -c 16 0<&- 2>&- &!) || return
function my_msa_callback() {
if (( ARGC == 1 )); then
local line suf
[[ -t $1 ]] # https://www.zsh.org/mla/workers/2020/msg00207.html
while true; do
if sysread -t0 -i $1 'line[$#line+1]'; then
line=${line##*$'\n'}
elif (( $? == 4 )); then
(( $#line == 16 )) || continue
if [[ $line != $my_msa_content ]]; then
my_msa_content=$line
p10k display -r
fi
return
else
break
fi
done
fi
zle -F $1
exec {1}<&-
my_msa_content=
}
zle -F $fd my_msa_callback
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment