jugyo-termtter 0.5.7 → 0.5.8

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.
data/Manifest.txt CHANGED
@@ -4,7 +4,6 @@ PostInstall.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  run_termtter.rb
7
- example_dot_termtter
8
7
  bin/termtter
9
8
  lib/termtter.rb
10
9
  lib/plugin/stdout.rb
@@ -15,6 +14,10 @@ lib/plugin/growl.rb
15
14
  lib/plugin/say.rb
16
15
  lib/plugin/english.rb
17
16
  lib/plugin/completion.rb
17
+ lib/plugin/log.rb
18
+ lib/plugin/favorite.rb
19
+ lib/plugin/plugin.rb
20
+ lib/plugin/erb.rb
18
21
  test/test_termtter.rb
19
22
  test/friends_timeline.json
20
23
  test/search.json
data/README.rdoc CHANGED
@@ -24,13 +24,20 @@ Run:
24
24
  sudo gem source -a http://gems.github.com (you only have to do this once)
25
25
  sudo gem install jugyo-termtter
26
26
 
27
- create configuration file named '.termtter' in your HOME directory.
27
+ Just run a new command termtter.
28
+
29
+ termtter
30
+
31
+ Termtter generates a configuration file named '.termtter' in your HOME directory.
32
+ You can edit the file anytime.
28
33
 
29
34
  vim ~/.termtter
30
35
 
31
36
  configatron.user_name = 'USERNAME'
32
37
  configatron.password = 'PASSWORD'
33
38
 
39
+ To update the config, just restart your termtter proccess.
40
+
34
41
  == LICENSE:
35
42
 
36
43
  (The MIT License)
data/bin/termtter CHANGED
@@ -25,8 +25,10 @@ else
25
25
  io.puts "#plugin '#{p}'"
26
26
  end
27
27
 
28
+ io.puts
28
29
  io.puts "configatron.user_name = '#{username}'"
29
30
  io.puts "configatron.password = '#{password}'"
31
+ io.puts "#configatron.update_interval = 120"
30
32
  io.puts
31
33
  io.puts "# vim: set filetype=ruby"
32
34
  }
data/lib/plugin/erb.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'erb'
2
+
3
+ module Termtter::Client
4
+ add_command /^(update|u)\s+(.*)/ do |m, t|
5
+ text = ERB.new(m[2]).result(binding).gsub(/\n/, ' ')
6
+ unless text.empty?
7
+ t.update_status(text)
8
+ puts "=> #{text}"
9
+ end
10
+ end
11
+ end
12
+
13
+ # erb.rb
14
+ # enable to <%= %> in the command update
15
+ # example:
16
+ # > u erb test <%= 1+1 %>
17
+ # => erb test 2
@@ -0,0 +1,47 @@
1
+ module Termtter::Client
2
+ add_command %r'^(?:favorite|fav)\s+(\d+)$' do |m,t|
3
+ id = m[1]
4
+ res = t.favorite(id)
5
+ if res.code == '200'
6
+ puts "Favorited status ##{id}"
7
+ else
8
+ puts "Failed: #{res}"
9
+ end
10
+ end
11
+
12
+ if public_storage[:log]
13
+ add_command %r'^(?:favorite|fav)\s+/(.+)$' do |m,t|
14
+ pat = Regexp.new(m[1])
15
+ statuses = public_storage[:log].select { |s| s.text =~ pat }
16
+ if statuses.size == 1
17
+ status = statuses.first
18
+ res = t.favorite(status.id)
19
+ if res.code == '200'
20
+ puts %Q(Favorited "#{status.user_screen_name}: #{status.text}")
21
+ else
22
+ puts "Failed: #{res}"
23
+ end
24
+ else
25
+ puts "#{pat} does not match single status"
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ module Termtter
32
+ class Twitter
33
+ def favorite(id)
34
+ uri = "http://twitter.com/favourings/create/#{id}.json"
35
+ req = Net::HTTP::Post.new(uri)
36
+ req.basic_auth(@user_name, @password)
37
+ req.add_field('User-Agent', 'Termtter http://github.com/jugyo/termtter')
38
+ req.add_field('X-Twitter-Client', 'Termtter')
39
+ req.add_field('X-Twitter-Client-URL', 'http://github.com/jugyo/termtter')
40
+ req.add_field('X-Twitter-Client-Version', '0.1')
41
+
42
+ Net::HTTP.start('twitter.com', 80) do |http|
43
+ http.request(req)
44
+ end
45
+ end
46
+ end
47
+ end
data/lib/plugin/growl.rb CHANGED
@@ -1,7 +1,29 @@
1
+ require 'tmpdir'
2
+ require 'uri'
3
+
4
+ def get_icon_path(s)
5
+ cache_dir = "#{Dir.tmpdir}/termtter-icon-cache-dir"
6
+ cache_file = "#{cache_dir}/#{s.user_id}"
7
+ unless File.exist?(cache_file)
8
+ Dir.mkdir(cache_dir) unless File.exist?(cache_dir)
9
+ buf = ""
10
+ File.open(URI.encode(s.user_profile_image_url)) do |f|
11
+ buf = f.read
12
+ end
13
+ File.open(cache_file, "w") do |f|
14
+ f.write(buf)
15
+ end
16
+ end
17
+ cache_file
18
+ end
19
+
1
20
  Termtter::Client.add_hook do |statuses, event|
2
21
  if !statuses.empty? && event == :update_friends_timeline
3
- statuses.each do |s|
4
- system 'growlnotify', 'Termtter', '-m', "#{s.user_screen_name}: #{s.text}", '-n', 'termtter'
22
+ statuses.reverse.each do |s|
23
+ text = s.text.gsub("\n",'')
24
+ icon_path = get_icon_path(s)
25
+ system 'growlnotify', s.user_screen_name, '-m', text,
26
+ '-n', 'termtter', '--image', icon_path
5
27
  end
6
28
  end
7
29
  end
data/lib/plugin/log.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Termtter::Client
2
+ public_storage[:log] = []
3
+
4
+ add_hook do |statuses,event|
5
+ case event
6
+ when :update_friends_timeline
7
+ public_storage[:log] += statuses
8
+ end
9
+ end
10
+
11
+ add_command %r'^/(.+)' do |m,t|
12
+ pat = Regexp.new(m[1])
13
+ statuses = public_storage[:log].select { |s| s.text =~ pat }
14
+ call_hooks(statuses, :list_friends_timeline, t)
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module Termtter::Client
2
+ add_command /^plugin\s+(.*)/ do |m, t|
3
+ plugin m[1]
4
+ end
5
+ end
6
+
7
+ # plugin.rb
8
+ # a dynamic plugin loader
9
+ # example
10
+ # > u <%= not erbed %>
11
+ # => <%= not erbed %>
12
+ # > plugin erb
13
+ # > u <%= 1 + 2 %>
14
+ # => 3
data/lib/plugin/stdout.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require 'erb'
2
+
3
+ configatron.set_default(:timeline_format, '<%= color(time, 90) %> <%= status %> <%= color(id, 90) %>')
4
+
1
5
  def color(str, num)
2
6
  "\e[#{num}m#{str}\e[0m"
3
7
  end
@@ -21,21 +25,24 @@ Termtter::Client.add_hook do |statuses, event|
21
25
  when :update_friends_timeline, :list_friends_timeline
22
26
  time_format = '%H:%M:%S'
23
27
  else
24
- time_format = '%m-%d %H:%d'
28
+ time_format = '%m-%d %H:%M'
25
29
  end
26
- time_str = "(#{s.created_at.strftime(time_format)})"
27
30
 
28
- puts "#{color(time_str, 90)} #{color(status, color_num)}"
31
+ time = "(#{s.created_at.strftime(time_format)})"
32
+ status = color(status, color_num)
33
+ id = s.id
34
+ puts ERB.new(configatron.timeline_format).result(binding)
29
35
  end
30
36
  end
31
37
  when :search
32
38
  statuses.each do |s|
33
39
  text = s.text.gsub("\n", '')
34
40
  color_num = colors[s.user_screen_name.hash % colors.size]
35
- status = "#{s.user_screen_name}: #{text}"
36
- time_str = "(#{s.created_at.strftime('%m-%d %H:%d')})"
37
41
 
38
- puts "#{color(time_str, 90)} #{color(status, color_num)}"
42
+ status = color("#{s.user_screen_name}: #{text}", color_num)
43
+ time = "(#{s.created_at.strftime('%m-%d %H:%M')})"
44
+ id = s.id
45
+ puts ERB.new(configatron.timeline_format).result(binding)
39
46
  end
40
47
  end
41
48
  end
data/lib/termtter.rb CHANGED
@@ -11,6 +11,7 @@ $:.unshift(File.dirname(__FILE__)) unless
11
11
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
12
12
 
13
13
  configatron.set_default(:update_interval, 300)
14
+ configatron.set_default(:prompt, '> ')
14
15
 
15
16
  def plugin(s)
16
17
  require "plugin/#{s}"
@@ -28,7 +29,7 @@ def require(s)
28
29
  end
29
30
 
30
31
  module Termtter
31
- VERSION = '0.5.7'
32
+ VERSION = '0.5.8'
32
33
 
33
34
  class Twitter
34
35
 
@@ -63,6 +64,7 @@ module Termtter
63
64
  results = JSON.parse(open('http://search.twitter.com/search.json?q=' + CGI.escape(query)).read)['results']
64
65
  return results.map do |s|
65
66
  status = Status.new
67
+ status.id = s['id']
66
68
  status.text = s['text']
67
69
  status.created_at = Time.utc(*ParseDate::parsedate(s["created_at"])).localtime
68
70
  status.user_screen_name = s['from_user']
@@ -135,7 +137,6 @@ module Termtter
135
137
 
136
138
  def public_storage
137
139
  @@public_storage ||= {}
138
- return @@public_storage
139
140
  end
140
141
 
141
142
  def call_hooks(statuses, event, tw)
@@ -183,6 +184,8 @@ module Termtter
183
184
  end
184
185
 
185
186
  def run
187
+ puts 'initializing...'
188
+ initialized = false
186
189
  @@pause = false
187
190
  tw = Termtter::Twitter.new(configatron.user_name, configatron.password)
188
191
 
@@ -197,6 +200,7 @@ module Termtter
197
200
  since_id = statuses[0].id
198
201
  end
199
202
  call_hooks(statuses, :update_friends_timeline, tw)
203
+ initialized = true
200
204
 
201
205
  rescue => e
202
206
  puts "Error: #{e}"
@@ -207,8 +211,10 @@ module Termtter
207
211
  end
208
212
  end
209
213
 
214
+ until initialized; end
215
+
210
216
  @@input_thread = Thread.new do
211
- while buf = Readline.readline("", true)
217
+ while buf = Readline.readline(configatron.prompt, true)
212
218
  begin
213
219
  call_commands(buf, tw)
214
220
  rescue CommandNotFound => e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jugyo-termtter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -59,7 +59,6 @@ files:
59
59
  - README.rdoc
60
60
  - Rakefile
61
61
  - run_termtter.rb
62
- - example_dot_termtter
63
62
  - bin/termtter
64
63
  - lib/termtter.rb
65
64
  - lib/plugin/stdout.rb
@@ -70,6 +69,10 @@ files:
70
69
  - lib/plugin/say.rb
71
70
  - lib/plugin/english.rb
72
71
  - lib/plugin/completion.rb
72
+ - lib/plugin/log.rb
73
+ - lib/plugin/favorite.rb
74
+ - lib/plugin/plugin.rb
75
+ - lib/plugin/erb.rb
73
76
  - test/test_termtter.rb
74
77
  - test/friends_timeline.json
75
78
  - test/search.json
data/example_dot_termtter DELETED
@@ -1,11 +0,0 @@
1
- #require 'plugin/english'
2
- #require 'plugin/say'
3
- #require 'plugin/notify-send'
4
- #require 'plugin/uri-open'
5
- #require 'plugin/growl'
6
- #require 'plugin/completion'
7
-
8
- configatron.user_name = 'USERNAME'
9
- configatron.password = 'PASSWORD'
10
- #configatron.update_interval = 120
11
-
@@ -1,58 +0,0 @@
1
- require 'set'
2
-
3
- module Termtter::Client
4
-
5
- public_storage[:users] ||= Set.new
6
-
7
- add_hook do |statuses, event, t|
8
- if !statuses.empty?
9
- case event
10
- when :update_friends_timeline, :replies, :list_user_timeline
11
- statuses.each do |s|
12
- public_storage[:users].add(s.user_screen_name)
13
- s.text.scan(/@[a-zA-Z_0-9]*/).each do |u| # reply
14
- public_storage[:users].add(u.gsub("@","")) unless u == "@"
15
- end
16
- end
17
- end
18
- end
19
- end
20
-
21
- end
22
-
23
- module Termtter
24
- module InputCompletor
25
-
26
- Commands = %w[exit help list pause update resume replies search show uri-open]
27
-
28
- def self.find_candidates(a, b)
29
- if a.empty?
30
- Termtter::Client.public_storage[:users].to_a
31
- else
32
- Termtter::Client.public_storage[:users].
33
- grep(/^#{Regexp.quote a}/i).map {|u| b % u }
34
- end
35
- end
36
-
37
- CompletionProc = proc {|input|
38
- case input
39
- when /^l(ist)? +(.*)/
40
- find_candidates $2, "list %s"
41
- when /^(update|u)\s+(.*)@([^\s]*)$/
42
- find_candidates $3, "#{$1} #{$2}@%s"
43
- when /^uri-open +(.*)/
44
- find_candidates $1, "uri-open %s"
45
- else
46
- Commands.grep(/^#{Regexp.quote input}/)
47
- end
48
- }
49
-
50
- end
51
- end
52
-
53
- Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
54
- Readline.completion_proc = Termtter::InputCompletor::CompletionProc
55
-
56
- # author: bubbles
57
- #
58
- # see also: http://d.hatena.ne.jp/bubbles/20090105/1231145823