jugyo-termtter 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -16,7 +16,7 @@ Run:
16
16
 
17
17
  == REQUIREMENTS:
18
18
 
19
- * json
19
+ * json_pure
20
20
  * configatron
21
21
 
22
22
  == INSTALL:
@@ -62,7 +62,6 @@ http://wiki.github.com/jugyo/termtter/home (in Japanese)
62
62
 
63
63
  == TODO:
64
64
 
65
- - newgem を使わないようにする
66
65
  - rubytter を使うようにする
67
66
  - filter と plugin を統一する
68
67
  - plugin => plugins (ディレクトリ名変更)
data/lib/plugin/me.rb ADDED
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Termtter::Client
3
+ register_command(
4
+ :name => :me, :aliases => [],
5
+ :exec_proc => lambda {|arg|
6
+ myname = configatron.user_name
7
+ call_hooks(Termtter::API.twitter.get_user_timeline(myname), :list_user_timeline)
8
+ },
9
+ :help => ['me', 'show my timeline']
10
+ )
11
+ end
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Termtter::Client
3
+ register_command(
4
+ :name => :random, :aliases => [:rand],
5
+ :exec_proc => lambda {|_|
6
+
7
+ unless public_storage[:log]
8
+ puts 'Error: You should load "log" plugin!'
9
+ return
10
+ end
11
+
12
+ status = public_storage[:log][rand(public_storage[:log].size)]
13
+ unless status
14
+ puts 'No status.'
15
+ return
16
+ end
17
+
18
+ call_commands("update #{status.text}")
19
+
20
+ },
21
+ :help => ['random', 'random post']
22
+ )
23
+ end
data/lib/termtter.rb CHANGED
@@ -14,13 +14,6 @@ require 'readline'
14
14
  require 'enumerator'
15
15
  require 'configatron'
16
16
 
17
- Thread.abort_on_exception = true
18
-
19
- configatron.set_default(:update_interval, 300)
20
- configatron.set_default(:prompt, '> ')
21
- configatron.set_default(:enable_ssl, false)
22
- configatron.proxy.set_default(:port, '8080')
23
-
24
17
  require 'termtter/twitter'
25
18
  require 'termtter/connection'
26
19
  require 'termtter/status'
@@ -31,6 +24,7 @@ require 'termtter/task'
31
24
  require 'termtter/task_manager'
32
25
  require 'termtter/client'
33
26
  require 'termtter/api'
27
+ require 'termtter/system_extensions'
34
28
  require 'termtter/version'
35
29
 
36
30
  module Termtter
@@ -45,95 +39,6 @@ if RUBY_VERSION < '1.8.7'
45
39
  end
46
40
  end
47
41
 
48
- def win?
49
- RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
50
- end
51
-
52
- if win?
53
- require 'iconv'
54
- require 'Win32API'
55
- $wGetACP = Win32API.new('kernel32','GetACP','','I')
56
-
57
- module Readline
58
- $iconv_sj_to_u8 = Iconv.new('UTF-8', "CP#{$wGetACP.call()}")
59
- alias :old_readline :readline
60
- def readline(*a)
61
- str = old_readline(*a)
62
- out = ''
63
- loop do
64
- begin
65
- out << $iconv_sj_to_u8.iconv(str)
66
- break
67
- rescue Iconv::Failure
68
- out << "#{$!.success}?"
69
- str = $!.failed[1..-1]
70
- end
71
- end
72
- return out
73
- end
74
- module_function :old_readline, :readline
75
- end
76
-
77
- $wSetConsoleTextAttribute = Win32API.new('kernel32','SetConsoleTextAttribute','II','I')
78
- $wGetConsoleScreenBufferInfo = Win32API.new("kernel32", "GetConsoleScreenBufferInfo", ['l', 'p'], 'i')
79
- $wGetStdHandle = Win32API.new('kernel32','GetStdHandle','I','I')
80
- $wGetACP = Win32API.new('kernel32','GetACP','','I')
81
-
82
- $hStdOut = $wGetStdHandle.call(0xFFFFFFF5)
83
- lpBuffer = ' ' * 22
84
- $wGetConsoleScreenBufferInfo.call($hStdOut, lpBuffer)
85
- $oldColor = lpBuffer.unpack('SSSSSssssSS')[4]
86
-
87
- $colorMap = {
88
- 0 => 0x07|0x00|0x00|0x00, # black/white
89
- 37 => 0x08|0x00|0x00|0x00, # white/intensity
90
- 31 => 0x04|0x08|0x00|0x00, # red/red
91
- 32 => 0x02|0x08|0x00|0x00, # green/green
92
- 33 => 0x06|0x08|0x00|0x00, # yellow/yellow
93
- 34 => 0x01|0x08|0x00|0x00, # blue/blue
94
- 35 => 0x05|0x08|0x00|0x00, # magenta/purple
95
- 36 => 0x03|0x08|0x00|0x00, # cyan/aqua
96
- 39 => 0x07, # default
97
- 40 => 0x00|0x00|0xf0|0x00, # background:white
98
- 41 => 0x07|0x00|0x40|0x00, # background:red
99
- 42 => 0x07|0x00|0x20|0x00, # background:green
100
- 43 => 0x07|0x00|0x60|0x00, # background:yellow
101
- 44 => 0x07|0x00|0x10|0x00, # background:blue
102
- 45 => 0x07|0x00|0x50|0x80, # background:magenta
103
- 46 => 0x07|0x00|0x30|0x80, # background:cyan
104
- 47 => 0x07|0x00|0x70|0x80, # background:gray
105
- 49 => 0x70, # default
106
- 90 => 0x07|0x00|0x00|0x00, # erase/white
107
- }
108
- $iconv_u8_to_sj = Iconv.new("CP#{$wGetACP.call()}", 'UTF-8')
109
- def print(str)
110
- str.to_s.gsub("\xef\xbd\x9e", "\xe3\x80\x9c").split(/(\e\[\d*[a-zA-Z])/).each do |token|
111
- case token
112
- when /\e\[(\d+)m/
113
- $wSetConsoleTextAttribute.call $hStdOut, $colorMap[$1.to_i].to_i
114
- when /\e\[\d*[a-zA-Z]/
115
- # do nothing
116
- else
117
- loop do
118
- begin
119
- STDOUT.print $iconv_u8_to_sj.iconv(token)
120
- break
121
- rescue Iconv::Failure
122
- STDOUT.print "#{$!.success}?"
123
- token = $!.failed[1..-1]
124
- end
125
- end
126
- end
127
- end
128
- $wSetConsoleTextAttribute.call $hStdOut, $oldColor
129
- $iconv_u8_to_sj.iconv(nil)
130
- end
131
- def puts(str)
132
- print str
133
- STDOUT.puts
134
- end
135
- end
136
-
137
42
  def plugin(s, init = {})
138
43
  unless init.empty?
139
44
  init.each do |key, value|
@@ -19,6 +19,11 @@ module Termtter
19
19
  @@main_thread = nil
20
20
  @@input_thread = nil
21
21
  @@task_manager = Termtter::TaskManager.new
22
+ configatron.set_default(:update_interval, 300)
23
+ configatron.set_default(:prompt, '> ')
24
+ configatron.set_default(:enable_ssl, false)
25
+ configatron.proxy.set_default(:port, '8080')
26
+ Thread.abort_on_exception = true
22
27
  end
23
28
 
24
29
  def public_storage
@@ -250,7 +255,9 @@ module Termtter
250
255
  end
251
256
 
252
257
  def setup_readline
253
- Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
258
+ if Readline.respond_to?(:basic_word_break_characters=)
259
+ Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
260
+ end
254
261
  Readline.completion_proc = lambda {|input|
255
262
  begin
256
263
  # FIXME: when migrate to Termtter::Command
@@ -70,7 +70,7 @@ module Termtter
70
70
  end
71
71
 
72
72
  def commands
73
- aliases.unshift(name)
73
+ [name] + aliases
74
74
  end
75
75
  end
76
76
  end
@@ -0,0 +1,88 @@
1
+ def win?
2
+ RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
3
+ end
4
+
5
+ if win?
6
+ require 'iconv'
7
+ require 'Win32API'
8
+ $wGetACP = Win32API.new('kernel32','GetACP','','I')
9
+
10
+ module Readline
11
+ $iconv_sj_to_u8 = Iconv.new('UTF-8', "CP#{$wGetACP.call()}")
12
+ alias :old_readline :readline
13
+ def readline(*a)
14
+ str = old_readline(*a)
15
+ out = ''
16
+ loop do
17
+ begin
18
+ out << $iconv_sj_to_u8.iconv(str)
19
+ break
20
+ rescue Iconv::Failure
21
+ out << "#{$!.success}?"
22
+ str = $!.failed[1..-1]
23
+ end
24
+ end
25
+ return out
26
+ end
27
+ module_function :old_readline, :readline
28
+ end
29
+
30
+ $wSetConsoleTextAttribute = Win32API.new('kernel32','SetConsoleTextAttribute','II','I')
31
+ $wGetConsoleScreenBufferInfo = Win32API.new("kernel32", "GetConsoleScreenBufferInfo", ['l', 'p'], 'i')
32
+ $wGetStdHandle = Win32API.new('kernel32','GetStdHandle','I','I')
33
+ $wGetACP = Win32API.new('kernel32','GetACP','','I')
34
+
35
+ $hStdOut = $wGetStdHandle.call(0xFFFFFFF5)
36
+ lpBuffer = ' ' * 22
37
+ $wGetConsoleScreenBufferInfo.call($hStdOut, lpBuffer)
38
+ $oldColor = lpBuffer.unpack('SSSSSssssSS')[4]
39
+
40
+ $colorMap = {
41
+ 0 => 0x07|0x00|0x00|0x00, # black/white
42
+ 37 => 0x08|0x00|0x00|0x00, # white/intensity
43
+ 31 => 0x04|0x08|0x00|0x00, # red/red
44
+ 32 => 0x02|0x08|0x00|0x00, # green/green
45
+ 33 => 0x06|0x08|0x00|0x00, # yellow/yellow
46
+ 34 => 0x01|0x08|0x00|0x00, # blue/blue
47
+ 35 => 0x05|0x08|0x00|0x00, # magenta/purple
48
+ 36 => 0x03|0x08|0x00|0x00, # cyan/aqua
49
+ 39 => 0x07, # default
50
+ 40 => 0x00|0x00|0xf0|0x00, # background:white
51
+ 41 => 0x07|0x00|0x40|0x00, # background:red
52
+ 42 => 0x07|0x00|0x20|0x00, # background:green
53
+ 43 => 0x07|0x00|0x60|0x00, # background:yellow
54
+ 44 => 0x07|0x00|0x10|0x00, # background:blue
55
+ 45 => 0x07|0x00|0x50|0x80, # background:magenta
56
+ 46 => 0x07|0x00|0x30|0x80, # background:cyan
57
+ 47 => 0x07|0x00|0x70|0x80, # background:gray
58
+ 49 => 0x70, # default
59
+ 90 => 0x07|0x00|0x00|0x00, # erase/white
60
+ }
61
+ $iconv_u8_to_sj = Iconv.new("CP#{$wGetACP.call()}", 'UTF-8')
62
+ def print(str)
63
+ str.to_s.gsub("\xef\xbd\x9e", "\xe3\x80\x9c").split(/(\e\[\d*[a-zA-Z])/).each do |token|
64
+ case token
65
+ when /\e\[(\d+)m/
66
+ $wSetConsoleTextAttribute.call $hStdOut, $colorMap[$1.to_i].to_i
67
+ when /\e\[\d*[a-zA-Z]/
68
+ # do nothing
69
+ else
70
+ loop do
71
+ begin
72
+ STDOUT.print $iconv_u8_to_sj.iconv(token)
73
+ break
74
+ rescue Iconv::Failure
75
+ STDOUT.print "#{$!.success}?"
76
+ token = $!.failed[1..-1]
77
+ end
78
+ end
79
+ end
80
+ end
81
+ $wSetConsoleTextAttribute.call $hStdOut, $oldColor
82
+ $iconv_u8_to_sj.iconv(nil)
83
+ end
84
+ def puts(str)
85
+ print str
86
+ STDOUT.puts
87
+ end
88
+ end
data/lib/termtter/task.rb CHANGED
@@ -2,15 +2,16 @@
2
2
 
3
3
  module Termtter
4
4
  class Task
5
- attr_accessor :name, :exec_at, :exec_proc, :interval
5
+ attr_accessor :name, :exec_at, :exec_proc, :interval, :work
6
6
  def initialize(args = {}, &block)
7
7
  @name = args[:name]
8
8
  @exec_at = Time.now + (args[:after] || 0)
9
9
  @interval = args[:interval]
10
10
  @exec_proc = block || lambda {}
11
+ @work = true
11
12
  end
12
13
  def execute
13
- exec_proc.call
14
+ exec_proc.call(self) if work
14
15
  end
15
16
  end
16
17
  end
@@ -34,7 +34,7 @@ module Termtter
34
34
  end
35
35
 
36
36
  def step
37
- pull_due_tasks().each do |task|
37
+ pull_due_tasks.each do |task|
38
38
  invoke_and_wait do
39
39
  task.execute
40
40
  end
@@ -96,7 +96,7 @@ module Termtter
96
96
  time_now = Time.now
97
97
  due_tasks = []
98
98
  @tasks.delete_if do |key, task|
99
- if task.exec_at <= time_now
99
+ if task.work && task.exec_at <= time_now
100
100
  due_tasks << task
101
101
  if task.interval
102
102
  task.exec_at = time_now + task.interval
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Termtter
3
- VERSION = '0.8.5'
3
+ VERSION = '0.8.6'
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: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -83,6 +83,7 @@ files:
83
83
  - lib/plugin/history.rb
84
84
  - lib/plugin/keyword.rb
85
85
  - lib/plugin/log.rb
86
+ - lib/plugin/me.rb
86
87
  - lib/plugin/modify_arg_hook_sample.rb
87
88
  - lib/plugin/msagent.rb
88
89
  - lib/plugin/multi_reply.rb
@@ -95,6 +96,7 @@ files:
95
96
  - lib/plugin/pre_exec_hook_sample.rb
96
97
  - lib/plugin/primes.rb
97
98
  - lib/plugin/quicklook.rb
99
+ - lib/plugin/random.rb
98
100
  - lib/plugin/reblog.rb
99
101
  - lib/plugin/reload.rb
100
102
  - lib/plugin/say.rb
@@ -118,6 +120,7 @@ files:
118
120
  - lib/termtter/connection.rb
119
121
  - lib/termtter/hook.rb
120
122
  - lib/termtter/status.rb
123
+ - lib/termtter/system_extensions.rb
121
124
  - lib/termtter/task.rb
122
125
  - lib/termtter/task_manager.rb
123
126
  - lib/termtter/twitter.rb