class Termtter::StdOut

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/plugins/defaults/stdout.rb, line 97
def initialize
  super(:name => :stdout, :points => [:output])
end

Public Instance Methods

call(statuses, event) click to toggle source
# File lib/plugins/defaults/stdout.rb, line 101
def call(statuses, event)
  print_statuses(statuses, event)
end
color_of_screen_name(screen_name) click to toggle source
# File lib/plugins/defaults/stdout.rb, line 195
def color_of_screen_name(screen_name)
  return color_of_screen_name_cache[screen_name] if
    color_of_screen_name_cache.key?(screen_name)
  num = screen_name_to_hash(screen_name)
  color = config.plugins.stdout.instance_eval {
    sweets.include?(screen_name) ?
      sweet_color : colors[num % colors.size]
  }
  color_of_screen_name_cache[screen_name] = color
  color_of_screen_name_cache[screen_name]
end
color_of_screen_name_cache() click to toggle source
# File lib/plugins/defaults/stdout.rb, line 212
def color_of_screen_name_cache
  @color_of_screen_name_cache ||= {}
end
color_of_user(user) click to toggle source
# File lib/plugins/defaults/stdout.rb, line 191
def color_of_user(user)
  color_of_screen_name(user.screen_name)
end
colorize_users(text) click to toggle source
# File lib/plugins/defaults/stdout.rb, line 184
def colorize_users(text)
  text.gsub(/@([0-9A-Za-z_]+)/) do |i|
    color = color_of_screen_name($1)
    "<#{color}>#{i}</#{color}>"
  end
end
escape(data) click to toggle source
# File lib/plugins/defaults/stdout.rb, line 216
def escape(data)
  data.gsub(/[:cntrl:]/) {|c| c == "\n" ? c : c.dump[1...-1]}.untaint
end
inspect() click to toggle source
# File lib/plugins/defaults/stdout.rb, line 105
def inspect
  "#<Termtter::StdOut @name=#{@name}, @points=#{@points.inspect}, @exec_proc=#{@exec_proc.inspect}>"
end
print_statuses(statuses, event, sort = true, time_format = nil) click to toggle source
screen_name_to_hash(screen_name) click to toggle source
# File lib/plugins/defaults/stdout.rb, line 207
def screen_name_to_hash(screen_name)
  config.plugins.stdout.screen_name_to_hash_proc.
    call(screen_name)
end
status_line(s, time_format, event, indent = 0) click to toggle source
# File lib/plugins/defaults/stdout.rb, line 132
def status_line(s, time_format, event, indent = 0)
  return '' unless s
  text = escape(TermColor.escape(s.text))
  color = color_of_user(s.user)
  status_id = Termtter::Client.data_to_typable_id(s.id)
  reply_to_status_id =
    if s.in_reply_to_status_id
      Termtter::Client.data_to_typable_id(s.in_reply_to_status_id)
    else
      nil
    end

  retweeted_status_id =
    if s.retweeted_status
      Termtter::Client.data_to_typable_id(s.retweeted_status.id)
    else
      nil
    end

  time = "(#{Time.parse(s.created_at).localtime.strftime(time_format)})"
  source =
    case s.source
    when />(.*?)</ then $1
    when 'web' then 'web'
    end

  text = colorize_users(text)
  text = Client.get_hooks(:pre_coloring).inject(text) {|result, hook|
    #Termtter::Client.logger.debug "stdout status_line: call hook :pre_coloring #{hook.inspect}"
    hook.call(result, event)
  }
  indent_text = indent > 0 ? eval(config.plugins.stdout.indent_format) : ''
  erbed_text = ERB.new(config.plugins.stdout.timeline_format).result(binding)
  erbed_text = Client.get_hooks(:pre_output).inject(erbed_text) {|result, hook|
    #Termtter::Client.logger.debug "stdout status_line: call hook :pre_output #{hook.inspect}"
    hook.call(result, event)
  }
  text = TermColor.unescape(TermColor.parse(erbed_text) + "\n")
  if config.plugins.stdout.show_reply_chain && s.in_reply_to_status_id
    indent += 1
    unless indent > config.plugins.stdout.max_indent_level
      begin
        if status = Termtter::API.twitter.cached_status(s.in_reply_to_status_id)
          text << status_line(status, time_format, event, indent)
        end
      rescue Rubytter::APIError
      end
    end
  end
  text
end