Module: Earthquake::Output
- Included in:
- Earthquake
- Defined in:
- lib/earthquake/output.rb
Instance Method Summary collapse
- #color_of(screen_name) ⇒ Object
- #insert(*messages) ⇒ Object
- #output(name = nil, &block) ⇒ Object
- #output_filter(&block) ⇒ Object
- #output_filters ⇒ Object
- #outputs ⇒ Object
- #puts_items(items) ⇒ Object
Instance Method Details
#color_of(screen_name) ⇒ Object
66 67 68 |
# File 'lib/earthquake/output.rb', line 66 def color_of(screen_name) config[:colors][screen_name.delete("^0-9A-Za-z_").to_i(36) % config[:colors].size] end |
#insert(*messages) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/earthquake/output.rb', line 52 def insert(*) $stdout = StringIO.new puts yield if block_given? unless $stdout.string.empty? STDOUT.print "\e[0G\e[K#{$stdout.string}" Readline.refresh_line end ensure $stdout = STDOUT end |
#output(name = nil, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/earthquake/output.rb', line 18 def output(name = nil, &block) if block outputs.delete_if { |o| o[:name] == name } if name outputs << {:name => name, :block => block} else insert do while item = item_queue.shift item["_stream"] = true puts_items(item) end end end end |
#output_filter(&block) ⇒ Object
10 11 12 |
# File 'lib/earthquake/output.rb', line 10 def output_filter(&block) output_filters << block end |
#output_filters ⇒ Object
6 7 8 |
# File 'lib/earthquake/output.rb', line 6 def output_filters @output_filters ||= [] end |
#outputs ⇒ Object
14 15 16 |
# File 'lib/earthquake/output.rb', line 14 def outputs @outputs ||= [] end |
#puts_items(items) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/earthquake/output.rb', line 32 def puts_items(items) mark_color = config[:colors].sample + 10 [items].flatten.reverse_each do |item| next if output_filters.any? { |f| f.call(item) == false } if item["text"] && !item["_stream"] item['_mark'] = ' '.c(mark_color) + item['_mark'].to_s end outputs.each do |o| begin o[:block].call(item) rescue => e error e end end end end |