lijab 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,174 @@
1
+ require 'lijab/input'
2
+ require 'lijab/term/ansi'
3
+ require 'monitor'
4
+ require 'readline'
5
+ require 'readline/extra'
6
+
7
+ include Term
8
+
9
+ module Lijab
10
+
11
+ module Out
12
+
13
+ @monitor = Monitor.new
14
+ @time = Time.now
15
+
16
+ module_function
17
+
18
+ def put(s="\n", redisplay_input=false)
19
+ print "#{ANSI.clearline}#{s}\n#{ANSI.clearline}"
20
+ STDOUT.flush
21
+ InputHandler::redisplay_input if redisplay_input
22
+ end
23
+
24
+ def notice_if_day_changed(redisplay_input=true)
25
+ t = Time.now
26
+ if @time.day != t.day
27
+ ft = @time.strftime('%Y-%M-%d')
28
+ @time = t
29
+ puts "#{ANSI.clearline}** day changed -- #{ft} -> #{Date.today}".green
30
+ end
31
+ end
32
+
33
+ def format_time(time=nil, format=:datetime_format)
34
+ return "" unless time
35
+ time = Time.now if time == :now
36
+
37
+ "#{time.strftime(Config.opts[format])} "
38
+ end
39
+
40
+ def format_message_in(from, text, colors, time)
41
+ "#{ANSI.clearline}#{time}#{from} -> ".colored(*colors) + text
42
+ end
43
+
44
+ def format_message_out(to, text, colors, time)
45
+
46
+ prefix = "#{time}#{to} <- "
47
+ indent = " " * prefix.length
48
+
49
+ lines = text.to_a
50
+ s = []
51
+
52
+ s << "#{ANSI.clearline}#{prefix.colored(*colors)}#{lines.shift.chomp}"
53
+ lines.each do |l|
54
+ s << "#{ANSI.clearline}#{indent}#{l.chomp}"
55
+ end
56
+
57
+ s.join("\n")
58
+ end
59
+
60
+ def message_in(from, text, colors=[])
61
+ @monitor.synchronize do
62
+ clear_infoline()
63
+ InputHandler::delete_typed
64
+
65
+ notice_if_day_changed()
66
+
67
+ print "\a" if Config.opts[:terminal_bell_on_message]
68
+ puts format_message_in(from, text, colors, format_time(:now))
69
+
70
+ InputHandler::redisplay_input
71
+ end
72
+ end
73
+
74
+ def message_out(to, text, colors=[])
75
+ @monitor.synchronize do
76
+ InputHandler::delete_last_typed
77
+
78
+ notice_if_day_changed(false)
79
+
80
+ puts format_message_out(to, text, colors, format_time(:now))
81
+ end
82
+ end
83
+
84
+ def presence(from, presence, colors=[])
85
+ @monitor.synchronize do
86
+ clear_infoline()
87
+ InputHandler::delete_typed
88
+
89
+ notice_if_day_changed()
90
+
91
+ print "#{ANSI.clearline}"
92
+ print "** #{format_time(:now)}#{from} (#{presence.priority || 0}) is now ".colored(*colors)
93
+ puts presence.pretty(true)
94
+
95
+ InputHandler::redisplay_input
96
+ end
97
+ end
98
+
99
+ def subscription(from, type, msg=nil, colors=[])
100
+ @monitor.synchronize do
101
+ clear_infoline()
102
+ InputHandler::delete_typed
103
+
104
+ notice_if_day_changed()
105
+
106
+ time = format_time(:now)
107
+ case type
108
+ when :subscribe
109
+ indent = ' ' * time.length
110
+ s = "** #{time}subscription request from #{from} received:\n"
111
+ s += %{"#{msg}"\n} if msg
112
+ s += "** See '/help requests' to see how to handle requests."
113
+ when :subscribed
114
+ s = "** #{time}#{from} has subscribed to you"
115
+ when :unsubscribed
116
+ s = "** #{time}#{from} has unsubscribed from you"
117
+ end
118
+
119
+ puts "#{ANSI.clearline}#{s}"
120
+
121
+ InputHandler::redisplay_input
122
+ end
123
+ end
124
+
125
+ def history(*log_entries)
126
+ log_entries.each do |e|
127
+ contact = Main.contacts[Jabber::JID.new(e[:target])]
128
+ target_s = contact ? contact.simple_name : e[:target]
129
+ colors = contact ? [contact.color] : []
130
+ time = format_time(e[:time].localtime, :history_datetime_format)
131
+
132
+ if e[:direction] == :from
133
+ colors << :bold
134
+ m = method(:format_message_in)
135
+ else
136
+ m = method(:format_message_out)
137
+ end
138
+
139
+ puts m.call(target_s, e[:msg], colors, time)
140
+ end
141
+ end
142
+
143
+ def error(s, redisplay_input=true)
144
+ print "#{ANSI.clearline}error: #{s}\n#{ANSI.clearline}".red.bold
145
+ STDOUT.flush
146
+ InputHandler::redisplay_input if redisplay_input
147
+ end
148
+
149
+ def infoline(s)
150
+ @monitor.synchronize do
151
+ print "#{ANSI.savepos}#{ANSIMove.down(1)}#{ANSI.clearline}"
152
+ print s
153
+ print "#{ANSI.restorepos}"
154
+ STDOUT.flush
155
+ end
156
+ end
157
+
158
+ def clear_infoline
159
+ @monitor.synchronize do
160
+ print "#{ANSI.savepos}\n#{ANSI.clearline}#{ANSI.restorepos}"
161
+ STDOUT.flush
162
+ end
163
+ end
164
+
165
+ def make_infoline
166
+ @monitor.synchronize do
167
+ print "\n\r#{ANSI.cleartoeol}#{ANSIMove.up(1)}"
168
+ STDOUT.flush
169
+ end
170
+ end
171
+
172
+ end
173
+
174
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module Term
3
+ module ANSIMove
4
+ module_function
5
+ def to(line, col) "\033[#{line};#{col}H" end
6
+ def up(lines) "\033[#{lines}A" end
7
+ def down(lines) "\033[#{lines}B" end
8
+ def fwd(cols) "\033[#{cols}C" end
9
+ def back(cols) "\033[#{cols}D" end
10
+ end
11
+ module ANSI
12
+ module_function
13
+ def savepos() "\033[s" end
14
+ def restorepos() "\033[u" end
15
+ def title(s) "\033]2;#{s}\007" end
16
+ def clear() "\033[2J" end
17
+ def cleartoeol() "\033[K" end
18
+ def clearline() "\r#{cleartoeol}" end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module Lijab
3
+ VERSION = '0.1.1'
4
+ end
@@ -0,0 +1,45 @@
1
+ require 'xmpp4r'
2
+
3
+ unless Jabber::Message.method_defined?(:chat_state)
4
+ class Jabber::Message
5
+ CHAT_STATES = %w(active composing gone inactive paused).freeze
6
+
7
+ # Returns the current chat state, or nil if no chat state is set
8
+ def each_elements(*els, &block)
9
+ els.inject([ ]) do |res, e|
10
+ res + each_element(e, &block)
11
+ end
12
+ end
13
+
14
+ def chat_state
15
+ each_elements(*CHAT_STATES) { |el| return el.name.to_sym }
16
+ return nil
17
+ end
18
+
19
+ ##
20
+ # Sets the chat state :active, :composing, :gone, :inactive, :paused
21
+ def chat_state=(s)
22
+ s = s.to_s
23
+ raise InvalidChatState,
24
+ "Chat state must be one of #{CHAT_STATES.join(', ')}" unless CHAT_STATES.include?(s)
25
+ CHAT_STATES.each { |state| delete_elements(state) }
26
+ add_element(REXML::Element.new(s).add_namespace('http://jabber.org/protocol/chatstates'))
27
+ end
28
+
29
+ CHAT_STATES.each do |state|
30
+ define_method("#{state}?") do
31
+ chat_state == state.to_sym
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ class Jabber::Message
38
+ ##
39
+ # Sets the message's chat state
40
+ def set_chat_state(s)
41
+ self.chat_state = s
42
+ self
43
+ end
44
+ end
45
+
@@ -0,0 +1,7 @@
1
+
2
+ require 'readline_extra.so'
3
+
4
+ module Readline
5
+ Extra = :"oh yeah"
6
+ end
7
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lijab
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Pablo Flouret
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-05 00:46:35 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: file-tail
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: term-ansicolor
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: xmpp4r
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
56
+ description:
57
+ email: quuxbaz@gmail.com
58
+ executables:
59
+ - lijab
60
+ extensions:
61
+ - ext/extconf.rb
62
+ extra_rdoc_files: []
63
+
64
+ files:
65
+ - ext/extconf.rb
66
+ - ext/test.rb
67
+ - ext/readline_extra.c
68
+ - lib/bleh.rb
69
+ - lib/configs/commands/cowsay.rb
70
+ - lib/configs/hooks/ting.rb
71
+ - lib/lijab/commands/contacts.rb
72
+ - lib/lijab/commands/options.rb
73
+ - lib/lijab/commands/simple.rb
74
+ - lib/lijab/commands/status.rb
75
+ - lib/lijab/commands/subscription.rb
76
+ - lib/lijab/commands.rb
77
+ - lib/lijab/config.rb
78
+ - lib/lijab/contacts.rb
79
+ - lib/lijab/history.rb
80
+ - lib/lijab/hooks.rb
81
+ - lib/lijab/input.rb
82
+ - lib/lijab/main.rb
83
+ - lib/lijab/out.rb
84
+ - lib/lijab/term/ansi.rb
85
+ - lib/lijab/version.rb
86
+ - lib/lijab/xmpp4r/message.rb
87
+ - lib/lijab.rb
88
+ - lib/readline/extra.rb
89
+ has_rdoc: true
90
+ homepage: http://github.com/palbo/lijab
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options: []
95
+
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 1
104
+ - 8
105
+ - 0
106
+ version: 1.8.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ requirements: []
115
+
116
+ rubyforge_project:
117
+ rubygems_version: 1.3.6
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Extensible line oriented jabber client
121
+ test_files: []
122
+