### Home Classes Methods

### In Files

- lib/plugins/defaults/stdout.rb

### Parent

Termtter::Hook

### Methods

- ::new
- #call
- #color_of_screen_name
- #color_of_screen_name_cache
- #color_of_user
- #colorize_users
- #escape
- #inspect
- #print_statuses
- #screen_name_to_hash
- #status_line

### Files

- ChangeLog
- README.rdoc

### Class/Module Index

Quicksearch

- Termtter
- Termtter::API
- Termtter::ActiveRubytter
- Termtter::Client
- Termtter::Client::DirectMessage
- Termtter::Client::Jakigan
- Termtter::Client::SearchEvent
- Termtter::Client::UserSearchEvent
- Termtter::Command
- Termtter::CommandCanceled
- Termtter::CommandLine
- Termtter::CommandNotFound
- Termtter::Config
- Termtter::ConfigSetup
- Termtter::Crypt
- Termtter::English
- Termtter::Event
- Termtter::HTTPpool
- Termtter::Hook
- Termtter::HookCanceled
- Termtter::Hookable
- Termtter::JSONError
- Termtter::MemoryCache
- Termtter::MemoryCache::MemCacheMock
- Termtter::OptParser
- Termtter::Plugin
- Termtter::Plugin::Screen
- Termtter::Plugins
- Termtter::Plugins::Haml
- Termtter::Plugins::ListSwitch
- Termtter::RubytterProxy
- Termtter::RubytterProxy::FrequentAccessError
- Termtter::RubytterProxy::LimitManager
- Termtter::Status
- Termtter::StdOut
- Termtter::Storage
- Termtter::Storage::SQLite3
- Termtter::Storage::Status
- Termtter::Task
- Termtter::TaskManager
- Termtter::TypableIdGenerator
- Termtter::UserStreamReceiver
- Yharian
- Yharian::Alex
- Yharian::Jenifer
- Yharian::Remark
- Yharian::Speaker
- Yharian::Vicki
- Yharian::Yhara
- HatenaKeywordHaiku
- HatenaKeywordHaiku::Word
- OAuth
- OAuth::AccessToken
- Readline
- Readline::LIBREADLINE
- AAMaker
- Array
- BrowserNotFound
- Growl
- IRB
- Object
- Status
- String
- Symbol
- TermColor
- TermtterIrcGateway
- User

No matching classes.

# Termtter::StdOut

### Public Class Methods

new() click to toggle source

    # File lib/plugins/defaults/stdout.rb, line 95
    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 99
    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 193
    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 210
    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 189
    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 182
    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 214
    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 103
    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

    # File lib/plugins/defaults/stdout.rb, line 107
    def print_statuses(statuses, event, sort = true, time_format = nil)
      return unless statuses and statuses.first
      time_format ||= Termtter::Client.time_format_for statuses

      output_text = ''
      statuses.each do |s|
        output_text << status_line(s, time_format, event)
      end

      if config.plugins.stdout.enable_pager &&
        ENV['LINES'] &&
        statuses.size > ENV['LINES'].to_i
          file = Tempfile.new('termtter')
          file.print output_text
          file.close
          system "#{config.plugins.stdout.pager} #{file.path}"
          file.close(true)
      else
        Termtter::Client.clear_line
        print output_text
      end
    end

screen_name_to_hash(screen_name) click to toggle source

    # File lib/plugins/defaults/stdout.rb, line 205
    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 130
    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).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

[Validate]

Generated with the Darkfish Rdoc Generator 2.