nuno gist felülvizsgálása 1 month ago. Revízióhoz ugrás
1 file changed, 26 insertions
gistfile1.txt(fájl létrehozva)
| @@ -0,0 +1,26 @@ | |||
| 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 state | |
| 6 | + | state=$(peers::connection_state "$is_blocked" "$is_restricted" \ | |
| 7 | + | "$handshake_ts" "$last_ts") | |
| 8 | + | ||
| 9 | + | local conn_str modifier color | |
| 10 | + | IFS="|" read -r conn_str modifier color <<< "$state" | |
| 11 | + | ||
| 12 | + | # Color based on state — modifier overrides base connection color | |
| 13 | + | if [[ "$is_blocked" == "true" ]]; then | |
| 14 | + | color="\033[1;31m" # red — blocked | |
| 15 | + | elif [[ "$is_restricted" == "true" ]]; then | |
| 16 | + | color="\033[1;33m" # yellow — restricted | |
| 17 | + | elif [[ "$conn_str" == "online" ]]; then | |
| 18 | + | color="\033[1;32m" # green — online | |
| 19 | + | else | |
| 20 | + | color="\033[0;37m" # gray — offline | |
| 21 | + | fi | |
| 22 | + | ||
| 23 | + | local conn_str_padded | |
| 24 | + | conn_str_padded=$(printf "%-7s" "$conn_str") | |
| 25 | + | echo -e "${color}${conn_str_padded}\033[0m" | |
| 26 | + | } | |
Újabb
Régebbi