shithub: gridchat

ref: 1484fc83f17c4b303eb7620479f7f87f781779fb
dir: /chat/

View raw version
#!/bin/rc
# chat - a gridchat client
# usage: chat
# requires:
#	- chat-fmt
#	- mq (https://shithub.us/ori/mq/HEAD/info.html)
#	- newsrv
#	- LABEL

if(~ $#nick 1)
	user=$nick

fn chatg{
	label chatg
	grep -i '[^a-z0-9]'$user'([^a-z0-9]|$)' /n/chatbuf/chat | grep -v '^'$user' →' | chat-fmt
}

fn chati{
	label chati
	while(){
		echo -n '→ ' >> /dev/text
		read | sed '1s/^/'$user' → /' >>/n/chat/chat
	}
}

fn chatv{
	label chatv
	</n/chatbuf/chat chat-fmt
}

fn chatstart{
	srv tcp!chat.tcp80.org!9990 chat.$pid
	mount /srv/chat.$pid /n/chat tail:0

	dims=`{read -c60 /dev/window}
	height=`{echo $dims(5) - $dims(3) | hoc}
	width=`{echo $dims(4) - $dims(2)| hoc}
	hchat=`{echo $height - 200 | hoc}

	mq -c -m /n/chatbuf -s mq.$pid
	cat /n/chat/chat > /n/chatbuf/chat &
	window -m -r 0     0    $width     100 -scroll rc -c chatg
	window -m -r 0   100    $width  $hchat -scroll rc -c chatv
	window -m -r 0  $hchat  $width $height -scroll rc -c chati
}

rfork ne
window 880,40,1560,860 newsrv 'LABEL gridchat; rio -i ''rc -c chatstart'''