fix(cli): make status dividers span terminal width
Some checks failed
Test blackout notifier / test (push) Failing after 2s
Hourly blackout check / check (push) Successful in 3s

This commit is contained in:
2026-07-21 17:01:00 +03:30
parent b317726638
commit 301e57fe70
2 changed files with 53 additions and 16 deletions

54
main.sh
View File

@@ -354,8 +354,25 @@ build_schedule() {
terminal_columns() {
local columns="${COLUMNS:-}"
local terminal_size="" detected_columns=""
if [[ -z "$columns" && -t 1 ]] && command -v tput >/dev/null 2>&1; then
if [[ -z "$columns" ]] && command -v stty >/dev/null 2>&1; then
if [[ -r /dev/tty ]]; then
terminal_size="$(stty size 2>/dev/null </dev/tty || true)"
fi
if [[ -z "$terminal_size" && -t 2 ]]; then
terminal_size="$(stty size <&2 2>/dev/null || true)"
fi
if [[ -z "$terminal_size" && -t 0 ]]; then
terminal_size="$(stty size <&0 2>/dev/null || true)"
fi
read -r _ detected_columns <<<"$terminal_size"
if [[ "$detected_columns" =~ ^[0-9]+$ ]]; then
columns="$detected_columns"
fi
fi
if [[ -z "$columns" ]] && command -v tput >/dev/null 2>&1; then
columns="$(tput cols 2>/dev/null || true)"
fi
@@ -691,28 +708,29 @@ render_event() {
render_empty() {
local columns="$1"
local width=$((columns < 64 ? columns : 64))
local rule
rule="$(repeat_character '=' "$width")"
rule="$(repeat_character '=' "$columns")"
printf '%s%s%s\n' "$GREEN" "$rule" "$RESET"
printf '\n'
center_line "ALL CLEAR" "$width"
center_line "No current or upcoming outages." "$width"
center_line "ALL CLEAR" "$columns"
center_line "No current or upcoming outages." "$columns"
printf '\n'
printf '%s%s%s\n' "$GREEN" "$rule" "$RESET"
}
render_unavailable() {
local columns width rule
local columns="${1:-}"
local rule
color_setup
columns="$(terminal_columns)"
width=$((columns < 64 ? columns : 64))
rule="$(repeat_character '=' "$width")"
if [[ -z "$columns" ]]; then
columns="$(terminal_columns)"
fi
rule="$(repeat_character '=' "$columns")"
printf '%s%s%s\n\n' "$RED" "$rule" "$RESET"
center_line "STATE UNAVAILABLE" "$width"
center_line "Waiting for the next refresh." "$width"
center_line "STATE UNAVAILABLE" "$columns"
center_line "Waiting for the next refresh." "$columns"
printf '\n%s%s%s\n' "$RED" "$rule" "$RESET"
}
@@ -753,12 +771,14 @@ schedule_next_transition() {
render_dashboard() {
local now_epoch="$1"
local columns content_width rule phase start_epoch stop_epoch record remaining banner
local columns="${2:-}"
local rule phase start_epoch stop_epoch record remaining banner
local schedule_line ignored
color_setup
columns="$(terminal_columns)"
content_width=$((columns < 150 ? columns : 150))
if [[ -z "$columns" ]]; then
columns="$(terminal_columns)"
fi
if ((${#SCHEDULE[@]} == 0)); then
render_empty "$columns"
@@ -792,6 +812,7 @@ render_dashboard() {
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 input_fd=0
local display_columns
while (($#)); do
case "$1" in
@@ -879,11 +900,12 @@ main() {
fi
fi
display_columns="$(terminal_columns)"
frame="$(
if ((state_ready)); then
render_dashboard "$now_epoch"
render_dashboard "$now_epoch" "$display_columns"
else
render_unavailable
render_unavailable "$display_columns"
fi
if [[ -n "$REFRESH_ERROR" ]]; then
printf '\n%s\n' "$REFRESH_ERROR"