Version 2 of picoIRC 0.2

Updated 2004-12-05 18:24:54 by suchenwi

if 0 {Richard Suchenwirth 2004-12-05 - Here's a slight rewrite of SS' minimal IRC client (see that page) - adding

  • indentation
  • user names in bold
  • other messages in italic
  • own posts are marked in blue as a rudimentary color scheme

http://mini.net/files/irc.gif

Still, it was only 38 LOC, last time I looked :) }

 package require Tk
 set ::server irc.freenode.org
 set ::chan #tcl
 text .t -width 80 -height 30 -wrap word -font {Arial 9}
 .t tag configure bold -font [linsert [.t cget -font] end bold]
 .t tag configure italic -font [linsert [.t cget -font] end italic]
 .t tag config blue -foreground blue
 entry .cmd
 pack .cmd -side bottom -fill x
 pack .t -fill both -expand 1
 bind .cmd <Return> usercommand
 proc send str {
     puts $::fd $str
     flush $::fd
 }
 set ::fd [socket $::server 6667]
 set ::me suchenwi ;# guest[expr int(rand()*10000)]
 send "NICK $::me"
 send "USER $::me 0 * :PicoIRC user"
 send "JOIN $::chan"

 fileevent $::fd readable recv
 proc recv {} {
     gets $::fd line
     if {[regexp {:([^!]*)![^ ].* +PRIVMSG ([^ :]+) +:(.*)} $line -> \
         nick target msg]} {
        .t insert end <$nick>\t bold $msg\n
     } else {.t insert end $line\n italic}
     .t yview end
 }
 proc usercommand {} {
     set cmd [.cmd get]
     .cmd delete 0 end
     .t insert end <$::me>\t {bold blue} $cmd\n blue
     .t yview end
     send "PRIVMSG $::chan :$cmd"
 }
 bind . <Escape> {exec wish $argv0 &; exit}