wgctl/modules/ui/policy.module.sh
Nuno Duque Nunes 1a78dcf5da feat: display config, table layouts for all commands
- display.module.sh: style toggle per view (compact/table)
- display.json: default config with all views set to compact
- ctx::display: points to .wgctl/config/display.json
- list: _render_table with dynamic widths, colors, shared row_color/status_color
- group/identity/net/hosts/activity: _render_table added
- rule/subnet/policy: table UI functions + _render_table
- ui::peer::status_color: \033[2m for offline (dimmer, more readable)
- note: individual table layout refinements pending cleanup pass
- note: configurable colors per field deferred to display config v2
2026-05-27 03:32:31 +00:00

45 lines
No EOL
1.3 KiB
Bash

#!/usr/bin/env bash
function ui::policy::list_row() {
local name="${1:-}" default_rule="${2:-}" strict="${3:-}" auto="${4:-}"
local rule_val="-"
[[ -n "$default_rule" ]] && rule_val="$default_rule"
local rule_padded
rule_padded=$(printf "%-16s" "$rule_val")
local strict_display
[[ "$strict" == "true" ]] && strict_display="yes" || strict_display="no"
local strict_padded
strict_padded=$(printf "%-4s" "$strict_display")
local auto_display=""
[[ "$auto" == "false" ]] && auto_display=" \033[2mauto:\033[0m no"
printf " %-14s \033[2mrule:\033[0m %s \033[2mstrict:\033[0m %s%s\n" \
"$name" "$rule_padded" "$strict_padded" "$auto_display"
}
function ui::policy::detail_field() {
local key="${1:-}" value="${2:-}"
ui::row "$key" "$value"
}
# ======================================================
# Table view
# ======================================================
function ui::policy::list_header_table() {
printf "\n %-16s %-8s %-14s %-8s %s\n" \
"NAME" "TUNNEL" "DEFAULT RULE" "STRICT" "AUTO"
printf " %s\n" "$(printf '─%.0s' {1..60})"
}
function ui::policy::list_row_table() {
local name="${1:-}" tunnel="${2:-}" default_rule="${3:-}" \
strict="${4:-}" auto="${5:-}"
printf " %-16s %-8s %-14s %-8s %s\n" \
"$name" "$tunnel" "${default_rule:--}" "$strict" "$auto"
}