jugyo-termtter 1.0.0 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  = termtter
2
3
 
3
4
  http://github.com/jugyo/termtter
@@ -63,10 +64,10 @@ http://wiki.github.com/jugyo/termtter/home (in Japanese)
63
64
 
64
65
  == TODO:
65
66
 
66
- - filter plugin を統一する
67
- - plugin => plugins (ディレクトリ名変更)
68
- - $HOME 以下に plugin 用のディレクトリを置けるようにする
69
- - コマンドラインオプションでいろいろ指定できるようにする
67
+ - Enhance the document and spec
68
+ - Finalize the Hook specification and integration
69
+ - Improve the UI(a status view, etc...)
70
+ - Build a logging function
70
71
 
71
72
  == LICENSE:
72
73
 
data/Rakefile CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency("highline", ">= 1.5.0")
28
28
  s.add_dependency("termcolor", ">= 0.3.1")
29
29
  s.add_dependency("rubytter", ">= 0.4.8")
30
+ s.add_dependency("sqlite3-ruby", ">= 1.2.4")
30
31
  s.authors = %w(jugyo ujihisa)
31
32
  s.email = 'jugyo.org@gmail.com'
32
33
  s.homepage = 'http://wiki.github.com/jugyo/termtter'
@@ -48,7 +49,7 @@ end
48
49
  namespace :gem do
49
50
  desc 'Install needed gems'
50
51
  task :install do
51
- %w[ json_pure highline termcolor ].each do |gem|
52
+ %w[ json_pure highline termcolor rubytter ].each do |gem|
52
53
  sh "sudo gem install #{gem} -r"
53
54
  end
54
55
  end
@@ -12,7 +12,7 @@ module Termtter::Client
12
12
  :name => :outputz,
13
13
  :points => [:pre_exec_update],
14
14
  :exec_proc => lambda {|cmd, arg|
15
- Thead.new do
15
+ Thread.new do
16
16
  Termtter::API.connection.start('outputz.com', 80) do |http|
17
17
  key = CGI.escape key
18
18
  uri = CGI.escape config.plugins.outputz.uri
@@ -11,7 +11,7 @@ module Termtter::Client
11
11
  :exec_proc => lambda {|arg|
12
12
  unless arg =~ /^\s*$/
13
13
  text = ERB.new(arg).result(binding).gsub(/\n/, ' ')
14
- result = Termtter::API.twitter.update(text)
14
+ result = Termtter::API.twitter.update(text, :source=>Termtter::APP_NAME)
15
15
  puts "=> #{text}"
16
16
  result
17
17
  end
data/lib/termtter.rb CHANGED
@@ -25,37 +25,3 @@ require 'termtter/task_manager'
25
25
  require 'termtter/client'
26
26
  require 'termtter/api'
27
27
  require 'termtter/system_extensions'
28
-
29
- module Termtter
30
- APP_NAME = 'termtter'
31
-
32
- config.system.set_default :conf_dir, File.expand_path('~/.termtter')
33
- CONF_DIR = config.system.conf_dir
34
-
35
- config.system.set_default :conf_file, CONF_DIR + '/config'
36
- CONF_FILE = config.system.conf_file
37
- end
38
-
39
- if RUBY_VERSION < '1.8.7'
40
- class Array
41
- def take(n) self[0...n] end
42
- end
43
- end
44
-
45
- def plugin(name, init = {})
46
- unless init.empty?
47
- init.each do |key, value|
48
- config.plugins.__refer__(name.to_sym).__assign__(key.to_sym, value)
49
- end
50
- end
51
- # FIXME: below path should be replaced by optparsed path
52
- if File.exist?(path = File.expand_path("~/.termtter/plugins/#{name}"))
53
- require path
54
- else
55
- require "plugins/#{name}"
56
- end
57
- rescue LoadError => e
58
- Termtter::Client.handle_error(e)
59
- end
60
-
61
- $:.unshift(Termtter::CONF_DIR) # still does not use
@@ -1,6 +1,16 @@
1
1
  # -*- coding: utf-8 -*-
2
+ require 'fileutils'
2
3
 
3
4
  module Termtter
5
+ APP_NAME = 'termtter'
6
+
7
+ config.system.set_default :conf_dir, File.expand_path('~/.termtter')
8
+ CONF_DIR = config.system.conf_dir
9
+
10
+ config.system.set_default :conf_file, CONF_DIR + '/config'
11
+ CONF_FILE = config.system.conf_file
12
+ $:.unshift(Termtter::CONF_DIR)
13
+
4
14
  class CommandNotFound < StandardError; end
5
15
 
6
16
  module Client
@@ -210,40 +220,11 @@ module Termtter
210
220
 
211
221
  def load_config
212
222
  legacy_config_support() if File.exist? Termtter::CONF_DIR
213
- if File.exist? Termtter::CONF_FILE
214
- load Termtter::CONF_FILE
215
- else
216
- ui = create_highline
217
- username = ui.ask('your twitter username: ')
218
- password = ui.ask('your twitter password: ') { |q| q.echo = false }
219
-
220
- Dir.mkdir(Termtter::CONF_DIR)
221
- File.open(Termtter::CONF_FILE, 'w') {|io|
222
- io.puts '# -*- coding: utf-8 -*-'
223
-
224
- plugins = Dir.glob(File.dirname(__FILE__) + "/../lib/plugins/*.rb").map {|f|
225
- f.match(%r|lib/plugin/(.*?).rb$|)[1]
226
- }
227
- plugins -= %w[stdout standard_plugins]
228
- plugins.each do |p|
229
- io.puts "#plugin '#{p}'"
230
- end
231
-
232
- io.puts
233
- io.puts "config.user_name = '#{username}'"
234
- io.puts "config.password = '#{password}'"
235
- io.puts "#config.update_interval = 120"
236
- io.puts "#config.proxy.host = 'proxy host'"
237
- io.puts "#config.proxy.port = '8080'"
238
- io.puts "#config.proxy.user_name = 'proxy user'"
239
- io.puts "#config.proxy.password = 'proxy password'"
240
- io.puts
241
- io.puts "# vim: set filetype=ruby"
242
- }
243
- puts "generated: ~/.termtter/config"
244
- puts "enjoy!"
245
- load Termtter::CONF_FILE
223
+ unless File.exist?(Termtter::CONF_FILE)
224
+ require 'termtter/config_setup'
225
+ ConfigSetup.run
246
226
  end
227
+ load Termtter::CONF_FILE
247
228
  end
248
229
 
249
230
  def legacy_config_support
@@ -306,6 +287,7 @@ module Termtter
306
287
  @@since_id = statuses[0].id
307
288
  end
308
289
  call_hooks(statuses, :update_friends_timeline)
290
+ Readline.refresh_line
309
291
  statuses
310
292
  rescue OpenURI::HTTPError => e
311
293
  if e.message == '401 Unauthorized'
@@ -373,20 +355,6 @@ module Termtter
373
355
  start_input_thread()
374
356
  end
375
357
 
376
- def create_highline
377
- HighLine.track_eof = false
378
- if $stdin.respond_to?(:getbyte) # for ruby1.9
379
- require 'delegate'
380
- stdin_for_highline = SimpleDelegator.new($stdin)
381
- def stdin_for_highline.getc
382
- getbyte
383
- end
384
- else
385
- stdin_for_highline = $stdin
386
- end
387
- HighLine.new(stdin_for_highline)
388
- end
389
-
390
358
  def handle_error(e)
391
359
  call_new_hooks("on_error", e)
392
360
  rescue => e
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter
4
+ module ConfigSetup
5
+ def run
6
+ ui = create_highline
7
+ username = ui.ask('your twitter username: ')
8
+ password = ui.ask('your twitter password: ') { |q| q.echo = false }
9
+
10
+ Dir.mkdir(Termtter::CONF_DIR) unless File.exists?(Termtter::CONF_DIR)
11
+ File.open(Termtter::CONF_FILE, 'w') {|io|
12
+ io.puts '# -*- coding: utf-8 -*-'
13
+
14
+ io.puts
15
+ io.puts "config.user_name = '#{username}'"
16
+ io.puts "config.password = '#{password}'"
17
+ io.puts "#config.update_interval = 120"
18
+ io.puts "#config.proxy.host = 'proxy host'"
19
+ io.puts "#config.proxy.port = '8080'"
20
+ io.puts "#config.proxy.user_name = 'proxy user'"
21
+ io.puts "#config.proxy.password = 'proxy password'"
22
+ io.puts
23
+ plugins = Dir.glob(File.expand_path(File.dirname(__FILE__) + "/../plugins/*.rb")).map {|f|
24
+ f.match(%r|lib/plugins/(.*?).rb$|)[1]
25
+ }
26
+ plugins -= %w[stdout standard_plugins]
27
+ plugins.each do |p|
28
+ io.puts "#plugin '#{p}'"
29
+ end
30
+ io.puts
31
+ io.puts "# vim: set filetype=ruby"
32
+ }
33
+ puts "generated: ~/.termtter/config"
34
+ puts "enjoy!"
35
+ end
36
+
37
+ module_function :run
38
+
39
+ def self.create_highline
40
+ HighLine.track_eof = false
41
+ if $stdin.respond_to?(:getbyte) # for ruby1.9
42
+ require 'delegate'
43
+ stdin_for_highline = SimpleDelegator.new($stdin)
44
+ def stdin_for_highline.getc
45
+ getbyte
46
+ end
47
+ else
48
+ stdin_for_highline = $stdin
49
+ end
50
+ HighLine.new(stdin_for_highline)
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ def plugin(name, init = {})
4
+ unless init.empty?
5
+ init.each do |key, value|
6
+ config.plugins.__refer__(name.to_sym).__assign__(key.to_sym, value)
7
+ end
8
+ end
9
+ # FIXME: below path should be replaced by optparsed path
10
+ if File.exist?(path = File.expand_path("~/.termtter/plugins/#{name}"))
11
+ require path
12
+ else
13
+ require "plugins/#{name}"
14
+ end
15
+ rescue LoadError => e
16
+ Termtter::Client.handle_error(e)
17
+ end
18
+
19
+ def filter(name, init = {})
20
+ warn "filter method will be removed. Use plugin instead."
21
+ plugin(name, init)
22
+ end
23
+
24
+ require 'dl/import'
25
+ module Readline
26
+ begin
27
+ module LIBREADLINE
28
+ extend DL::Importable
29
+ dlload '/opt/local/lib/libreadline.dylib' # TODO: 環境によってパスを変える必要あり。どうやったらいいかはこれから調べる。
30
+ extern 'int rl_refresh_line(int, int)'
31
+ end
32
+ def self.refresh_line
33
+ LIBREADLINE.rl_refresh_line(0, 0)
34
+ end
35
+ rescue RuntimeError, NameError
36
+ def self.refresh_line;end
37
+ end
38
+ end
39
+
1
40
  def win?
2
41
  RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
3
42
  end
@@ -86,3 +125,17 @@ if win?
86
125
  STDOUT.puts
87
126
  end
88
127
  end
128
+
129
+ unless Array.instance_methods.include?('take')
130
+ class Array
131
+ def take(n) self[0...n] end
132
+ end
133
+ end
134
+
135
+ unless Symbol.instance_methods.include?('to_proc')
136
+ class Symbol
137
+ def to_proc
138
+ Proc.new { |*args| args.shift.__send__(self, *args) }
139
+ end
140
+ end
141
+ end
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Termtter
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.3'
4
4
  end
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: 1.0.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -53,6 +53,16 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.4.8
55
55
  version:
56
+ - !ruby/object:Gem::Dependency
57
+ name: sqlite3-ruby
58
+ type: :runtime
59
+ version_requirement:
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.2.4
65
+ version:
56
66
  description: Termtter is a terminal based Twitter client
57
67
  email: jugyo.org@gmail.com
58
68
  executables:
@@ -131,6 +141,7 @@ files:
131
141
  - lib/termtter/client.rb
132
142
  - lib/termtter/command.rb
133
143
  - lib/termtter/config.rb
144
+ - lib/termtter/config_setup.rb
134
145
  - lib/termtter/connection.rb
135
146
  - lib/termtter/hook.rb
136
147
  - lib/termtter/optparse.rb