setopt localoptions extendedglob clobber

integer idx is_locked
local name busyfile busywith

for (( idx = 1; idx <= 100; idx ++ )); do
    name=""
    busywith=""

    __zconvey_is_session_active "$idx" && is_locked=1 || is_locked=0

    __zconvey_get_name_of_id "$idx"
    name="$REPLY"

    busyfile="$ZCONVEY_OTHER_DIR/${idx}.busy"
    [[ -e "$busyfile" && "$idx" != "$ZCONVEY_ID" ]] && busywith=" \033[1;33m(BUSY: $(<$busyfile))\033[0m"

    if [[ "$is_locked" = "0" && -n "$name" ]]; then
        print "\033[1;31m(ABSENT)\033[0m  ID: $idx, NAME: $name"
    elif [[ "$is_locked" = "0" && -z "$name" ]]; then
        # Don't inform about absent, nameless sessions
        :
    elif [[ "$is_locked" = "1" && -z "$name" ]]; then
        if [ "$idx" = "$ZCONVEY_ID" ]; then
            print "\033[1;32m\033[4m(CURRENT) ID: $idx\033[0m$busywith"
        else
            print "\033[1;33m(ON-LINE)\033[0m ID: $idx$busywith"
        fi
    elif [[ "$is_locked" = "1" && -n "$name" ]]; then
        if [ "$idx" = "$ZCONVEY_ID" ]; then
            print "\033[1;32m\033[4m(CURRENT) ID: $idx, NAME: $name\033[0m$busywith"
        else
            print "\033[1;33m(ON-LINE)\033[0m ID: $idx, NAME: $name$busywith"
        fi
    fi
done

# vim:ft=zsh
