wm: gchat

Download patch

ref: 375d7fb8b6eee1f02f66136cb0532df757fce724
author: mkf <mkf@cloud9p.org>
date: Mon Sep 4 08:16:59 EDT 2023

import sources

--- /dev/null
+++ b/gchat
@@ -1,0 +1,117 @@
+#!/bin/rc
+# public domain or ISC or MIT
+cat=cat # one might want to use read instead.
+datefmt='hh:mm'
+server=tcp!cloud9p.org!900
+
+nick=$user
+room=chat
+mnt=/n/chat/
+seprator=' >'
+
+tls=false
+bs=false
+date=false
+annoying=false
+
+# wont work in acme well.
+fn clear {
+	awk 'BEGIN {
+		for(i = 0; i < '$1'+1; i++)
+			printf "\x08"
+	}'
+}
+
+fn readchat {
+	if(test -f $mnt^$room)
+	{
+		cat $mnt^$room &
+	}
+	if not
+	{
+		echo 'no such room exist' >[1=2]
+		exit 'no room'
+	}
+}
+
+fn writechat {
+	if(test -w $mnt^$room) {
+		while() {
+			cat >/env/message
+			
+			# bs and annoy can be buggy together
+			if(! ~ $bs false && ~ $annoy false)
+				clear `{cat /env/message | wc -r} #i
+
+			if(! ~ $date false) {
+				d=`{date -u -f $datefmt}
+				echo -n $d > /env/x
+			
+			}
+				echo -n $nick^$seprator^' '> /env/x
+
+			if(~ $annoying false) {
+				cat /env/x /env/message >>$mnt^$room
+			}
+			if not
+			{
+				ifs=' ' annoy=`{cat /env/message}
+				cat /env/x >> $mnt^$room
+				for(i in $annoy) {
+					echo -n ' '$i >> $mnt^$room
+					sleep 0.01
+				}
+			}
+		}
+	}
+	if not {
+		echo 'room is read-only'
+		exit 'read-only room'
+	}
+}
+
+while (~ $1 -*) {
+	switch ($1) {
+	case -a
+		annoying=YEAH
+	case -b
+		bs=t
+	case -d
+		date=t
+	case -f
+		datefmt=$2
+		date=t
+		shift
+	case -n
+		nick=$2
+		shift
+	case -r
+		room=$2
+		shift
+	case -s
+		seprator=$2
+		shift
+	case -*
+		echo 'usage: gchat [-abd] [-f datefmt] [-n nick] [-r room] [-s seprator] [server]' >[1=2]
+		exit 'usage'	
+	}
+	shift
+}
+
+if (~ $#* 1) {
+	switch ($1) {
+	case 9pzone
+		server=tcp!chat.9p.zone!9990
+
+	case cloud9p
+		server=tcp!cloud9p.org!900
+	case *
+		server=$1
+	}
+}
+
+9fs $server $mnt
+label $server: $mnt^$room
+
+readchat
+writechat