wgctl/modules/ui/subnet.module.sh
Nuno Duque Nunes 8bb1de4976 init feature
2026-05-19 15:26:31 +00:00

51 lines
No EOL
1.5 KiB
Bash

#!/usr/bin/env bash
# ui/subnet.module.sh — rendering for subnet data
# All functions pure rendering — no writes, no state changes.
function ui::subnet::header() {
printf " %-14s %-18s %-10s %-8s %s\n" \
"NAME" "SUBNET" "TYPE" "TUNNEL" "DESCRIPTION"
ui::divider 70
}
function ui::subnet::row() {
local display_name="${1:-}" subnet="${2:-}" type_key="${3:-}" \
tunnel_mode="${4:-}" desc="${5:-}" is_group="${6:-false}"
local name_col="$display_name"
[[ "$is_group" == "true" ]] && name_col=" ${display_name}"
printf " %-14s %-18s %-10s %-8s %s\n" \
"$name_col" "$subnet" "$type_key" "$tunnel_mode" "$desc"
}
function ui::subnet::group_separator() {
echo ""
}
function ui::subnet::detail() {
local name="${1:-}" is_group="${2:-false}"
ui::row "Name" "$name"
ui::row "Type" "$( [[ "$is_group" == "true" ]] && echo "group" || echo "scalar" )"
}
function ui::subnet::detail_field() {
local key="${1:-}" value="${2:-}"
ui::row "$key" "$value"
}
function ui::subnet::child_header() {
printf "\n"
printf " %-12s %-18s %-8s %s\n" "TYPE" "SUBNET" "TUNNEL" "DESCRIPTION"
ui::divider 56
}
function ui::subnet::child_row() {
local type_key="${1:-}" subnet="${2:-}" tunnel_mode="${3:-}" desc="${4:-}"
printf " %-12s %-18s %-8s %s\n" "$type_key" "$subnet" "$tunnel_mode" "$desc"
}
function ui::subnet::peers_in_use() {
local peers_csv="${1:-}"
[[ -z "$peers_csv" ]] && return 0
echo ""
ui::row "Peers using" "${peers_csv//,/, }"
}