Author: nornagon
Date: 2005-07-06 19:40:44 -0400 (Wed, 06 Jul 2005)
New Revision: 845
Modified:
trunk/clients/ravish/eventmanager.rb
trunk/clients/ravish/haver.rb
trunk/clients/ravish/ravish2.rb
Log:
[Act: 1, 2, 3]
Modified: trunk/clients/ravish/eventmanager.rb
===================================================================
--- trunk/clients/ravish/eventmanager.rb 2005-07-06 17:03:35 UTC (rev
844)
+++ trunk/clients/ravish/eventmanager.rb 2005-07-06 23:40:44 UTC (rev
845)
@@ -40,7 +40,9 @@
ret = select(readhand, writehand, errorhand, nexttimer)
if !ret then ret = [[],[],[]] end
- ret[0].delete @pipe[0]
+ if ret[0].delete @pipe[0]
+ @pipe[0].read 1
+ end
ret[0].each { |fd| @fdread[fd].values.each { |c| c.call fd } }
ret[1].each { |fd| @fdwrite[fd].values.each { |c| c.call fd } }
Modified: trunk/clients/ravish/haver.rb
===================================================================
--- trunk/clients/ravish/haver.rb 2005-07-06 17:03:35 UTC (rev 844)
+++ trunk/clients/ravish/haver.rb 2005-07-06 23:40:44 UTC (rev 845)
@@ -7,7 +7,7 @@
class Client
include Observable
- def initialize server, port=7070, hash={}
+ def initialize server, port=7575, hash={}
@server = server.to_s
@port = port.to_i
@conf = hash.to_hash
Modified: trunk/clients/ravish/ravish2.rb
===================================================================
--- trunk/clients/ravish/ravish2.rb 2005-07-06 17:03:35 UTC (rev 844)
+++ trunk/clients/ravish/ravish2.rb 2005-07-06 23:40:44 UTC (rev 845)
@@ -1,6 +1,6 @@
# ravish -- Haver client written in ruby. Second attempt.
-$:.unshift "lib"
+$:.unshift "/home/nornagon/dev/termvisual/lib"
require 'term/visual'
require 'haver'
@@ -8,6 +8,16 @@
Thread.abort_on_exception = true
class Ravish
+ class Window
+ attr_reader :window, :type, :name
+ def initialize window, type, args={}
+ @window = window
+ @type = type
+ @args = args
+ @name = args['name']
+ end
+ def [](*args); @args[*args]; end
+ end
ServerPrefix = "%(bblue)-%(bwhite)!%(bblue)-%(default) "
Palette = {
@@ -23,6 +33,10 @@
'nick' => 'de on de',
'donick' => 'bold de on de',
'mynick' => 'bold de on de',
+ 'statdecs' => 'cyan on blue',
+ 'lowact' => 'cyan on blue',
+ 'medact' => 'bold white on blue',
+ 'highact' => 'bold purple on blue',
}
Bindings = {
@@ -30,11 +44,11 @@
|k| "A-#{k}" } => :switch_window
}
- def initialize server, port=7070
+ def initialize server, port=7575
@term = Term::Visual.new
@term.palette.setcolors Palette
@term.global_prefix = self.method :global_prefix
- @term.on_got_line self.method(:got_line)
+ @term.on_got_line self.method(:got_curses_line)
Bindings.each { |k, v|
if v.kind_of? Symbol
v = self.method v
@@ -47,8 +61,10 @@
@term.bind k, v
end
}
- @servwin = @term.create_window('title' => 'Ravish')
- @windows = [['(server)', @servwin]]
+ @servwin = Window.new(@term.create_window('title' => server),
:server,
+ 'server' => server, 'port' => port, 'name' =>
server)
+ @windows = [EMAIL PROTECTED]
+ statbar_wheel
@server = server
@port = port
@haver = Haver::Client.new server
@@ -60,13 +76,7 @@
Time.now.strftime "%H:%M:%S "
end
- def srvmsg *args
- args.each { |arg|
- @servwin.addline arg, ServerPrefix
- }
- end
-
- def got_line line
+ def got_curses_line line
if line =~ /^[.\/]{1,2}([^.\/].*)/
# command
args = $1.split(/ /)
@@ -109,48 +119,91 @@
## HELPER METHODS ##
- def find_window name
- if name.kind_of?(Term::Visual::Window)
- @windows.rassoc(name)
+ def srvmsg *args
+ args.each { |arg|
+ @servwin.window.addline arg, ServerPrefix
+ }
+ activity @servwin, 1
+ end
+
+ def find_window type, arg=nil
+ if type.kind_of?(Term::Visual::Window)
+ @windows.find { |w| w.window == type }
+ elsif arg.kind_of?(Hash)
+ @windows.find { |w|
+ h = arg.select { |k, v|
+ w[k] == v
+ }
+ h == arg.to_a
+ }
else
- @windows.assoc(name)
+ @windows.find { |w|
+ w.type == type and (!arg or w.name == arg)
+ }
end
end
+ def activity win, num
+ @act ||= []
+ return if @term.current_window == win.window
+
+ index = @windows.index(win)
+ n = -1
+ if @act.find { |i| n += 1; i[0] == index }
+ if @act[n][1] < num
+ @act[n][1] = num
+ end
+ else
+ @act << [index, num]
+ end
+ end
+
## TERM HANDLING ##
def switch_window ch
- win = nil
- if ch == ?1 then win = 1
- elsif ch == ?2 then win = 2
- elsif ch == ?3 then win = 3
- elsif ch == ?4 then win = 4
- elsif ch == ?5 then win = 5
- elsif ch == ?6 then win = 6
- elsif ch == ?7 then win = 7
- elsif ch == ?8 then win = 8
- elsif ch == ?9 then win = 9
- elsif ch == ?0 then win = 10
- elsif ch == ?q then win = 11
- elsif ch == ?w then win = 12
- elsif ch == ?e then win = 13
- elsif ch == ?r then win = 14
- elsif ch == ?t then win = 15
- elsif ch == ?y then win = 16
- elsif ch == ?u then win = 17
- elsif ch == ?i then win = 18
- elsif ch == ?o then win = 19
- else
- return
- end
- if @windows[win-1] and to = @windows[win-1][1]
+ keys = { ?1 => 1, ?2 => 2, ?3 => 3, ?4 => 4, ?5 => 5, ?6 => 6,
?7 => 7,
+ ?8 => 8, ?9 => 9, ?0 => 10, ?q => 11, ?w => 12, ?e =>
13, ?r => 14,
+ ?t => 15, ?y => 16, ?u => 17, ?i => 18, ?o => 19 }
+ win = keys[ch] or return
+ if @windows[win-1] and to = @windows[win-1].window
+ @act.delete_if { |a| a[0] == win - 1 }
unless to == @term.current_window
- srvmsg "switching to window #{win-1}
(A-#{ch.chr}) (#{to})"
@term.switch_window to
+ statbar_update
end
end
end
+ def statbar_wheel arg=nil
+ statbar_update
+ EventManager.instance.in 0.5, self.method(:statbar_wheel)
+ end
+
+ def statbar_update
+ win = find_window(@term.current_window)
+ winnum = @windows.index(win) + 1
+ status =
+ "%(statdecs)[%(status)" + Time.now.strftime("%H:%M:%S")
+
+ "%(statdecs)]%(status) %(statdecs)[%(status)[EMAIL
PROTECTED]" +
+ "%(statdecs)]%(status) %(statdecs)[%(status)#{winnum}" +
+ (win.type == :query ? '.' : ':') + win.name +
+ "%(statdecs)]%(status)"
+ if @act and [EMAIL PROTECTED]
+ status += " %(statdecs)[%(status)Act: " +
+ @act.collect { |a|
+ if a[1] == 3
+ "%(highact)#{a[0] + 1}"
+ elsif a[1] == 2
+ "%(medact)#{a[0] + 1}"
+ else
+ "%(lowact)#{a[0] + 1}"
+ end
+ }.join("%(statdecs),%(status) ") +
+ "%(statdecs)]%(status)"
+ end
+ win.window.status = status
+ end
+
## SERVER MESSAGES ##
def unknown_ev cmd, args
@@ -161,11 +214,13 @@
def ev_HAVER server, version
srvmsg "Server #{server} running #{version}"
@haver.msg 'IDENT', 'nornagon'
+ activity @servwin, 2
end
def ev_HELLO nick
srvmsg "Server accepted uid #{nick}"
@nick = nick
+ activity @servwin, 2
end
def ev_PING data
@@ -173,15 +228,20 @@
end
def ev_JOIN cid, uid
+ win = find_window :channel, cid
if @nick and uid == @nick
- unless (win = find_window cid)
+ unless win
win = @term.create_window('title' => cid)
- @windows << [cid, win]
+ @windows << Window.new(win, :channel,
+ 'name' => cid, 'channel' => cid)
@term.switch_window win
end
@haver.msg 'LIST', cid, 'user'
- elsif win = find_window(cid)
- win[1].print "#{uid} has joined #{cid}"
+ elsif win
+ win.window.print "#{uid} has joined #{cid}"
+ activity win, 1
+ else
+ srvmsg "Stray JOIN: #{uid} has joined #{cid}"
end
end
@@ -193,7 +253,7 @@
else
listed = ns
end
- win = find_window(cid)[1] || @servwin
+ win = find_window(:channel, cid).window || @servwin
win.print "%(listdecs)[%(listtitle)#{listed} %(listcid)#{cid}"+
"%(listdecs)]%(default)"
users.sort!
@@ -208,10 +268,11 @@
elsif type == 'do'
pref = "%(donick)* #{uid}%(default) "
end
- if win = find_window(cid)
- win[1].addline msg.join(' '), pref
+ if win = find_window(:channel, cid)
+ activity win, 2
+ win.window.addline msg.join(' '), pref
else
- @servwin.addline msg.join, "#{cid}:#{pref}"
+ srvmsg msg.join(' '), "Stray IN: #{cid}:#{pref}"
end
end
@@ -223,26 +284,42 @@
def user_nocmd line
win = find_window(@term.current_window)
- unless win[0] == '(server)'
- @haver.msg 'IN', win[0], 'say', line
+ case win.type
+ when :channel
+ @haver.msg 'IN', win['channel'], 'say', line
+ when :query
+ @haver.msg 'TO', win['uid'], 'say', line
end
end
+
+ def user_RAW args
+ @haver.msg args.shift.upcase, *args
+ end
def user_SAY args
win = find_window(@term.current_window)
- unless win[0] == '(server)'
- @haver.msg 'IN', win[0], 'say', args.join(' ')
+ case win.type
+ when :channel
+ @haver.msg 'IN', win['channel'], 'say', args.join(' ')
+ when :query
+ @haver.msg 'TO', win['uid'], 'say', args.join(' ')
end
end
def user_ME line
win = find_window(@term.current_window)
- unless win[0] == '(server)'
- @haver.msg 'IN', win[0], 'do', line
+ case win.type
+ when :channel
+ @haver.msg 'IN', win['channel'], 'do', line
+ when :query
+ @haver.msg 'TO', win['uid'], 'do', line
end
end
def user_JOIN args
+ if args.length < 1
+ srvmsg "JOIN: Not enough arguments"
+ end
@haver.msg 'JOIN', args[0]
end
@@ -251,14 +328,10 @@
@haver.msg 'LIST', args[0], args[1]
elsif args[0] and not args[1]
@haver.msg 'LIST', args[0], 'user'
- elsif win = find_window(@term.current_window) and win[0] !=
'(server)'
- @haver.msg 'LIST', win[0], 'user'
+ elsif win = find_window(@term.current_window) and win.type ==
:channel
+ @haver.msg 'LIST', win['channel'], 'user'
end
end
-
- def user_RAW args
- @haver.msg args.shift.upcase, *args
- end
end
ravish = Ravish.new 'hardison.net'