From 7481a68367b471a6a5058817342340a3e069e581 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 19 Nov 2020 02:01:46 +0100 Subject: [PATCH] display users in channel --- channel.sh | 40 ++++++++++++++++++++++++++++++++++++++-- webchat.css | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/channel.sh b/channel.sh index b930620..0f1bda7 100755 --- a/channel.sh +++ b/channel.sh @@ -28,6 +28,28 @@ case $(POST action) in ;; esac +nicklist(){ + local nickfile="${chatfile%/channel}/nicks" + case $1 in + enter) + trap 'sed -i -E "/^${SESSION_KEY%%-*} $$ /d" "$nickfile"' INT QUIT + sed -i -E "/^${SESSION_KEY%%-*} /d" "$nickfile" + printf '%s %i %s\n' "${SESSION_KEY%%-*}" "$$" "$nickname" >>"$nickfile" + ;; + leave) + sed -i -E "/^${SESSION_KEY%%-*} $$ /d" "$nickfile" + ;; + esac + + nicklist='NICKNAMES: ' + while read -r s p nick; do + nicklist="${nicklist}/$nick/" + done <"$nickfile" + if ! tail -n20 "$chatfile" |grep -qxF "$nicklist"; then + printf '%s\n' "$nicklist" >>"$chatfile" + fi +} + if [ ! -f "$chatfile" ]; then yield_page create <<-EOF [form #nonexist method="POST" @@ -36,6 +58,8 @@ if [ ! -f "$chatfile" ]; then ] EOF else + nicklist enter + printf '%s: %s\r\n' Refresh 1 { printf ' [form #channel method="POST" @@ -50,14 +74,26 @@ else printf '[div #chat' tail --pid $$ -n50 -f "$chatfile" \ | sed -nuE ' - /^[^ ]+ [^ ]+ [^ ]+$/{ + /^[0-9-]{10}_[0-9:]{8}+ [^ ]+ [^ ]+$/{ h; s;^([^ ]+) ([^ ]+) ([^ ]+)$;\1;; s;.*_;;; s;.+;[p .message [span .date &];p; g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;a\2;; bESC; :A s;.;;; s;(.)(.+);[span .nick [span .indicator \1]\2];p; g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;b\3;; bESC; :B s;.;;; s;.+;[span .message &]];p; + b; + } + /^NICKNAMES: .*/{ + s;^NICKNAMES: ;;; h; s;^.*$;[div .nicklist [h2 Nicknames];p; g; + :NICKLIST + h; s;^/([^/]+)/.*$;c\1;; bESC :C + s;^.([^?])(.*)$;[a .nick href="/~\1\2" \1\2];p; + s;^.(\?)(.*)$;[span .nick [span .indcator \1]\2];p; + g; s;/[^/]+/;;; /.+/bNICKLIST s;^.*$;];p; + b; } b; :ESC '"$UNSTRING"' '"$SHESCAPE"' - /^a/bA; /^b/bB; + /^a/bA; /^b/bB; /^c/bC; ' } |yield_page channel + + nicklist leave fi diff --git a/webchat.css b/webchat.css index 123a052..1335fe6 100644 --- a/webchat.css +++ b/webchat.css @@ -32,6 +32,7 @@ button { background-color: #FFF; border: 1px solid; border-radius: 1ex 1ex .5ex .5ex; + z-index: 2; } #settings h1 { background-color: #08b; @@ -112,7 +113,7 @@ form#channel button[value=submit] { display: none; } left: 0; right: 0; padding: 1ex; margin: .5ex; - z-index: -1; + -z-index: -1; } #chat p.message { @@ -141,3 +142,33 @@ form#channel button[value=submit] { display: none; } border-radius: 0 .5em .5em 0; padding-right: .5em; } + +#chat div.nicklist { + position: fixed; + top: 1em; bottom: 3em; + right: 0; width: 1em; + background-color: rgba(255, 255, 255, .875); + padding: .5em; + z-index: 1; + border: 1px solid black; + border-width: 1px 0 1px 1px; + overflow-y: auto; + white-space: nowrap; +} +#chat div.nicklist:hover { + width: 20%; + min-width: 10em; + white-space: normal; +} +#chat div.nicklist h2 { + font-weight: bold; + border-bottom: 1px solid black; +} +#chat div.nicklist .nick { + margin-top: .5em; + display: block; + line-height: 1.5em; +} +#chat div.nicklist a.nick { + color: #00F; +} -- 2.39.2