Class: Termtter::StdOut
- Inherits:
-
Hook
- Object
- Hook
- Termtter::StdOut
show all
- Defined in:
- lib/plugins/stdout.rb
Instance Attribute Summary
Attributes inherited from Hook
#exec_proc, #name, #points
Instance Method Summary
collapse
Methods inherited from Hook
#match?
Constructor Details
#initialize ⇒ StdOut
Returns a new instance of StdOut.
20
21
22
|
# File 'lib/plugins/stdout.rb', line 20
def initialize
super(:name => :stdout, :points => [:output])
end
|
Instance Method Details
#call(statuses, event) ⇒ Object
24
25
26
|
# File 'lib/plugins/stdout.rb', line 24
def call(statuses, event)
print_statuses(statuses)
end
|
#print_statuses(statuses, sort = true, time_format = nil) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/plugins/stdout.rb', line 28
def print_statuses(statuses, sort = true, time_format = nil)
return unless statuses and statuses.first
unless time_format
t0 = Time.now
t1 = Time.parse(statuses.first[:created_at])
t2 = Time.parse(statuses.last[:created_at])
time_format =
if [t0.year, t0.month, t0.day] == [t1.year, t1.month, t1.day] \
and [t1.year, t1.month, t1.day] == [t2.year, t2.month, t2.day]
'%H:%M:%S'
else
'%y/%m/%d %H:%M'
end
end
output_text = ''
statuses.each do |s|
text = s.text
status_color = config.plugins.stdout.colors[s.user.id.hash % config.plugins.stdout.colors.size]
status = "#{s.user.screen_name}: #{TermColor.escape(text)}"
if s.in_reply_to_status_id
status += " (repl. to #{s.in_reply_to_status_id})"
end
time = "(#{Time.parse(s.created_at).strftime(time_format)})"
id = s.id
source =
case s.source
when />(.*?)</ then $1
when 'web' then 'web'
end
erbed_text = ERB.new(config.plugins.stdout.timeline_format).result(binding)
output_text << TermColor.parse(erbed_text) + "\n"
end
if config.plugins.stdout. && ENV['LINES'] && statuses.size > ENV['LINES'].to_i
file = Tempfile.new('termtter')
file.print output_text
file.close
system "#{config.plugins.stdout.} #{file.path}"
file.close(true)
else
print output_text
end
end
|