termtter 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. data/ChangeLog +115 -0
  2. data/README.rdoc +25 -10
  3. data/Rakefile +53 -34
  4. data/lib/plugins/cool.rb +2 -5
  5. data/lib/plugins/curry.rb +43 -0
  6. data/lib/plugins/db.rb +91 -0
  7. data/lib/plugins/{auto_reload.rb → defaults/auto_reload.rb} +0 -0
  8. data/lib/plugins/defaults/command_line.rb +111 -0
  9. data/lib/plugins/{exec.rb → defaults/exec.rb} +2 -7
  10. data/lib/plugins/{fib.rb → defaults/fib.rb} +1 -4
  11. data/lib/plugins/defaults/retweet.rb +34 -0
  12. data/lib/plugins/{standard_commands.rb → defaults/standard_commands.rb} +60 -136
  13. data/lib/plugins/defaults/standard_completion.rb +67 -0
  14. data/lib/plugins/{stdout.rb → defaults/stdout.rb} +30 -19
  15. data/lib/plugins/defaults.rb +14 -0
  16. data/lib/plugins/en2ja.rb +11 -5
  17. data/lib/plugins/english.rb +2 -2
  18. data/lib/plugins/expand-tinyurl.rb +27 -6
  19. data/lib/plugins/github-issues.rb +192 -0
  20. data/lib/plugins/group.rb +30 -4
  21. data/lib/plugins/growl.rb +10 -1
  22. data/lib/plugins/http_server/favicon.ico +0 -0
  23. data/lib/plugins/http_server/index.html +117 -0
  24. data/lib/plugins/http_server.rb +82 -0
  25. data/lib/plugins/irb.rb +6 -0
  26. data/lib/plugins/l2.rb +1 -1
  27. data/lib/plugins/list_with_opts.rb +0 -3
  28. data/lib/plugins/log.rb +6 -9
  29. data/lib/plugins/modify_arg_hook_sample.rb +3 -5
  30. data/lib/plugins/multi_reply.rb +0 -5
  31. data/lib/plugins/notify-send.rb +1 -1
  32. data/lib/plugins/notify-send2.rb +1 -1
  33. data/lib/plugins/notify-send3.rb +11 -3
  34. data/lib/plugins/open_url.rb +0 -8
  35. data/lib/plugins/otsune.rb +3 -9
  36. data/lib/plugins/outputz.rb +1 -1
  37. data/lib/plugins/pool.rb +30 -0
  38. data/lib/plugins/quicklook.rb +1 -1
  39. data/lib/plugins/saykanji.rb +81 -0
  40. data/lib/plugins/shell.rb +1 -6
  41. data/lib/plugins/sl.rb +8 -8
  42. data/lib/plugins/tinyurl.rb +26 -7
  43. data/lib/plugins/trends.rb +84 -0
  44. data/lib/plugins/twitpic.rb +46 -0
  45. data/lib/plugins/uri-open.rb +1 -1
  46. data/lib/plugins/wassr.rb +0 -3
  47. data/lib/plugins/whois.rb +45 -0
  48. data/lib/plugins/yhara.rb +2 -6
  49. data/lib/termtter/client.rb +73 -100
  50. data/lib/termtter/config.rb +4 -6
  51. data/lib/termtter/config_setup.rb +1 -1
  52. data/lib/termtter/hook.rb +2 -2
  53. data/lib/termtter/optparse.rb +14 -1
  54. data/lib/termtter/system_extensions.rb +3 -2
  55. data/lib/termtter/task_manager.rb +1 -5
  56. data/lib/termtter/version.rb +1 -1
  57. data/spec/plugins/cool_spec.rb +1 -1
  58. data/spec/plugins/curry_spec.rb +13 -0
  59. data/spec/plugins/db_spec.rb +62 -0
  60. data/spec/plugins/english_spec.rb +2 -2
  61. data/spec/plugins/fib_spec.rb +2 -2
  62. data/spec/plugins/filter_spec.rb +2 -2
  63. data/spec/plugins/pause_spec.rb +1 -1
  64. data/spec/plugins/primes_spec.rb +2 -2
  65. data/spec/plugins/shell_spec.rb +1 -1
  66. data/spec/plugins/sl_spec.rb +1 -1
  67. data/spec/plugins/{standard_plugins_spec.rb → standard_commands_spec.rb} +2 -2
  68. data/spec/plugins/whois_spec.rb +20 -0
  69. data/spec/termtter/client_spec.rb +114 -37
  70. data/spec/termtter/config_spec.rb +10 -0
  71. data/spec/termtter/optparse_spec.rb +16 -0
  72. data/spec/termtter_spec.rb +7 -8
  73. metadata +39 -19
  74. data/History.txt +0 -4
  75. data/lib/plugins/direct_messages.rb +0 -36
  76. data/lib/plugins/retweet.rb +0 -46
@@ -7,6 +7,8 @@ config.plugins.standard.set_default(
7
7
  :limit_format,
8
8
  '<<%=remaining_color%>><%=limit.remaining_hits%></<%=remaining_color%>>/<%=limit.hourly_limit%> until <%=limit.reset_time%> (<%=remaining_time%> remaining)')
9
9
 
10
+ config.set_default(:easy_reply, true)
11
+
10
12
  module Termtter::Client
11
13
 
12
14
  register_command(
@@ -27,13 +29,17 @@ module Termtter::Client
27
29
  :name => :update, :alias => :u,
28
30
  :exec => lambda {|arg|
29
31
  unless arg.empty?
30
- result = Termtter::API.twitter.update(arg)
31
- puts TermColor.parse("updated => #{result.text} <90>#{result.id}</90>")
32
- end
33
- },
34
- :completion => lambda {|cmd, args|
35
- if /(.*)@([^\s]*)$/ =~ args
36
- find_user_candidates $2, "#{cmd} #{$1}@%s"
32
+ params =
33
+ if config.easy_reply && /^\s*(@\w+)/ =~ arg
34
+ user_name = normalize_as_user_name($1)
35
+ in_reply_to_status_id = Termtter::API.twitter.user(user_name).status.id rescue nil
36
+ in_reply_to_status_id ? {:in_reply_to_status_id => in_reply_to_status_id} : {}
37
+ else
38
+ {}
39
+ end
40
+
41
+ result = Termtter::API.twitter.update(arg, params)
42
+ puts "updated => #{result.text}"
37
43
  end
38
44
  },
39
45
  :help => ["update,u TEXT", "Post a new message"]
@@ -51,7 +57,7 @@ module Termtter::Client
51
57
  end
52
58
  if id
53
59
  result = Termtter::API.twitter.remove_status(id)
54
- puts TermColor.parse("deleted => #{result.text} <90>#{result.id}</90>")
60
+ puts "deleted => #{result.text}"
55
61
  end
56
62
  },
57
63
  :help => ['delete,del [STATUS ID]', 'Delete a status']
@@ -67,8 +73,8 @@ module Termtter::Client
67
73
  :name => :direct, :aliases => [:d],
68
74
  :exec_proc => lambda {|arg|
69
75
  case arg
70
- when /^([^\s]+)\s+(.*)\s*$/
71
- user, text = $1, $2
76
+ when /^([^\s]+)\s+?(.*)\s*$/
77
+ user, text = normalize_as_user_name($1), $2
72
78
  Termtter::API.twitter.direct_message(user, text)
73
79
  puts "=> to:#{user} message:#{text}"
74
80
  when 'list'
@@ -87,10 +93,6 @@ module Termtter::Client
87
93
  )
88
94
  end
89
95
  },
90
- :completion_proc => lambda {|cmd, arg|
91
- find_user_candidates(arg, "#{cmd} %s") +
92
- ["list", "sent_list"].grep(/^#{Regexp.quote(arg)}/).map { |i| "#{cmd} #{i}" }
93
- },
94
96
  :help => [
95
97
  ["direct,d USERNAME TEXT", "Send direct message"],
96
98
  ["direct,d list", 'List direct messages'],
@@ -101,7 +103,7 @@ module Termtter::Client
101
103
  register_command(
102
104
  :name => :profile, :aliases => [:p],
103
105
  :exec_proc => lambda {|arg|
104
- user = Termtter::API.twitter.user(arg.strip)
106
+ user = Termtter::API.twitter.user(normalize_as_user_name(arg))
105
107
  attrs = %w[ name screen_name url description profile_image_url location protected following
106
108
  friends_count followers_count statuses_count favourites_count
107
109
  id time_zone created_at utc_offset notifications
@@ -112,16 +114,13 @@ module Termtter::Client
112
114
  puts "#{attr.gsub('_', ' ').rjust(label_width)}: #{value}"
113
115
  end
114
116
  },
115
- :completion_proc => lambda {|cmd, arg|
116
- find_user_candidates arg, "#{cmd} %s"
117
- },
118
117
  :help => ["profile,p USERNAME", "Show user's profile"]
119
118
  )
120
119
 
121
120
  register_command(
122
121
  :name => :followers,
123
122
  :exec_proc => lambda {|arg|
124
- user_name = arg.strip
123
+ user_name = normalize_as_user_name(arg)
125
124
  user_name = config.user_name if user_name.empty?
126
125
 
127
126
  followers = []
@@ -133,9 +132,6 @@ module Termtter::Client
133
132
  public_storage[:users] += followers.map(&:screen_name)
134
133
  puts followers.map(&:screen_name).join(' ')
135
134
  },
136
- :completion_proc => lambda {|cmd, arg|
137
- find_user_candidates arg, "#{cmd} %s"
138
- },
139
135
  :help => ["followers", "Show followers"]
140
136
  )
141
137
 
@@ -147,13 +143,11 @@ module Termtter::Client
147
143
  statuses = Termtter::API.twitter.friends_timeline
148
144
  else
149
145
  event = :list_user_timeline
150
- statuses = Termtter::API.twitter.user_timeline(arg)
146
+ user_name = normalize_as_user_name(arg)
147
+ statuses = Termtter::API.twitter.user_timeline(user_name)
151
148
  end
152
149
  output(statuses, event)
153
150
  },
154
- :completion_proc => lambda {|cmd, arg|
155
- find_user_candidates arg, "#{cmd} %s"
156
- },
157
151
  :help => ["list,l [USERNAME]", "List the posts"]
158
152
  )
159
153
 
@@ -166,7 +160,7 @@ module Termtter::Client
166
160
  output(statuses, :search)
167
161
  },
168
162
  :completion_proc => lambda {|cmd, arg|
169
- public_storage[:search_keywords].grep(/#{Regexp.quote(arg)}/).map { |i| "#{cmd} #{i}" }
163
+ public_storage[:search_keywords].grep(/^#{Regexp.quote(arg)}/).map { |i| "#{cmd} #{i}" }
170
164
  },
171
165
  :help => ["search,s TEXT", "Search for Twitter"]
172
166
  )
@@ -220,14 +214,10 @@ module Termtter::Client
220
214
  :name => :follow, :aliases => [],
221
215
  :exec_proc => lambda {|args|
222
216
  args.split(' ').each do |arg|
223
- if /^(\w+)/ =~ arg
224
- res = Termtter::API::twitter.follow($1.strip)
225
- end
217
+ user_name = normalize_as_user_name(arg)
218
+ res = Termtter::API::twitter.follow(user_name)
226
219
  end
227
220
  },
228
- :completion_proc => lambda {|cmd, args|
229
- find_user_candidates args, "#{cmd} %s"
230
- },
231
221
  :help => ['follow USER', 'Follow user']
232
222
  )
233
223
 
@@ -235,14 +225,10 @@ module Termtter::Client
235
225
  :name => :leave, :aliases => [],
236
226
  :exec_proc => lambda {|args|
237
227
  args.split(' ').each do |arg|
238
- if /^(\w+)/ =~ arg
239
- res = Termtter::API::twitter.leave($1.strip)
240
- end
228
+ user_name = normalize_as_user_name(arg)
229
+ res = Termtter::API::twitter.leave(user_name)
241
230
  end
242
231
  },
243
- :completion_proc => lambda {|cmd, args|
244
- find_user_candidates args, "#{cmd} %s"
245
- },
246
232
  :help => ['leave USER', 'Leave user']
247
233
  )
248
234
 
@@ -254,8 +240,8 @@ module Termtter::Client
254
240
  when /^\d+/
255
241
  id = arg.to_i
256
242
  when /^@([A-Za-z0-9_]+)/
257
- user = $1
258
- statuses = Termtter::API.twitter.user_timeline(user)
243
+ user_name = normalize_as_user_name($1)
244
+ statuses = Termtter::API.twitter.user_timeline(user_name)
259
245
  return if statuses.empty?
260
246
  id = statuses[0].id
261
247
  when /^\/(.*)$/
@@ -274,8 +260,6 @@ module Termtter::Client
274
260
  },
275
261
  :completion_proc => lambda {|cmd, arg|
276
262
  case arg
277
- when /@(.*)/
278
- find_user_candidates $1, "#{cmd} @%s"
279
263
  when /(\d+)/
280
264
  find_status_ids(arg).map{|id| "#{cmd} #{id}"}
281
265
  else
@@ -341,7 +325,7 @@ module Termtter::Client
341
325
  )
342
326
 
343
327
  register_command(
344
- :name => :exit, :aliases => [:e],
328
+ :name => :exit, :aliases => [:quit],
345
329
  :exec_proc => lambda {|arg| exit},
346
330
  :help => ['exit,e', 'Exit']
347
331
  )
@@ -360,6 +344,9 @@ module Termtter::Client
360
344
  end
361
345
  end
362
346
  helps.compact!
347
+ unless arg.empty?
348
+ helps = helps.select {|n, _| /#{arg}/ =~ n }
349
+ end
363
350
  puts formatted_help(helps)
364
351
  },
365
352
  :help => ["help,h", "Print this help message"]
@@ -374,28 +361,6 @@ module Termtter::Client
374
361
  }.join("\n")
375
362
  end
376
363
 
377
- # completion for standard commands
378
-
379
- public_storage[:users] ||= Set.new
380
- public_storage[:status_ids] ||= Set.new
381
-
382
- register_hook(
383
- :name => :for_completion,
384
- :points => [:pre_filter],
385
- :exec_proc => lambda {|statuses, event|
386
- statuses.each do |s|
387
- public_storage[:users].add(s.user.screen_name)
388
- public_storage[:users] += s.text.scan(/@([a-zA-Z_0-9]*)/).flatten
389
- public_storage[:status_ids].add(s.id)
390
- public_storage[:status_ids].add(s.in_reply_to_status_id) if s.in_reply_to_status_id
391
- end
392
- }
393
- )
394
-
395
- public_storage[:plugins] = (Dir["#{File.dirname(__FILE__)}/*.rb"] + Dir["#{Termtter::CONF_DIR}/plugins/*.rb"]).map do |f|
396
- f.match(%r|([^/]+).rb$|)[1]
397
- end
398
-
399
364
  register_command(
400
365
  :name => :plug,
401
366
  :alias => :plugin,
@@ -412,22 +377,29 @@ module Termtter::Client
412
377
  end
413
378
  },
414
379
  :completion_proc => lambda {|cmd, args|
415
- find_user_candidates args, "#{cmd} %s"
416
- unless args.empty?
417
- find_plugin_candidates args, "#{cmd} %s"
418
- else
419
- public_storage[:plugins].sort
420
- end
380
+ plugin_list.grep(/^#{Regexp.quote(args)}/).map{|i| "#{cmd} #{i}"}
421
381
  },
422
- :help => ['plug FILE', 'Load a plugin']
382
+ :help => ['plug FILE', 'Load a plugin']
423
383
  )
424
384
 
385
+ def self.plugin_list
386
+ (Dir["#{File.dirname(__FILE__)}/../*.rb"] + Dir["#{Termtter::CONF_DIR}/plugins/*.rb"]).
387
+ map{|f| File.basename(f).sub(/\.rb$/, '')}.
388
+ sort
389
+ end
390
+
425
391
  register_command(
426
- :name => :plugins,
392
+ :name => :plugins,
427
393
  :exec_proc => lambda {|arg|
428
- puts public_storage[:plugins].sort.join("\n")
429
- },
430
- :help => ['plugins', 'Show list of plugins']
394
+ list = plugin_list
395
+ width = list.map{|i|i.size}.max + 2
396
+ a = []
397
+ list.sort.each_slice(4) {|i|
398
+ a << i.map{|j| j + (" " * (width - j.size))}.join
399
+ }
400
+ puts TermColor.parse('<green>' + TermColor.escape(a.join("\n")) + '</green>')
401
+ },
402
+ :help => ['plugins', 'Show list of plugins']
431
403
  )
432
404
 
433
405
  register_command(
@@ -457,17 +429,18 @@ module Termtter::Client
457
429
  if s
458
430
  update_with_user_and_id($2, s.user.screen_name, s.id)
459
431
  end
460
- when /^\s*@(\w+)/
461
- in_reply_to_status_id = Termtter::API.twitter.user($1).status.id rescue nil
462
- params = in_reply_to_status_id ? {:in_reply_to_status_id => in_reply_to_status_id} : {}
463
- Termtter::API.twitter.update(arg, params)
464
- puts "=> #{arg}"
432
+ when /^\s*(@\w+)/
433
+ user_name = normalize_as_user_name($1)
434
+ s = Termtter::API.twitter.user(user_name).status
435
+ if s
436
+ params = s ? {:in_reply_to_status_id => s.id} : {}
437
+ Termtter::API.twitter.update(arg, params)
438
+ puts "=> #{arg}"
439
+ end
465
440
  end
466
441
  },
467
442
  :completion_proc => lambda {|cmd, arg|
468
443
  case arg
469
- when /(.*)@([^\s]*)$/
470
- find_user_candidates $2, "#{cmd} #{$1}@%s"
471
444
  when /(\d+)/
472
445
  find_status_ids(arg).map{|id| "#{cmd} #{id}"}
473
446
  end
@@ -502,50 +475,11 @@ module Termtter::Client
502
475
  def self.update_with_user_and_id(text, username, id)
503
476
  text = "@#{username} #{text}"
504
477
  result = Termtter::API.twitter.update(text, {'in_reply_to_status_id' => id})
505
- puts TermColor.parse("replied => #{result.text} <90>#{result.id}</90>")
478
+ puts "replied => #{result.text}"
506
479
  end
507
480
 
508
- =begin
509
- = Termtter reply command
510
- == Usage
511
- === list
512
- * ステータスリストを連番と一緒に出す。
513
- > reply [list|ls]
514
- 0: foo: foo's message
515
- 1: bar: bar's message
516
- ..
517
-
518
- * ユーザ指定してリスト作成。
519
- > reply [list|ls] foo
520
- 0: foo: foo's message0
521
- 1: foo: foo's message1
522
-
523
- === reply
524
- メッセージ送信の際、@usernameが自動的に付与される。
525
-
526
- * status_idを自分で入力してreply送信
527
- > reply 1234567890 message to status_id
528
- => @foo message to status_id (reply to 1234567890)
529
-
530
- * reply listコマンドで出したステータス番号に対してreply送信
531
- > reply up 0 message to status no
532
- => @foo message to status_no
533
-
534
- * 対象ユーザの最後の発言に対してreply
535
- > reply @foo message to foo
536
- => @foo message to foo
537
-
538
- == Todo
539
- * 英語で説明 => ヘルプを設定する
540
- * リファクタ
541
- * 補完
542
- * 確認画面を出したい
543
- =end
544
-
545
- def self.find_plugin_candidates(a, b)
546
- public_storage[:plugins].
547
- grep(/^#{Regexp.quote a}/i).
548
- map {|u| b % u }
481
+ def self.normalize_as_user_name(text)
482
+ text.strip.sub(/^@/, '')
549
483
  end
550
484
 
551
485
  def self.find_status_ids(text)
@@ -555,14 +489,4 @@ module Termtter::Client
555
489
  def self.find_users(text)
556
490
  public_storage[:users].select {|user| /^#{Regexp.quote(text)}/ =~ user}
557
491
  end
558
-
559
- def self.find_user_candidates(a, b)
560
- users =
561
- if a.nil? || a.empty?
562
- public_storage[:users].to_a
563
- else
564
- public_storage[:users].grep(/^#{Regexp.quote a}/i)
565
- end
566
- users.map {|u| b % u }
567
- end
568
492
  end
@@ -0,0 +1,67 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'set'
4
+
5
+ module Termtter::Client
6
+
7
+ #
8
+ # completion for status ids
9
+ # (I want to delete)
10
+ #
11
+
12
+ public_storage[:status_ids] ||= Set.new
13
+
14
+ register_hook(:collect_status_ids, :point => :pre_filter) do |statuses, event|
15
+ statuses.each do |s|
16
+ public_storage[:status_ids].add(s.id)
17
+ public_storage[:status_ids].add(s.in_reply_to_status_id) if s.in_reply_to_status_id
18
+ end
19
+ end
20
+
21
+ #
22
+ # completion for user names
23
+ #
24
+
25
+ public_storage[:users] ||= Set.new
26
+
27
+ register_hook(:collect_user_names, :point => :pre_filter) do |statuses, event|
28
+ statuses.each do |s|
29
+ public_storage[:users].add(s.user.screen_name)
30
+ public_storage[:users] += s.text.scan(/@([a-zA-Z_0-9]*)/).flatten
31
+ end
32
+ end
33
+
34
+ register_hook(:user_names_completion, :point => :completion) do |input|
35
+ if /(.*)@([^\s]*)$/ =~ input
36
+ command_str = $1
37
+ part_of_user_name = $2
38
+
39
+ users =
40
+ if part_of_user_name.nil? || part_of_user_name.empty?
41
+ public_storage[:users].to_a
42
+ else
43
+ public_storage[:users].grep(/^#{Regexp.quote(part_of_user_name)}/)
44
+ end
45
+
46
+ users.map {|u| "#{command_str}@%s" % u }
47
+ end
48
+ end
49
+
50
+ #
51
+ # completion for hashtags
52
+ #
53
+
54
+ public_storage[:hashtag] ||= Set.new
55
+
56
+ register_hook(:collect_hashtags, :point => /^post_exec_/) do |cmd, arg, result|
57
+ public_storage[:hashtag] += arg.scan(/\s+#([^\s]+)/).flatten if arg
58
+ end
59
+
60
+ register_hook(:hashtags_completion, :point => :completion) do |input|
61
+ if /(.*)#([^\s]*)$/ =~ input
62
+ command_str = $1
63
+ part_of_hashtag = $2
64
+ public_storage[:hashtag].grep(/^#{Regexp.quote(part_of_hashtag)}/i).map { |i| "#{command_str}##{i}" }
65
+ end
66
+ end
67
+ end
@@ -15,6 +15,7 @@ config.plugins.stdout.set_default(:pager, 'less -R -f +G')
15
15
  config.plugins.stdout.set_default(:window_height, 50)
16
16
  config.plugins.stdout.set_default(:typable_ids, ('aa'..'zz').to_a)
17
17
  config.plugins.stdout.set_default(:typable_id_prefix, '$')
18
+ config.plugins.stdout.set_default(:show_as_thread, false)
18
19
 
19
20
  module Termtter
20
21
  class TypableIdGenerator
@@ -78,25 +79,7 @@ module Termtter
78
79
 
79
80
  output_text = ''
80
81
  statuses.each do |s|
81
- text = TermColor.escape(s.text)
82
- color = config.plugins.stdout.colors[s.user.id.to_i % config.plugins.stdout.colors.size]
83
- status_id = Termtter::Client.data_to_typable_id(s.id)
84
- reply_to_status_id =
85
- if s.in_reply_to_status_id.nil?
86
- nil
87
- else
88
- Termtter::Client.data_to_typable_id(s.in_reply_to_status_id)
89
- end
90
-
91
- time = "(#{Time.parse(s.created_at).strftime(time_format)})"
92
- source =
93
- case s.source
94
- when />(.*?)</ then $1
95
- when 'web' then 'web'
96
- end
97
-
98
- erbed_text = ERB.new(config.plugins.stdout.timeline_format).result(binding)
99
- output_text << TermColor.parse(erbed_text) + "\n"
82
+ output_text << status_line(s, time_format)
100
83
  end
101
84
 
102
85
  if config.plugins.stdout.enable_pager && ENV['LINES'] && statuses.size > ENV['LINES'].to_i
@@ -109,6 +92,34 @@ module Termtter
109
92
  print output_text
110
93
  end
111
94
  end
95
+
96
+ def status_line(s, time_format, indent = 0)
97
+ return '' unless s
98
+ text = TermColor.escape(s.text)
99
+ color = config.plugins.stdout.colors[s.user.id.to_i % config.plugins.stdout.colors.size]
100
+ status_id = Termtter::Client.data_to_typable_id(s.id)
101
+ reply_to_status_id =
102
+ if s.in_reply_to_status_id.nil?
103
+ nil
104
+ else
105
+ Termtter::Client.data_to_typable_id(s.in_reply_to_status_id)
106
+ end
107
+
108
+ time = "(#{Time.parse(s.created_at).strftime(time_format)})"
109
+ source =
110
+ case s.source
111
+ when />(.*?)</ then $1
112
+ when 'web' then 'web'
113
+ end
114
+
115
+ erbed_text = ERB.new(config.plugins.stdout.timeline_format).result(binding)
116
+ indent_text = indent > 0 ? "#{' ' * (indent - 1)} ┗ " : ''
117
+ text = TermColor.parse(indent_text + erbed_text) + "\n"
118
+ if config.plugins.stdout.show_as_thread && s.in_reply_to_status_id
119
+ text << status_line(Status[s.in_reply_to_status_id], time_format, indent + 1)
120
+ end
121
+ text
122
+ end
112
123
  end
113
124
 
114
125
  Client.register_hook(StdOut.new)
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter::Client
4
+ config.set_default(:stdout, true)
5
+ config.set_default(:standard_commands, true)
6
+ config.set_default(:standard_completion, true)
7
+ config.set_default(:auto_reload, true)
8
+
9
+ defaults = Dir[File.dirname(__FILE__) + '/defaults/*.rb'].map { |f|
10
+ f.match(%r|defaults/(.*?).rb$|)[1]
11
+ }.each { |plugin|
12
+ plug "defaults/#{plugin}" if config.__refer__(plugin.to_sym)
13
+ }
14
+ end
data/lib/plugins/en2ja.rb CHANGED
@@ -1,11 +1,17 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- plugin 'translation'
3
+ module Termtter::Client
4
+ plug 'translation'
4
5
 
5
- Termtter::Client.add_filter do |statuses, event|
6
- statuses.each do |s|
7
- if s.english?
8
- s.text = translate(s.text, 'en|ja')
6
+ register_hook(:en2ja, :point => :filter_for_output) do |statuses, event|
7
+ statuses.each do |s|
8
+ if english?(s.text)
9
+ s.text = translate(s.text, 'en|ja')
10
+ end
9
11
  end
10
12
  end
13
+
14
+ def self.english?(text)
15
+ /[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ text
16
+ end
11
17
  end
@@ -20,6 +20,6 @@ end
20
20
  # select English posts only
21
21
  #
22
22
  # config sample:
23
- # plugin 'english'
23
+ # t.plug 'english'
24
24
  # or,
25
- # plugin 'english', :only => [:list_friends_timeline, :update_friends_timeline]
25
+ # t.plug 'english', :only => [:list_friends_timeline, :update_friends_timeline]
@@ -4,13 +4,34 @@ URL_SHORTTERS = [
4
4
  { :host => "tinyurl.com", :pattern => %r'(http://tinyurl\.com(/[\w/]+))' },
5
5
  { :host => "is.gd", :pattern => %r'(http://is\.gd(/[\w/]+))' },
6
6
  { :host => "bit.ly", :pattern => %r'(http://bit\.ly(/[\w/]+))' },
7
- { :host => "ff.im", :pattern => %r'(http://ff\.im(/[\w/]+))'},
7
+ { :host => "ff.im", :pattern => %r'(http://ff\.im(/[-\w/]+))'},
8
8
  ]
9
9
 
10
- module Termtter::Client
11
- add_filter do |statuses, event|
10
+ config.plugins.expand_tinyurl.set_default(:shortters, [])
11
+ config.plugins.expand_tinyurl.set_default(:skip_users, [])
12
+
13
+ # for Ruby 1.8
14
+ unless String.public_method_defined?(:force_encoding)
15
+ class String
16
+ def force_encoding(enc)
17
+ self
18
+ end
19
+ end
20
+
21
+ module Encoding
22
+ UTF_8 = nil
23
+ end
24
+ end
25
+
26
+ Termtter::Client::register_hook(
27
+ :name => :expand_tinyurl,
28
+ :point => :filter_for_output,
29
+ :exec_proc => lambda do |statuses, event|
30
+ shortters = URL_SHORTTERS + config.plugins.expand_tinyurl.shortters
31
+ skip_users = config.plugins.expand_tinyurl.skip_users
12
32
  statuses.each do |s|
13
- URL_SHORTTERS.each do |site|
33
+ skip_users.include?(s.user.screen_name) and next
34
+ shortters.each do |site|
14
35
  s.text.gsub!(site[:pattern]) do |m|
15
36
  expand_url(site[:host], $2) || $1
16
37
  end
@@ -18,7 +39,7 @@ module Termtter::Client
18
39
  end
19
40
  statuses
20
41
  end
21
- end
42
+ )
22
43
 
23
44
  def expand_url(host, path)
24
45
  http_class = Net::HTTP
@@ -30,5 +51,5 @@ def expand_url(host, path)
30
51
  end
31
52
  res = http_class.new(host).head(path)
32
53
  return nil unless res.code == "301" or res.code == "302"
33
- res['Location']
54
+ res['Location'].force_encoding(Encoding::UTF_8)
34
55
  end