#!/bin/bash #2026 miredo version="3" refresh_time=30 #strip out excess keypresses cleanbuffer() { while read -t 0 do read -N 1 -s done } #reset all colors reset_col() { echo -e -n "\033[0m" } check_scrollback() { echo "$msg_raw" | less } #set the color #usage: set_col color bold #color 30-37: blk, red, grn, ylw, blu, mag, cyn, wht #40-47 set the background color #bold is 1 or 0 set_col() { echo -e -n "\033[$2;$1m" } #sends a message via cURL #TODO: should we set our own referrer? might be useful/fun #TODO: add some color send_msg() { reset_col echo IFS= read -e -r -p "message: " mymsg curl -s \ --data-urlencode "mode=regist" \ --data-urlencode "name=$username" \ --data-urlencode "email=" \ --data-urlencode "password=" \ --data-urlencode "comment=$mymsg" \ --data-urlencode "face=" \ --data-urlencode "color=0" \ --data-urlencode "retime=0" \ --data-urlencode "lines=1" \ --data-urlencode "autoclear=on" \ https://cgi.heyuri.net/chat/comchat.cgi > /dev/null } #shows the help show_help() { reset_col clear set_col 34 1 echo "command keys:" echo "q - quit" echo "? - show this help message" echo "/ - send a message (leave the message blank to cancel)" echo "r - refresh" echo "p - view the chat scrollback (via the less command, press q to exit)" echo "other notes:" echo "* refresh the screen if you change your terminal size" echo "* any unused key will also refresh, not just r" reset_col echo "Press any key to continue." read -N 1 -s } #main program starts here, shows the intro reset_col clear set_col 36 0 echo "miredo's very very lazy comchat client for Chat@Heyuri" echo "version $version" set_col 36 1 IFS= read -e -r -p "username: " username #main loop here while true do #get terminal size scr_w=`tput cols` scr_h=`tput lines` #load and format the message list reset_col set_col 31 1 echo -n "[loading...]" cleanbuffer #TODO: handle HTML entities somehow lol (or at least find and replace " and &) #TODO: strip all control characters - probably not ever going to be an issue, but there isn't a real reason to not do it for sanity's sake msg_raw="$( curl -s https://cgi.heyuri.net/chat/simplelog.txt) " msg="$( echo "$msg_raw" | fold -s -w $scr_w | head -n $(expr $scr_h - 4) )" clear set_col 44 0 set_col 37 1 echo "[refeshed on $(date) | ($scr_w"x"$scr_h) | reload: $refresh_time"s"]" #display the messages #dumb hack that admittedly doesn't matter to show the first line in a diferent color reset_col set_col 37 1 echo "$msg" | head -n 1 reset_col echo "$msg" | tail -n +2 set_col 44 0 set_col 37 1 echo -n "keys: q-quit, /-send, r-refresh, ?-help" reset_col #handle user commands read -t $refresh_time -N 1 -s inp #quit if [[ "$inp" == "q" ]] then clear exit 1 fi #post if [[ "$inp" == "/" ]] then send_msg fi #view whole scrollback of posts if [[ "$inp" == "p" ]] then check_scrollback fi if [[ "$inp" == "?" ]] then show_help fi cleanbuffer set_col 33 1 echo -n "[refreshing...]" reset_col sleep 1 #minimum time so we don't hammer the site with a bunch of requests done