~aleteoryx/tclircc

133ef83a37963e0684f69e86ddae35da29ba573c — aleteoryx a month ago eb4eaa5
basic ui things
2 files changed, 47 insertions(+), 44 deletions(-)

M main.tcl
A uiMain.tcl
M main.tcl => main.tcl +11 -44
@@ 1,53 1,20 @@
#!/bin/env tclsh

lappend auto_path /usr/lib/tcllib1.21
package require logger
set log [logger::init tclircc]
set path [file dirname [dict get [info frame 0] file]]

source irc.tcl
source cap.tcl
package require Thread
package require logger
set log [logger::init tclircc::main]

puts "connecting to testnet.ergo.chat"
set chan [irc::connect testnet.ergo.chat 6697 1]
#set chan [irc::connect localhost 8000 0]
${log}::info {tclircc 0.0.1 <https://amehut.dev/~aleteoryx/tclircc>}
${log}::info "running from $path"

irc::handler add $chan * {
  ${log}::debug [dict get $dispatch rawmsg]
${log}::debug "starting ui thread"
set ui_thread [thread::create -preserved]
if {[thread::send $ui_thread [list source "$path[file separator]/uiMain.tcl"] result] == 1} {
  ${log}::critical "couldn't start ui thread: $result"
  exit -1
}

proc nocap {dispatch} {
  if {[dict get $dispatch cmd] == "CAP"} {
    uplevel #0 {${log}::info "GET TROLLED, CAP BLOCKED"}
    return true
  }
}

irc::interceptor add $chan nocap

#irc::handler add $chan CAP {
#  ${log}::debug "parsing cap ls"
#  set parsed [cap::parse_msg [dict get $dispatch params]]
#  dict for {k v} $parsed {
#    if {$k == "caps"} {
#      ${log}::debug "$k:"
#      dict for {k v} $v {
#        ${log}::debug "  $k: $v"
#      }
#    } else {
#      ${log}::debug "$k: $v"
#    }
#  }
#}

cap::negotiate $chan
cap::support $chan message-tags

puts [irc::meta get $chan]

irc::listen on $chan

#${log}::info "requesting CAPs"
#irc::msg send $chan CAP LS 302

${log}::info "entering event loop"
vwait nil

A uiMain.tcl => uiMain.tcl +36 -0
@@ 0,0 1,36 @@
#!/bin/env tclsh

set path [file dirname [dict get [info frame 0] file]]

variable toplevel_count 0

package require logger
set log [logger::init tclircc::ui]

${log}::debug "loading tk"
package require Tk
wm withdraw .
# TODO: tray handling

proc mkToplevel {varname {takefocus 0}} {
  variable toplevel_count
  upvar $varname window
  set window .win$toplevel_count
  toplevel $window -takefocus $takefocus
  incr toplevel_count

  wm title $window "tclircc - $window"

  menu $window.menu
  menu $window.menu.me
  $window configure -menu "$window.menu"

  $window.menu add cascade -label "tclircc" -menu $window.menu.me
  $window.menu.me add command -label "About" -command {
    tk_messageBox -title "About tclircc" \
                  -message "tclircc v0.0.1" \
                  -detail "by Aleteoryx\nhttps://amehut.dev/~aleteoryx/tclircc\n\nThis software is in the public domain." \
                  -type ok }
}

mkToplevel _