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 logfile
79 set newfile [tk_getOpenFile -multiple 0 -initialfile $currentfile \
80 -title "Select YPP log to track"]
81 if {![string length $newfile]} return
83 catch { close $logfile }
84 catch { unset logfile }
86 set currentfile $newfile
87 set newdefaults [open $defaultfile.new w]
88 puts $newdefaults "[list set currentfile $currentfile]"
90 file rename -force $defaultfile.new $defaultfile
98 set body [lindex $args end]
99 set args [lreplace $args end end]
109 set tint_switched [expr { exp( -($tint_switch+0.0) / $e_life ) }]
112 global times e_life retint_after otherevent prtimes
113 catch { after cancel $retint_after }
115 set now [clock seconds]
116 set latest $otherevent
118 foreach time $times {
119 set age [expr {$now-$time}]
121 lappend newprtimes {}
122 } elseif {$age < 60} {
123 lappend newprtimes [format "%3ds" $age]
125 lappend newprtimes [format "%3dm" [expr {$age/60}]]
127 set latest [expr { $time > $latest ? $time : $latest }]
128 set tint [expr { exp( (-($age >= 0 ? $age : 0) + 0.0) / $e_life ) }]
129 #puts "AGE $age LA $latest TI $tint"
130 tintentries .msg $i $tint
133 set prtimes $newprtimes
134 set next [expr { ($now - $latest < 10 ? 10 :
135 $now - $latest > 3000 ? 3000 :
138 #puts "nexting $latest $now $next"
139 set retint_after [after $next retint]
142 proc tintentries {ws y tint} {
144 #puts "$tint $tint_switched"
145 set yellow [format "%02x" [expr {round( 255 *
146 ( $tint >= $tint_switched ? $tint : 0 )
148 set black [format "%02x" [expr {round( 255 *
149 ( $tint >= $tint_switched ? 0 : ($tint / $tint_switched)*0.75 + 0.25 )
151 set fg [format "#${black}${black}${black}"]
152 set bg [format "#${yellow}${yellow}00"]
153 foreach w $ws { $w itemconfigure $y -foreground $fg -background $bg }
157 global height otherevent
158 global times prtimes pirates messages
161 for_lw { $w delete 0 end; set $l {} }
164 for {set i 0} {$i<$height} {incr i} {
165 for_lw { lappend $l {}; $w insert end {} }
170 set otherevent [clock seconds]
177 listbox .tints -width 60 -height [expr {$divs+1}]
178 for {set y 0} {$y <= $divs} {incr y} {
179 set tint [expr {($y+0.0)/$divs}]
181 "[format "#%2d %6f %4ds" $y $tint [expr {round(
182 $tint > 0 ? -log($tint) * $e_life : "9999"
183 )}]] The quick brown fox jumped over the lazy dog"
184 tintentries .tints $y $tint
186 pack .tints -side bottom
189 proc file-read-lines {lvar body} {
191 global logfile poll_after lastactivity bufdata
194 if {![info exists logfile]} {
198 if {[catch { read $logfile } got]} {
202 #puts "f-r-l [string length $got]"
203 if {![string length $got] && [eof $logfile]} {
204 set ago [expr { [clock seconds] - $lastactivity }]
205 set interval [expr {( $ago < 10 ? 10 :
208 #puts "requeue filepoll $interval"
209 set poll_after [after $interval pollfile]
212 set lastactivity [clock seconds]
214 while {[regexp {^(.*?)[\r\n]+(.*)$} $got dummy lhs rhs]} {
225 proc file-error {emsg} {
228 shownotice red "Error reading logfile $currentfile:\n$emsg"
229 catch { close $logfile }
230 catch { unset logfile }
234 global poll_after logfile currentfile
235 global errorCode errorInfo bufdata lastactivity
237 catch { after cancel $poll_after }
238 if {![string length $currentfile]} {
239 shownotice red "No log file selected. Use File / Open."
242 if {![info exists logfile]} {
244 set lastactivity [clock seconds]
245 if {[catch { set logfile [open $currentfile r] } emsg]} {
246 shownotice red "Error opening logfile $currentfile:\n$emsg"
249 shownotice \#000080 "Reading $currentfile"
251 seek $logfile -1024 end
253 if {![string match {POSIX EINVAL *} $errorCode]} {
257 file-read-lines l { }
261 if {[regexp {^\[\d+:\d+:\d+\] (.*)} $l dummy rhs]} {
268 proc process-line {l} {
269 if {[regexp {^(\w+) tells ye, \"(.*)\"$} $l dummy pirate msg]} {
275 proc message {pirate msg} {
276 global times pirates messages height
279 set ix [lsearch -exact $pirates $pirate]
280 set now [clock seconds]
284 foreach time $times {
285 if {$time < $oldest} {
292 set $l [lreplace [set $l] $ix $ix]
297 set ix [expr {$height-1}]
299 for_lw new [list $now $pirate $msg] {
300 set $l [lreplace [set $l] $ix $ix $new]
305 .pirate itemconfigure $ix -foreground white
312 if {![string compare $arg --test-tints]} {
315 error "unknown option $arg"
326 if {[file exists $defaultfile]} {