Module: Earthquake::Output
- Included in:
- Earthquake
- Defined in:
- lib/earthquake/output.rb
Instance Method Summary collapse
- #color_of(screen_name) ⇒ Object
- #insert(*messages) ⇒ Object
- #insert_monitor ⇒ 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
72 73 74 |
# File 'lib/earthquake/output.rb', line 72 def color_of(screen_name) config[:colors][screen_name.delete("^0-9A-Za-z_").to_i(36) % config[:colors].size] end |
#insert(*messages) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/earthquake/output.rb', line 53 def insert(*) insert_monitor.synchronize do begin try_swap = !$stdout.is_a?(StringIO) $stdout = StringIO.new if try_swap puts yield if block_given? unless $stdout.string.empty? STDOUT.print "\e[0G\e[K#{$stdout.string}" Readline.refresh_line end ensure $stdout = STDOUT if try_swap end end end |
#insert_monitor ⇒ Object
76 77 78 |
# File 'lib/earthquake/output.rb', line 76 def insert_monitor @insert_monitor ||= Monitor.new end |
#output(name = nil, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/earthquake/output.rb', line 19 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
11 12 13 |
# File 'lib/earthquake/output.rb', line 11 def output_filter(&block) output_filters << block end |
#output_filters ⇒ Object
7 8 9 |
# File 'lib/earthquake/output.rb', line 7 def output_filters @output_filters ||= [] end |
#outputs ⇒ Object
15 16 17 |
# File 'lib/earthquake/output.rb', line 15 def outputs @outputs ||= [] end |
#puts_items(items) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/earthquake/output.rb', line 33 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 |