shithub: gridchat

Download patch

ref: c5437c71ae33a1623057e1db393adb4a938c03db
parent: 917a1d503a424c5d753b28aea7c9c20416ede021
author: grobe0ba <[email protected]>
date: Mon Nov 21 13:47:03 EST 2022

use ori's chat script

--- a/chat
+++ b/chat
@@ -1,112 +1,39 @@
 #!/bin/rc
-# minimal chat client for hubfs: chat [-n NICK] [-j CHANNEL] [chatsrv]
-# dd -bs `{du -n /n/chat/chat | sed 's/ .*//'} -skip 1 -if /n/chat/chat
-rfork enf
+user=be0ba
 
-fn helpmessage{
-	echo -------------------------
-	echo '/q to quit  |  /c to list channels  |  /h for help message'
-	echo '/n NICK to change nick  |  /j CHANNEL to change channels'
-	echo -------------------------
+fn chatg{
+	label chatg
+	grep -i '[^a-z0-9]'$user'([^a-z0-9]|$)' /n/chatbuf/chat | grep -v '^'$user' →' | chat-fmt
 }
 
-fn close{
-#	echo PART $name from $channel >>/n/$chatsrv/$channel
-	@{echo kill>/proc/$catkill/ctl}
+fn chati{
+	label chati
+	while(){
+		echo -n '→ ' >> /dev/text
+		read | sed '1s/^/'$user' → /' >>/n/chat/chat
+	}
 }
 
-fn shutdown{
-	close
-	exit
+fn chatv{
+	label chatv
+	</n/chatbuf/chat chat-fmt
 }
 
-fn sighup{
-	shutdown
-}
+fn chatstart{
+	9fs tcp!chat.9p.zone!9990 /n/chat
 
-fn sigint{
-	shutdown
-}
+	dims=`{read -c60 /dev/window}
+	height=`{echo $dims(5) - $dims(3) | hoc}
+	width=`{echo $dims(4) - $dims(2)| hoc}
+	hchat=`{echo $height - 200 | hoc}
 
-fn clear{
-	awk 'BEGIN{
-		for(i = 0; i < '$1'; i++)
-			printf "\x08"
-	}'
+	mq -m /n/chatbuf
+	cat /n/chat/chat > /n/chatbuf/chat &
+	window -m -r 0     0    $width     200 -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
 }
 
-channel=chat
-chatsrv=gchat
-while (~ $1 -*){
-	switch($1){
-	case -n
-		name = $2
-		shift 2
-	case -j
-		channel = $2
-		shift 2
-	case *
-		echo bad flag $1 '-n NICK -j CHANNEL'
-		shift
-	}
-}
-if(! ~ $1 '')
-	chatsrv=$1
-if(! test -e /n/$chatsrv/chat)
-	mount /srv/$chatsrv /n/$chatsrv
-if(! test -e /n/$chatsrv/chat){
-	echo 'no chat service named $chatsrv found' >[1=2]
-	exit no.chat
-}
+rfork ne
+rio -i 'rc -c chatstart'
 
-echo '		-- hubchat 0.2 --'
-helpmessage
-sleep 2
-#while(~ $#name 0){
-#	echo 'please enter a chat name:'
-#	name=`{read}
-#}
-name=be0ba
-#echo JOIN $name to $channel >>/n/$chatsrv/$channel
-
-chat-fmt </n/$chatsrv/$channel &
-catkill=$apid
-
-while(talk=`{read}){
-	clear `{echo $talk | wc -r}
-	switch($talk(1)){
-	case /q
-		shutdown
-	case /n
-			name=$talk(2)
-	case /j
-		if (~ $talk(2) '')
-			echo must specify a channel to join
-		if not if(test -e /n/chat/$talk(2)){
-			close
-			channel=$talk(2)
-			cat /n/$chatsrv/$channel &
-			catkill=$apid
-			echo JOIN $name to $channel >>/n/$chatsrv/$channel
-		}
-		if not
-			echo channel does not exist
-	case /h
-		helpmessage
-		echo currently in $channel
-		echo
-	case /c
-		echo Available channels:
-		lc /n/$chatsrv
-		echo -------------------
-		echo currently in $channel
-		echo
-	case *
-#		ts=`{date -u}
-#		ts=`{echo '('^$ts(4)^')'}
-		if(! ~ $talk ''){
-			line=`{echo $name '→ ' $talk}
-			echo $line >>/n/$chatsrv/$channel &
-		}
-	}
-}