Module: Earthquake::Output

Included in:
Earthquake
Defined in:
lib/earthquake/output.rb

Instance Method Summary collapse

Instance Method Details

#clear_lineObject



52
53
54
# File 'lib/earthquake/output.rb', line 52

def clear_line
  print "\e[0G" + "\e[K"
end

#color_of(screen_name) ⇒ Object



56
57
58
# File 'lib/earthquake/output.rb', line 56

def color_of(screen_name)
  config[:colors][screen_name.to_i(36) % config[:colors].size]
end

#insert(*messages) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/earthquake/output.rb', line 44

def insert(*messages)
  clear_line
  puts messages unless messages.empty?
  yield if block_given?
ensure
  Readline.refresh_line
end

#output(name = nil, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/earthquake/output.rb', line 16

def output(name = nil, &block)
  if block
    outputs.delete_if { |o| o[:name] == name } if name
    outputs << {:name => name, :block => block}
  else
    return if item_queue.empty?
    insert do
      while item = item_queue.shift
        item["_stream"] = true
        puts_items(item)
      end
    end
  end
end

#output_filter(&block) ⇒ Object



8
9
10
# File 'lib/earthquake/output.rb', line 8

def output_filter(&block)
  output_filters << block
end

#output_filtersObject



4
5
6
# File 'lib/earthquake/output.rb', line 4

def output_filters
  @output_filters ||= []
end

#outputsObject



12
13
14
# File 'lib/earthquake/output.rb', line 12

def outputs
  @outputs ||= []
end

#puts_items(items) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/earthquake/output.rb', line 31

def puts_items(items)
  [items].flatten.reverse_each do |item|
    next if output_filters.any? { |f| f.call(item) == false }
    outputs.each do |o|
      begin
        o[:block].call(item)
      rescue => e
        error e
      end
    end
  end
end