Class: Termtter::StdOut
- Inherits:
-
Hook
- Object
- Hook
- Termtter::StdOut
show all
- Defined in:
- lib/plugins/defaults/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.
57
58
59
|
# File 'lib/plugins/defaults/stdout.rb', line 57
def initialize
super(:name => :stdout, :points => [:output])
end
|
Instance Method Details
#call(statuses, event) ⇒ Object
61
62
63
|
# File 'lib/plugins/defaults/stdout.rb', line 61
def call(statuses, event)
print_statuses(statuses)
end
|
#print_statuses(statuses, sort = true, time_format = nil) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/plugins/defaults/stdout.rb', line 65
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|
output_text << status_line(s, time_format)
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
|
#status_line(s, time_format, indent = 0) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/plugins/defaults/stdout.rb', line 96
def status_line(s, time_format, indent = 0)
return '' unless s
text = TermColor.escape(s.text)
color = config.plugins.stdout.colors[s.user.id.to_i % config.plugins.stdout.colors.size]
status_id = Termtter::Client.data_to_typable_id(s.id)
reply_to_status_id =
if s.in_reply_to_status_id.nil?
nil
else
Termtter::Client.data_to_typable_id(s.in_reply_to_status_id)
end
time = "(#{Time.parse(s.created_at).strftime(time_format)})"
source =
case s.source
when />(.*?)</ then $1
when 'web' then 'web'
end
erbed_text = ERB.new(config.plugins.stdout.timeline_format).result(binding)
indent_text = indent > 0 ? "#{' ' * (indent - 1)} ┗ " : ''
text = TermColor.parse(indent_text + erbed_text) + "\n"
text = TermColor.unescape(text)
if config.plugins.stdout.show_as_thread && s.in_reply_to_status_id
text << status_line(Status[s.in_reply_to_status_id], time_format, indent + 1)
end
text
end
|