Module: Facy::Output

Included in:
Facy
Defined in:
lib/facy/output.rb

Instance Method Summary collapse

Instance Method Details

#_post_code_table_loop(prefix, max_length) ⇒ Object



117
118
119
120
121
122
123
124
# File 'lib/facy/output.rb', line 117

def _post_code_table_loop(prefix, max_length)
  post_code_table << prefix if prefix.length > 0
  if prefix.length < max_length
    ('a'..'z').each do |char|
      _post_code_table_loop(prefix + char, max_length)
    end
  end
end

#clear_lineObject



57
58
59
# File 'lib/facy/output.rb', line 57

def clear_line
  Readline.refresh_line
end

#error(text) ⇒ Object



49
50
51
# File 'lib/facy/output.rb', line 49

def error(text)
  instant_output(Item.new(info: :error, content: text))
end

#instant_output(item) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/facy/output.rb', line 26

def instant_output(item)
  sync { printed_item << item.id if item.id }
  info = item.info
  print_registers.each do |pattern|
    if info == pattern[:name]
      pattern[:block].call(item)
    end
  end
rescue
end

#new_lineObject



53
54
55
# File 'lib/facy/output.rb', line 53

def new_line
  puts ''
end

#not_yet_print_itemsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/facy/output.rb', line 12

def not_yet_print_items
  items = []
  while !stream_print_queue.empty?
    post = stream_print_queue.pop
    items << post unless printed_item.include? post.id
  end

  while !notification_print_queue.empty?
    notify = notification_print_queue.pop
    items << notify unless printed_item.include? notify.id
  end
  return items
end

#periodic_outputObject



5
6
7
8
9
10
# File 'lib/facy/output.rb', line 5

def periodic_output
  return if (items = not_yet_print_items).empty?
  new_line
  items.each {|item| instant_output(item)}
  clear_line
end

#post_code(item) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/facy/output.rb', line 86

def post_code(item)
  post_id = item.id

  return post_code_map[post_id] if post_code_map[post_id]
  post_code_table_load if post_code_table.empty?
  code = post_code_table.pop

  post_code_reverse_map[code] = item
  post_code_map[post_id] = code

  return code 
end

#post_code_mapObject



103
104
105
# File 'lib/facy/output.rb', line 103

def post_code_map
  @post_code_map ||= {}
end

#post_code_reverse_mapObject



107
108
109
# File 'lib/facy/output.rb', line 107

def post_code_reverse_map
  @post_code_reverse_map ||= {}
end

#post_code_tableObject



99
100
101
# File 'lib/facy/output.rb', line 99

def post_code_table
  @post_code_table ||= []
end

#post_code_table_loadObject



111
112
113
114
115
# File 'lib/facy/output.rb', line 111

def post_code_table_load
  max_length = 3
  _post_code_table_loop('$', max_length)
  post_code_table.sort!
end


41
42
43
# File 'lib/facy/output.rb', line 41

def print_register(item_name, &block)
  print_registers << {name: item_name, block: block}
end


37
38
39
# File 'lib/facy/output.rb', line 37

def print_registers
  @print_registers ||= []
end

#stop_animationObject



45
46
47
# File 'lib/facy/output.rb', line 45

def stop_animation
  @stop_animation ||= true
end

#username_color(uname) ⇒ Object



80
81
82
83
84
# File 'lib/facy/output.rb', line 80

def username_color(uname)
  return username_color_map[uname] if username_color_map[uname]
  username_color_table_load if username_color_table.empty?
  return (username_color_map[uname] = username_color_table.pop)
end

#username_color_mapObject



61
62
63
# File 'lib/facy/output.rb', line 61

def username_color_map
  @username_color_map ||= {}
end

#username_color_tableObject



65
66
67
# File 'lib/facy/output.rb', line 65

def username_color_table
  @username_color_table ||= []
end

#username_color_table_loadObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/facy/output.rb', line 69

def username_color_table_load
  max_range = 256 
  step      = 9
  start     = current = 1
  (1..max_range).each do |col|
    username_color_table << [38,5,current]
    current = current + step
    current = current % max_range if current > max_range
  end
end