Allow interrupting "w".

This commit is contained in:
bʰedoh₂ swé 2025-01-12 05:05:09 +05:00
parent 6368aa3446
commit b064a0585b

View File

@ -70,16 +70,22 @@ print_messages() {
} }
wait_for_messages() { wait_for_messages() {
tmp=0
trap 'tmp=1' INT
oldlength="${length}" oldlength="${length}"
while :; do while :; do
length="$(get_message 1)" length="$(get_message 1)"
if [ "${oldlength}" -ne "${length}" ]; then if [ "${oldlength}" -ne "${length}" ]; then
break trap - INT
return 0
fi
if [ "${tmp}" -eq 1 ]; then
trap - INT
return 1
fi fi
echo -n . echo -n .
sleep 1 sleep 1
done done
echo
} }
length=0 length=0
@ -103,11 +109,14 @@ while :; do
echo "${length}" echo "${length}"
;; ;;
w) w)
wait_for_messages wait_for_messages &&
print_messages "${length}" {
if [ -n "${DOBROHO_VECHORA_ON_WAIT}" ]; then echo
${DOBROHO_VECHORA_ON_WAIT} print_messages "${length}"
fi if [ -n "${DOBROHO_VECHORA_ON_WAIT}" ]; then
${DOBROHO_VECHORA_ON_WAIT}
fi
}
;; ;;
p) p)
length="$(get_message 1)" length="$(get_message 1)"