#!/usr/bin/env bash

# omarchy:summary=Display a closing message and wait for user to press any key.
# omarchy:args=[message]

# The device node is there whether or not a terminal is behind it, so opening
# it is the only test that means anything.
: 2>/dev/null <>/dev/tty || exit 0

# gum 2.0 no longer lets a spun command read the terminal, so the wait has to
# happen here. Its own query replies are still queued on the tty; drop those or
# they answer the keypress for the user.
while read -rsn 1 -t 0.1 _ </dev/tty; do :; done

# Prompt on the terminal rather than stdout, or a caller that redirects us
# leaves the user waiting on a prompt they were never shown. The message is an
# argument because holding the window open is the same job whatever the flow has
# to say, and a flow somebody cancelled must not be told it is done.
printf '\n\033[32m● \033[0m%s Press any key to close...' "${1:-Done!}" >/dev/tty
read -rsn 1 </dev/tty
echo >/dev/tty
