From b064a0585b46805096ca783f69e8af60ef2b75b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Sun, 12 Jan 2025 05:05:09 +0500 Subject: [PATCH] Allow interrupting "w". --- dobroho_vechora.bash | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/dobroho_vechora.bash b/dobroho_vechora.bash index c6329ea..beca268 100755 --- a/dobroho_vechora.bash +++ b/dobroho_vechora.bash @@ -70,16 +70,22 @@ print_messages() { } wait_for_messages() { + tmp=0 + trap 'tmp=1' INT oldlength="${length}" while :; do length="$(get_message 1)" if [ "${oldlength}" -ne "${length}" ]; then - break + trap - INT + return 0 + fi + if [ "${tmp}" -eq 1 ]; then + trap - INT + return 1 fi echo -n . sleep 1 done - echo } length=0 @@ -103,11 +109,14 @@ while :; do echo "${length}" ;; w) - wait_for_messages - print_messages "${length}" - if [ -n "${DOBROHO_VECHORA_ON_WAIT}" ]; then - ${DOBROHO_VECHORA_ON_WAIT} - fi + wait_for_messages && + { + echo + print_messages "${length}" + if [ -n "${DOBROHO_VECHORA_ON_WAIT}" ]; then + ${DOBROHO_VECHORA_ON_WAIT} + fi + } ;; p) length="$(get_message 1)"