feat: refine live outage dashboard layout
Some checks failed
Test blackout notifier / test (push) Failing after 3s
Hourly blackout check / check (push) Successful in 5s

This commit is contained in:
2026-07-18 09:13:52 +03:30
parent ded914a6fd
commit e71dd125a9
2 changed files with 25 additions and 15 deletions

31
main.sh
View File

@@ -753,12 +753,12 @@ schedule_next_transition() {
render_dashboard() {
local now_epoch="$1"
local columns width rule phase start_epoch stop_epoch record remaining banner
local columns content_width rule phase start_epoch stop_epoch record remaining banner
local schedule_line ignored
color_setup
columns="$(terminal_columns)"
width=$((columns < 150 ? columns : 150))
content_width=$((columns < 150 ? columns : 150))
if ((${#SCHEDULE[@]} == 0)); then
render_empty "$columns"
@@ -772,12 +772,12 @@ render_dashboard() {
remaining=$((start_epoch - now_epoch))
fi
banner="$(banner_duration "$remaining")"
rule="$(repeat_character '=' "$width")"
rule="$(repeat_character '=' "$columns")"
printf '%s%s%s\n' "$CYAN" "$rule" "$RESET"
printf '\n'
printf '%s%s' "$BOLD" "$YELLOW"
print_large_countdown "$banner" "$width"
print_large_countdown "$banner" "$columns"
printf '%s' "$RESET"
printf '\n%s%s%s\n' "$CYAN" "$rule" "$RESET"
printf '\n%sOUTAGE SCHEDULE (%d)%s\n\n' "$BOLD" "${#SCHEDULE[@]}" "$RESET"
@@ -785,13 +785,13 @@ render_dashboard() {
for schedule_line in "${SCHEDULE[@]}"; do
IFS=$'\t' read -r ignored phase start_epoch stop_epoch record <<<"$schedule_line"
render_event "$schedule_line" "$now_epoch"
printf '%s\n' "$DIM$(repeat_character '-' "$width")$RESET"
printf '%s\n' "$DIM$(repeat_character '-' "$columns")$RESET"
done
}
main() {
local now_epoch next_refresh=0 refresh_minutes=10 refresh_seconds state_ready=0
local last_rendered=-1 next_transition=0 rebuild_schedule=0 frame key
local last_rendered=-1 next_transition=0 rebuild_schedule=0 frame key input_fd=0
while (($#)); do
case "$1" in
@@ -833,17 +833,23 @@ main() {
STATE_PATH="$(mktemp "${TMPDIR:-/tmp}/blackout-state.XXXXXX")"
DOWNLOAD_PATH="$(mktemp "${TMPDIR:-/tmp}/blackout-download.XXXXXX")"
REFRESH_STATUS_PATH="$(mktemp "${TMPDIR:-/tmp}/blackout-refresh.XXXXXX")"
if [[ -r /dev/tty ]]; then
exec {input_fd}</dev/tty
fi
start_terminal
while true; do
printf -v now_epoch '%(%s)T' -1
if ((now_epoch == last_rendered)); then
if [[ -t 0 ]]; then
if [[ -t "$input_fd" ]]; then
key=""
if read -rsn 1 -t 0.1 key && [[ "$key" == "q" || "$key" == "Q" ]]; then
if read -u "$input_fd" -rsn 1 -t 0.1 key \
&& [[ "$key" == "q" || "$key" == "Q" ]]; then
break
fi
else
fi
printf -v now_epoch '%(%s)T' -1
if ((now_epoch == last_rendered)); then
if [[ ! -t "$input_fd" ]]; then
sleep 0.1
fi
continue
@@ -882,9 +888,6 @@ main() {
if [[ -n "$REFRESH_ERROR" ]]; then
printf '\n%s\n' "$REFRESH_ERROR"
fi
if [[ -t 0 ]]; then
printf '\nPress q to quit.\n'
fi
)"
draw_frame "$frame"
done

View File

@@ -162,6 +162,13 @@ if [[ "$OUTPUT" == *$'\033['* ]]; then
printf 'FAIL: NO_COLOR output contains ANSI escapes\n' >&2
exit 1
fi
WIDE_OUTPUT="$(NO_COLOR=1 COLUMNS=180 render_dashboard "$NOW_EPOCH")"
WIDE_TOP_LINE="${WIDE_OUTPUT%%$'\n'*}"
assert_equal "180" "${#WIDE_TOP_LINE}" \
"the countdown divider should span the full terminal width"
WIDE_BOTTOM_LINE="${WIDE_OUTPUT##*$'\n'}"
assert_equal "180" "${#WIDE_BOTTOM_LINE}" \
"the dashboard bottom divider should span the full terminal width"
FUTURE_NOW="$(TZ=Asia/Tehran date -d '2026-07-18 15:00:00' +%s)"
build_schedule "$FIXTURE" "$FUTURE_NOW"