gistfile1.txt
· 1.7 KiB · Text
Eredeti
function peers::format_status() {
local name="${1:-}" public_key="${2:-}" is_blocked="${3:-false}"
local is_restricted="${4:-false}" handshake_ts="${5:-0}" last_ts="${6:-}"
local connected=false modifier="" color
if [[ "$is_blocked" == "true" ]]; then
local now attempt_ts diff
now=$(date +%s)
attempt_ts=$(json::iso_to_ts "$last_ts")
diff=$(( now - attempt_ts ))
(( diff < "$(config::handshake_time_sec)" )) && connected=true
modifier=" (blocked)"
color="\033[1;31m"
elif [[ "$is_restricted" == "true" ]]; then
local now diff
now=$(date +%s)
diff=$(( now - handshake_ts ))
(( diff < "$(config::handshake_time_sec)" )) && connected=true
modifier=" (restricted)"
color="\033[1;33m"
else
local now diff
now=$(date +%s)
diff=$(( now - handshake_ts ))
(( diff < "$(config::handshake_time_sec)" )) && connected=true
if $connected; then color="\033[1;32m"; else color="\033[0;37m"; fi
fi
local conn_str
$connected && conn_str="online" || conn_str="offline"
echo -e "${color}${conn_str}${modifier}\033[0m"
}
function peers::format_last_seen() {
local name="${1:-}" pubkey="${2:-}" is_blocked="${3:-false}"
local last_ts="${4:-}" last_evt="${5:-}" handshake_ts="${6:-0}"
if [[ "$is_blocked" == "true" ]]; then
if [[ -n "$last_ts" && "$last_ts" != "0" && "$last_ts" != "null" ]]; then
local formatted
formatted=$(fmt::datetime_iso "$last_ts")
echo "${formatted} (dropped)"
else
echo "—"
fi
else
if [[ -z "$handshake_ts" || "$handshake_ts" == "0" ]]; then
echo "—"
else
local formatted
formatted=$(fmt::datetime "$handshake_ts")
echo "${formatted} (handshake)"
fi
fi
}
| 1 | function peers::format_status() { |
| 2 | local name="${1:-}" public_key="${2:-}" is_blocked="${3:-false}" |
| 3 | local is_restricted="${4:-false}" handshake_ts="${5:-0}" last_ts="${6:-}" |
| 4 | |
| 5 | local connected=false modifier="" color |
| 6 | |
| 7 | if [[ "$is_blocked" == "true" ]]; then |
| 8 | local now attempt_ts diff |
| 9 | now=$(date +%s) |
| 10 | attempt_ts=$(json::iso_to_ts "$last_ts") |
| 11 | diff=$(( now - attempt_ts )) |
| 12 | (( diff < "$(config::handshake_time_sec)" )) && connected=true |
| 13 | modifier=" (blocked)" |
| 14 | color="\033[1;31m" |
| 15 | elif [[ "$is_restricted" == "true" ]]; then |
| 16 | local now diff |
| 17 | now=$(date +%s) |
| 18 | diff=$(( now - handshake_ts )) |
| 19 | (( diff < "$(config::handshake_time_sec)" )) && connected=true |
| 20 | modifier=" (restricted)" |
| 21 | color="\033[1;33m" |
| 22 | else |
| 23 | local now diff |
| 24 | now=$(date +%s) |
| 25 | diff=$(( now - handshake_ts )) |
| 26 | (( diff < "$(config::handshake_time_sec)" )) && connected=true |
| 27 | if $connected; then color="\033[1;32m"; else color="\033[0;37m"; fi |
| 28 | fi |
| 29 | |
| 30 | local conn_str |
| 31 | $connected && conn_str="online" || conn_str="offline" |
| 32 | echo -e "${color}${conn_str}${modifier}\033[0m" |
| 33 | } |
| 34 | |
| 35 | function peers::format_last_seen() { |
| 36 | local name="${1:-}" pubkey="${2:-}" is_blocked="${3:-false}" |
| 37 | local last_ts="${4:-}" last_evt="${5:-}" handshake_ts="${6:-0}" |
| 38 | |
| 39 | if [[ "$is_blocked" == "true" ]]; then |
| 40 | if [[ -n "$last_ts" && "$last_ts" != "0" && "$last_ts" != "null" ]]; then |
| 41 | local formatted |
| 42 | formatted=$(fmt::datetime_iso "$last_ts") |
| 43 | echo "${formatted} (dropped)" |
| 44 | else |
| 45 | echo "—" |
| 46 | fi |
| 47 | else |
| 48 | if [[ -z "$handshake_ts" || "$handshake_ts" == "0" ]]; then |
| 49 | echo "—" |
| 50 | else |
| 51 | local formatted |
| 52 | formatted=$(fmt::datetime "$handshake_ts") |
| 53 | echo "${formatted} (handshake)" |
| 54 | fi |
| 55 | fi |
| 56 | } |