3 proc manyset {list args} {
4 foreach val $list var $args {
10 set progname ypp-chatlog-alerter
13 proc menuent {w l a x} {
14 set c [list .mbar.$w add command -label $l -command $x]
15 if {[string length $a]} { lappend c -accel Command-$a }
22 foreach w {file edit} l {File Edit} {
23 menu .mbar.$w -tearoff 0
24 .mbar add cascade -menu .mbar.$w -label $l
26 foreach l {Open Quit} a {O Q} x {newfile exit} {
29 foreach l {Cut Copy Paste Clear} a {X C V {}} {
30 menuent edit $l $a [list event generate {[focus]} <<$l>>]]
32 . configure -menu .mbar
35 proc nonportability {} {
36 global progname defaultfile
38 switch -exact [tk windowingsystem] {
40 set defaultfile ~/Library/Preferences/$progname.prefs
43 set defaultfile ~/.$progname.rc
51 set lw_ls {times pirates messages}
52 set lw_ws {.time .pirate .msg}
55 global height lw_ws prtimes
56 listbox .time -width 5 -background black \
57 -listvariable prtimes -foreground white
58 listbox .pirate -width 14 -background black
59 listbox .msg -width 80
61 $w configure -height $height -borderwidth 0 -activestyle none \
64 eval pack $lw_ws -side left
65 label .overlay -relief raised -foreground white
68 proc shownotice {colour message} {
69 .overlay configure -text $message -background $colour
70 place .overlay -relx 0.5 -rely 0.5 -anchor center
77 global currentfile defaultfile
79 set newfile [tk_getOpenFile -multiple 0 -initialfile $currentfile \
80 -title "Select YPP log to track"]
81 if {![string length $newfile]} return
83 set currentfile $newfile
84 set newdefaults [open $defaultfile.new w]
85 puts $newdefaults "[list set currentfile $currentfile]"
87 file rename -force $defaultfile.new $defaultfile
95 set body [lindex $args end]
96 set args [lreplace $args end end]
106 set tint_switched [expr { exp( -($tint_switch+0.0) / $e_life ) }]
109 global times e_life retint_after otherevent prtimes
110 catch { after cancel $retint_after }
112 set now [clock seconds]
113 set latest $otherevent
115 foreach time $times {
116 set age [expr {$now-$time}]
118 lappend newprtimes {}
119 } elseif {$age < 120} {
120 lappend newprtimes [format "%3ds" $age]
122 lappend newprtimes [format "%3dm" [expr {$age/60}]]
124 set latest [expr { $time > $latest ? $time : $latest }]
125 set tint [expr { exp( (-($age >= 0 ? $age : 0) + 0.0) / $e_life ) }]
126 puts "AGE $age LA $latest TI $tint"
127 tintentries .msg $i $tint
130 set prtimes $newprtimes
131 set next [expr { ($now - $latest < 10 ? 10 :
132 $now - $latest > 3000 ? 3000 :
135 #puts "nexting $latest $now $next"
136 set retint_after [after $next retint]
139 proc tintentries {ws y tint} {
141 #puts "$tint $tint_switched"
142 set yellow [format "%02x" [expr {round( 255 *
143 ( $tint >= $tint_switched ? $tint : 0 )
145 set black [format "%02x" [expr {round( 255 *
146 ( $tint >= $tint_switched ? 0 : ($tint / $tint_switched)*0.75 + 0.25 )
148 set fg [format "#${black}${black}${black}"]
149 set bg [format "#${yellow}${yellow}00"]
150 foreach w $ws { $w itemconfigure $y -foreground $fg -background $bg }
154 global height otherevent
155 global times prtimes pirates messages
158 for_lw { $w delete 0 end; set $l {} }
161 for {set i 0} {$i<$height} {incr i} {
162 for_lw { lappend $l {}; $w insert end {} }
167 set otherevent [clock seconds]
174 listbox .tints -width 60 -height [expr {$divs+1}]
175 for {set y 0} {$y <= $divs} {incr y} {
176 set tint [expr {($y+0.0)/$divs}]
178 "[format "#%2d %6f %4ds" $y $tint [expr {round(
179 $tint > 0 ? -log($tint) * $e_life : "9999"
180 )}]] The quick brown fox jumped over the lazy dog"
181 tintentries .tints $y $tint
183 pack .tints -side bottom
186 proc file-read-lines {lvar body} {
188 global logfile poll_after lastactivity bufdata
191 if {![info exists logfile]} {
195 if {[catch { read $logfile } got]} {
199 #puts "f-r-l [string length $got]"
200 if {![string length $got] && [eof $logfile]} {
201 set ago [expr { [clock seconds] - $lastactivity }]
202 set interval [expr {( $ago < 10 ? 10 :
205 #puts "requeue filepoll $interval"
206 set poll_after [after $interval pollfile]
209 set lastactivity [clock seconds]
211 while {[regexp {^(.*?)[\r\n]+(.*)$} $got dummy lhs rhs]} {
222 proc file-error {emsg} {
225 shownotice red "Error reading logfile $currentfile:\n$emsg"
226 catch { close $logfile }
227 catch { unset logfile }
231 global poll_after logfile currentfile
232 global errorCode errorInfo bufdata lastactivity
234 catch { after cancel $poll_after }
235 if {![string length $currentfile]} {
236 shownotice red "No log file selected. Use File / Open."
239 if {![info exists logfile]} {
241 set lastactivity [clock seconds]
242 if {[catch { set logfile [open $currentfile r] } emsg]} {
243 shownotice red "Error opening logfile $currentfile:\n$emsg"
246 shownotice \#000080 "Reading $currentfile"
248 seek $logfile -1024 end
250 if {![string match {POSIX EINVAL *} $errorCode]} {
254 file-read-lines l { }
258 if {[regexp {^\[\d+:\d+:\d+\] (.*)} $l dummy rhs]} {
265 proc process-line {l} {
266 if {[regexp {^(\w+) tells ye, \"(.*)\"$} $l dummy pirate msg]} {
272 proc message {pirate msg} {
273 global times pirates messages height
276 set ix [lsearch -exact $pirates $pirate]
277 set now [clock seconds]
281 foreach time $times {
282 if {$time < $oldest} {
289 set $l [lreplace [set $l] $ix $ix]
294 set ix [expr {$height-1}]
296 for_lw new [list $now $pirate $msg] {
297 set $l [lreplace [set $l] $ix $ix $new]
302 .pirate itemconfigure $ix -foreground white
309 if {![string compare $arg --test-tints]} {
312 error "unknown option $arg"
323 if {[file exists $defaultfile]} {