Permalink
Browse files

Additional

  • Loading branch information...
1 parent 5042601 commit a813e6ae7cb5611b64118e61626ac65702f4daee @sorah sorah committed Mar 7, 2010
View
10 lib/plugins/defaults/list.rb
@@ -15,6 +15,7 @@ module Termtter::Client
register_command(
:name => :list, :aliases => [:l],
:exec_proc => lambda {|arg|
+ a = {}
if /\-([\d]+)/ =~ arg
options = {:count => $1}
arg = arg.gsub(/\-([\d]+)/, '')
@@ -26,14 +27,18 @@ module Termtter::Client
if arg.empty?
event = :list_friends_timeline
statuses = Termtter::API.twitter.home_timeline(options)
+ a[:type] = :home_timeline
else
event = :list_user_timeline
statuses = []
Array(arg.split).each do |user|
if user =~ /\/\w+/
user_name, slug = *user.split('/')
+ a[:type] = :list
user_name = config.user_name if user_name.empty?
user_name = normalize_as_user_name(user_name)
+ a[:list_user] = user_name
+ a[:list_slug] = slug
options[:per_page] = options[:count]
options.delete(:count)
statuses += Termtter::API.twitter.list_statuses(user_name, slug, options)
@@ -47,14 +52,17 @@ module Termtter::Client
end
end
user_name = normalize_as_user_name(user.sub(/\/$/, ''))
+ a[:type] = :user
+ a[:user_name] = user_name
statuses += Termtter::API.twitter.user_timeline(user_name, options)
rescue Rubytter::APIError => e
last_error = e
end
end
end
end
- output(statuses, event)
+ a[:type] = :multiple if arg.length > 1
+ output(statuses, event, a)
raise last_error if last_error
},
:help => ["list,l [USERNAME]/[SLUG] [-COUNT]", "List the posts"]
View
16 lib/plugins/defaults/standard_commands.rb
@@ -18,7 +18,7 @@ module Termtter::Client
unless statuses.empty?
print "\e[0G" + "\e[K" unless win?
@since_id = statuses[0].id
- output(statuses, :update_friends_timeline)
+ output(statuses, :update_friends_timeline, :type => :home_timeline)
Readline.refresh_line if arg =~ /\-r/
end
},
@@ -94,7 +94,8 @@ def method_missing(*args, &block)
Termtter::API.twitter.direct_messages.map { |d|
DirectMessage.new(d.id, "#{d.text} => #{d.recipient_screen_name}", d.sender, d.created_at)
},
- :direct_messages)
+ :direct_messages,
+ :type => :direct_message)
end
register_command(
@@ -105,7 +106,8 @@ def method_missing(*args, &block)
DirectMessage.new(
d.id, "#{d.text} => #{d.recipient_screen_name}", d.sender, d.created_at)
},
- :direct_messages
+ :direct_messages,
+ :type => :direct_message
)
end
@@ -139,7 +141,7 @@ class SearchEvent; attr_reader :query; def initialize(query); @query = query end
search_option = config.search.option.empty? ? {} : config.search.option
statuses = Termtter::API.twitter.search(arg, search_option)
public_storage[:search_keywords] << arg
- output(statuses, SearchEvent.new(arg))
+ output(statuses, SearchEvent.new(arg), :type => :search, :search_keyword => arg)
},
:completion_proc => lambda {|cmd, arg|
public_storage[:search_keywords].grep(/^#{Regexp.quote(arg)}/).map {|i| "#{cmd} #{i}" }
@@ -170,7 +172,7 @@ class SearchEvent; attr_reader :query; def initialize(query); @query = query end
unless arg.empty?
res = res.select {|e| e.user.screen_name == arg }
end
- output(res, :replies)
+ output(res, :replies, :type => :reply)
},
:help => ["replies,r", "List the replies"]
)
@@ -179,7 +181,7 @@ class SearchEvent; attr_reader :query; def initialize(query); @query = query end
:name => :show,
:exec_proc => lambda {|arg|
id = arg.gsub(/.*:\s*/, '')
- output([Termtter::API.twitter.show(id)], :show)
+ output([Termtter::API.twitter.show(id)], :show, :type => :show)
},
:completion_proc => lambda {|cmd, arg|
case arg
@@ -232,7 +234,7 @@ class SearchEvent; attr_reader :query; def initialize(query); @query = query end
help = ['favorite_list USERNAME', 'show user favorites']
register_command(:favorites, :alias => :favlist, :help => help) do |arg|
- output Termtter::API.twitter.favorites(arg), :user_timeline
+ output Termtter::API.twitter.favorites(arg), :user_timeline, :type => :favorite
end
register_command(
View
14 lib/plugins/defaults/stdout.rb
@@ -94,17 +94,17 @@ def initialize
super(:name => :stdout, :points => [:output])
end
- def call(statuses, event)
- print_statuses(statuses, event)
+ def call(statuses, event, additional = {})
+ print_statuses(statuses, event, true, nil, additional)
end
- def print_statuses(statuses, event, sort = true, time_format = nil)
+ def print_statuses(statuses, event, sort = true, time_format = nil, additional = {})
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)
+ output_text << status_line(s, time_format, event, 0, additional)
end
if config.plugins.stdout.enable_pager &&
@@ -120,7 +120,7 @@ def print_statuses(statuses, event, sort = true, time_format = nil)
end
end
- def status_line(s, time_format, event, indent = 0)
+ def status_line(s, time_format, event, indent = 0, additional = {})
return '' unless s
text = TermColor.escape(s.text)
color = color_of_user(s.user)
@@ -147,7 +147,7 @@ def status_line(s, time_format, event, indent = 0)
end
text = colorize_users(text)
- text = Client.get_hooks(:pre_coloring).inject(text){|result, hook| hook.call(result, event)}
+ text = Client.get_hooks(:pre_coloring).inject(text){|result, hook| hook.call(result, event, additional)}
indent_text = indent > 0 ? eval(config.plugins.stdout.indent_format) : ''
erbed_text = ERB.new(config.plugins.stdout.timeline_format).result(binding)
@@ -157,7 +157,7 @@ def status_line(s, time_format, event, indent = 0)
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)
+ text << status_line(status, time_format, event, indent, additional)
end
rescue Rubytter::APIError
end
View
17 lib/termtter/client.rb
@@ -109,23 +109,25 @@ def register_macro(name, macro, options = {})
# :text => status,
# :original_data => original data,
# }
- def output(statuses, event)
+ def output(statuses, event, additional={})
+ # NOTE: "additional" parameter will be substitute to event someday.
return if statuses.nil? || statuses.empty?
statuses = statuses.sort_by(&:id)
call_hooks(:pre_filter, statuses, event)
- filtered = apply_filters_for_hook(:filter_for_output, statuses.map(&:clone), event)
+ filtered = apply_filters_for_hook(:filter_for_output, statuses.map(&:clone), event, additional)
@filters.each do |f| # TODO: code for compatibility. delete someday.
- filtered = f.call(filtered, event)
+ filtered = f.call(filtered, event, additional)
end
call_hooks(:post_filter, filtered, event)
get_hooks(:output).each do |hook|
hook.call(
- apply_filters_for_hook(:"filter_for_#{hook.name}", filtered, event),
- event
+ apply_filters_for_hook(:"filter_for_#{hook.name}", filtered, event, additional),
+ event,
+ additional
)
end
end
@@ -134,9 +136,10 @@ def notify(*args)
::Notify.notify(*args)
end
- def apply_filters_for_hook(hook_name, statuses, event)
+ def apply_filters_for_hook(hook_name, statuses, event, additional={})
+ # NOTE: "additional" parameter will be substitute to event someday.
get_hooks(hook_name).inject(statuses) {|s, hook|
- hook.call(s, event)
+ hook.call(s, event, additional)
}
end
View
7 lib/termtter/hook.rb
@@ -25,7 +25,12 @@ def match?(point)
end
def call(*args)
- self.exec_proc.call(*args)
+ begin
+ self.exec_proc.call(*args)
+ rescue ArgumentError
+ args.pop
+ retry
+ end
end
end
end

0 comments on commit a813e6a

Please sign in to comment.