termtter 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/plugins/auto_reload.rb +5 -1
- data/lib/plugins/open_url.rb +10 -14
- data/lib/plugins/protected_filter.rb +9 -0
- data/lib/plugins/standard_commands.rb +30 -28
- data/lib/plugins/stdout.rb +64 -4
- data/lib/plugins/uri-open.rb +32 -27
- data/lib/termtter/client.rb +26 -11
- data/lib/termtter/command.rb +24 -9
- data/lib/termtter/config.rb +4 -0
- data/lib/termtter/config_template.erb +1 -4
- data/lib/termtter/version.rb +1 -1
- data/spec/termtter/client_spec.rb +41 -0
- data/spec/termtter/command_spec.rb +68 -35
- metadata +3 -2
data/lib/plugins/auto_reload.rb
CHANGED
data/lib/plugins/open_url.rb
CHANGED
@@ -23,8 +23,8 @@ module Termtter::Client
|
|
23
23
|
:help => ['open_url (TYPABLE|ID|@USER)', 'Open url'],
|
24
24
|
:exec_proc => lambda {|arg|
|
25
25
|
Thread.new(arg) do |arg|
|
26
|
-
if
|
27
|
-
status.text.gsub(URI.regexp) {|uri|
|
26
|
+
if status = Termtter::Client.typable_id_to_data(arg)
|
27
|
+
status.text.gsub(URI.regexp(['http', 'https'])) {|uri|
|
28
28
|
open_uri(uri)
|
29
29
|
}
|
30
30
|
else
|
@@ -33,27 +33,23 @@ module Termtter::Client
|
|
33
33
|
user = $1
|
34
34
|
statuses = Termtter::API.twitter.user_timeline(user)
|
35
35
|
return if statuses.empty?
|
36
|
-
statuses[0].text.gsub(URI.regexp) {|uri| open_uri(uri) }
|
36
|
+
statuses[0].text.gsub(URI.regexp(['http', 'https'])) {|uri| open_uri(uri) }
|
37
37
|
when /^\d+/
|
38
|
-
Termtter::API.twitter.show(arg).text.gsub(URI.regexp) {|uri| open_uri(uri) }
|
38
|
+
Termtter::API.twitter.show(arg).text.gsub(URI.regexp(['http', 'https'])) {|uri| open_uri(uri) }
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
},
|
43
43
|
:completion_proc => lambda {|cmd, arg|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
find_user_candidates $1, "#{cmd} @%s"
|
50
|
-
when /(\d+)/
|
51
|
-
find_status_ids(arg).map{|id| "#{cmd} #{$1}"}
|
52
|
-
end
|
44
|
+
case arg
|
45
|
+
when /@(.*)/
|
46
|
+
find_user_candidates $1, "#{cmd} @%s"
|
47
|
+
when /(\d+)/
|
48
|
+
find_status_ids(arg).map{|id| "#{cmd} #{$1}"}
|
53
49
|
end
|
54
50
|
}
|
55
51
|
)
|
56
52
|
end
|
57
53
|
|
58
54
|
#Optional Setting
|
59
|
-
# config.plugins.open_url.browser = firefox
|
55
|
+
# config.plugins.open_url.browser = 'firefox'
|
@@ -11,37 +11,27 @@ module Termtter::Client
|
|
11
11
|
|
12
12
|
register_command(
|
13
13
|
:name => :reload,
|
14
|
-
:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
unless
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
Readline.refresh_line
|
23
|
-
end
|
24
|
-
rescue OpenURI::HTTPError => e
|
25
|
-
if e.message == '401 Unauthorized'
|
26
|
-
puts 'Could not login'
|
27
|
-
puts 'plese check your account settings'
|
28
|
-
exit!
|
29
|
-
end
|
30
|
-
rescue => e
|
31
|
-
handle_error(e)
|
14
|
+
:exec => lambda {|arg|
|
15
|
+
args = @since_id ? [{:since_id => @since_id}] : []
|
16
|
+
statuses = Termtter::API.twitter.friends_timeline(*args)
|
17
|
+
unless statuses.empty?
|
18
|
+
print "\e[1K\e[0G" unless win?
|
19
|
+
@since_id = statuses[0].id
|
20
|
+
output(statuses, :update_friends_timeline)
|
21
|
+
Readline.refresh_line
|
32
22
|
end
|
33
23
|
}
|
34
24
|
)
|
35
25
|
|
36
26
|
register_command(
|
37
|
-
:name => :update, :
|
38
|
-
:
|
27
|
+
:name => :update, :alias => :u,
|
28
|
+
:exec => lambda {|arg|
|
39
29
|
unless arg.empty?
|
40
30
|
result = Termtter::API.twitter.update(arg)
|
41
31
|
puts TermColor.parse("updated => #{result.text} <90>#{result.id}</90>")
|
42
32
|
end
|
43
33
|
},
|
44
|
-
:
|
34
|
+
:completion => lambda {|cmd, args|
|
45
35
|
if /(.*)@([^\s]*)$/ =~ args
|
46
36
|
find_user_candidates $2, "#{cmd} #{$1}@%s"
|
47
37
|
end
|
@@ -184,9 +174,13 @@ module Termtter::Client
|
|
184
174
|
register_command(
|
185
175
|
:name => :replies, :aliases => [:r],
|
186
176
|
:exec_proc => lambda {|arg|
|
187
|
-
|
177
|
+
res = Termtter::API.twitter.replies
|
178
|
+
unless arg.empty?
|
179
|
+
res = res.map {|e| e.user.screen_name == arg ? e : nil }.compact
|
180
|
+
end
|
181
|
+
output(res, :replies)
|
188
182
|
},
|
189
|
-
:help => ["replies,r", "List the
|
183
|
+
:help => ["replies,r", "List the replies"]
|
190
184
|
)
|
191
185
|
|
192
186
|
register_command(
|
@@ -268,7 +262,11 @@ module Termtter::Client
|
|
268
262
|
word = $1
|
269
263
|
raise "Not implemented yet."
|
270
264
|
else
|
271
|
-
|
265
|
+
if public_storage[:typable_id] && typable_id?(arg)
|
266
|
+
id = typable_id_convert(arg)
|
267
|
+
else
|
268
|
+
return
|
269
|
+
end
|
272
270
|
end
|
273
271
|
|
274
272
|
r = Termtter::API.twitter.favorite id
|
@@ -281,10 +279,14 @@ module Termtter::Client
|
|
281
279
|
when /(\d+)/
|
282
280
|
find_status_ids(arg).map{|id| "#{cmd} #{id}"}
|
283
281
|
else
|
284
|
-
|
282
|
+
if data = Termtter::Client.typable_id_to_data(arg)
|
283
|
+
"#{cmd} #{data}"
|
284
|
+
else
|
285
|
+
%w(favorite).grep(/^#{Regexp.quote arg}/)
|
286
|
+
end
|
285
287
|
end
|
286
288
|
},
|
287
|
-
:help => ['favorite,fav (ID|@USER|/WORD)', 'Mark a status as a favorite']
|
289
|
+
:help => ['favorite,fav (ID|@USER|TYPABLE|/WORD)', 'Mark a status as a favorite']
|
288
290
|
)
|
289
291
|
|
290
292
|
def self.show_settings(conf, level = 0)
|
@@ -417,7 +419,7 @@ module Termtter::Client
|
|
417
419
|
public_storage[:plugins].sort
|
418
420
|
end
|
419
421
|
},
|
420
|
-
:help => ['
|
422
|
+
:help => ['plug FILE', 'Load a plugin']
|
421
423
|
)
|
422
424
|
|
423
425
|
register_command(
|
@@ -453,7 +455,7 @@ module Termtter::Client
|
|
453
455
|
when /^\s*(\d+)\s+(.+)$/
|
454
456
|
s = Termtter::API.twitter.show($1) rescue nil
|
455
457
|
if s
|
456
|
-
update_with_user_and_id($2, s.user.screen_name, id)
|
458
|
+
update_with_user_and_id($2, s.user.screen_name, s.id)
|
457
459
|
end
|
458
460
|
when /^\s*@(\w+)/
|
459
461
|
in_reply_to_status_id = Termtter::API.twitter.user($1).status.id rescue nil
|
data/lib/plugins/stdout.rb
CHANGED
@@ -7,14 +7,51 @@ require 'tempfile'
|
|
7
7
|
config.plugins.stdout.set_default(:colors, (31..36).to_a + (91..96).to_a)
|
8
8
|
config.plugins.stdout.set_default(
|
9
9
|
:timeline_format,
|
10
|
-
'<90><%=time
|
11
|
-
'<90><%=
|
10
|
+
'<90><%=time%> [<%=status_id%>]</90> <<%=color%>><%=s.user.screen_name%>: <%=text%></<%=color%>> ' +
|
11
|
+
'<90><%=reply_to_status_id ? " (reply_to [#{reply_to_status_id}]) " : ""%><%=source%></90>'
|
12
12
|
)
|
13
13
|
config.plugins.stdout.set_default(:enable_pager, true)
|
14
14
|
config.plugins.stdout.set_default(:pager, 'less -R -f +G')
|
15
15
|
config.plugins.stdout.set_default(:window_height, 50)
|
16
|
+
config.plugins.stdout.set_default(:typable_ids, ('aa'..'zz').to_a)
|
17
|
+
config.plugins.stdout.set_default(:typable_id_prefix, '$')
|
16
18
|
|
17
19
|
module Termtter
|
20
|
+
class TypableIdGenerator
|
21
|
+
def initialize(ids)
|
22
|
+
if not ids.kind_of?(Array)
|
23
|
+
raise ArgumentError, 'ids should be an Array'
|
24
|
+
elsif ids.empty?
|
25
|
+
raise ArgumentError, 'ids should not be empty'
|
26
|
+
end
|
27
|
+
@ids = ids
|
28
|
+
@table = {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def next(data)
|
32
|
+
id = @ids.shift
|
33
|
+
@ids.push id
|
34
|
+
@table[id] = data
|
35
|
+
id
|
36
|
+
end
|
37
|
+
|
38
|
+
def get(id)
|
39
|
+
@table[id]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module Client
|
44
|
+
@typable_id_generator = TypableIdGenerator.new(config.plugins.stdout.typable_ids)
|
45
|
+
|
46
|
+
def self.data_to_typable_id(data)
|
47
|
+
id = config.plugins.stdout.typable_id_prefix + @typable_id_generator.next(data)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.typable_id_to_data(id)
|
51
|
+
@typable_id_generator.get(id)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
18
55
|
class StdOut < Hook
|
19
56
|
def initialize
|
20
57
|
super(:name => :stdout, :points => [:output])
|
@@ -43,7 +80,14 @@ module Termtter
|
|
43
80
|
statuses.each do |s|
|
44
81
|
text = TermColor.escape(s.text)
|
45
82
|
color = config.plugins.stdout.colors[s.user.id.to_i % config.plugins.stdout.colors.size]
|
46
|
-
|
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
|
+
|
47
91
|
time = "(#{Time.parse(s.created_at).strftime(time_format)})"
|
48
92
|
source =
|
49
93
|
case s.source
|
@@ -68,10 +112,26 @@ module Termtter
|
|
68
112
|
end
|
69
113
|
|
70
114
|
Client.register_hook(StdOut.new)
|
115
|
+
|
116
|
+
Client.register_hook(
|
117
|
+
:name => :stdout_typable_id,
|
118
|
+
:point => /^modify_arg_for_.*/,
|
119
|
+
:exec => lambda { |cmd, arg|
|
120
|
+
if arg
|
121
|
+
prefix = config.plugins.stdout.typable_id_prefix
|
122
|
+
arg.gsub(/#{Regexp.quote(prefix)}\w+/) do |id|
|
123
|
+
Termtter::Client.typable_id_to_data(id[1..-1]) || id
|
124
|
+
end
|
125
|
+
else
|
126
|
+
arg
|
127
|
+
end
|
128
|
+
}
|
129
|
+
)
|
71
130
|
end
|
72
131
|
|
73
132
|
# stdout.rb
|
74
133
|
# output statuses to stdout
|
75
134
|
# example config
|
76
135
|
# config.plugins.stdout.colors = [:none, :red, :green, :yellow, :blue, :magenta, :cyan]
|
77
|
-
# config.plugins.stdout.timeline_format = '<90><%=time
|
136
|
+
# config.plugins.stdout.timeline_format = '<90><%=time%> [<%=status_id%>]</90> <<%=color%>><%=s.user.screen_name%>: <%=text%></<%=color%>> ' +
|
137
|
+
# '<90><%=reply_to_status_id ? " (reply_to [#{reply_to_status_id}]) " : ""%><%=source%></90>'
|
data/lib/plugins/uri-open.rb
CHANGED
@@ -8,39 +8,43 @@ module Termtter::Client
|
|
8
8
|
:points => [:output],
|
9
9
|
:exec_proc => lambda {|statuses, event|
|
10
10
|
statuses.each do |s|
|
11
|
-
public_storage[:uris]
|
11
|
+
public_storage[:uris] = s[:text].scan(%r|https?://[^\s]+|) + public_storage[:uris]
|
12
12
|
end
|
13
13
|
}
|
14
14
|
)
|
15
15
|
|
16
16
|
def self.open_uri(uri)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
case RUBY_PLATFORM
|
21
|
-
when /linux/
|
22
|
-
system 'firefox', uri
|
23
|
-
when /mswin(?!ce)|mingw|bccwin/
|
24
|
-
system 'explorer', uri
|
17
|
+
cmd =
|
18
|
+
unless config.plugins.uri_open.browser.empty?
|
19
|
+
config.plugins.uri_open.browser
|
25
20
|
else
|
26
|
-
|
21
|
+
case RUBY_PLATFORM
|
22
|
+
when /linux/; 'firefox'
|
23
|
+
when /mswin(?!ce)|mingw|bccwin/; 'explorer'
|
24
|
+
else; 'open'
|
25
|
+
end
|
27
26
|
end
|
28
|
-
|
27
|
+
system cmd, uri
|
29
28
|
end
|
30
29
|
|
31
30
|
register_command(
|
32
31
|
:name => :'uri-open', :aliases => [:uo],
|
33
|
-
:exec_proc => lambda{|arg|
|
32
|
+
:exec_proc => lambda {|arg|
|
34
33
|
case arg
|
35
|
-
when
|
36
|
-
public_storage[:uris].
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
when ''
|
35
|
+
open_uri public_storage[:uris].shift
|
36
|
+
when /^\s*all\s*$/
|
37
|
+
public_storage[:uris].
|
38
|
+
each {|uri| open_uri(uri) }.
|
39
|
+
clear
|
40
40
|
when /^\s*list\s*$/
|
41
|
-
public_storage[:uris].
|
42
|
-
|
43
|
-
|
41
|
+
public_storage[:uris].
|
42
|
+
enum_for(:each_with_index).
|
43
|
+
to_a.
|
44
|
+
reverse.
|
45
|
+
each do |uri, index|
|
46
|
+
puts "#{index}: #{uri}"
|
47
|
+
end
|
44
48
|
when /^\s*delete\s+(\d+)\s*$/
|
45
49
|
puts 'delete'
|
46
50
|
public_storage[:uris].delete_at($1.to_i)
|
@@ -48,19 +52,20 @@ module Termtter::Client
|
|
48
52
|
public_storage[:uris].clear
|
49
53
|
puts "clear uris"
|
50
54
|
when /^\s*(\d+)\s*$/
|
51
|
-
open_uri(public_storage[:uris]
|
52
|
-
|
55
|
+
open_uri(public_storage[:uris].delete_at($1.to_i))
|
56
|
+
else
|
57
|
+
puts "**parse error in uri-open**"
|
53
58
|
end
|
54
59
|
},
|
55
|
-
:completion_proc => lambda{|cmd, arg|
|
56
|
-
%w(list delete clear).grep(/^#{Regexp.quote arg}/).map{|a| "#{cmd} #{a}"}
|
60
|
+
:completion_proc => lambda {|cmd, arg|
|
61
|
+
%w(all list delete clear).grep(/^#{Regexp.quote arg}/).map {|a| "#{cmd} #{a}" }
|
57
62
|
}
|
58
63
|
)
|
59
64
|
end
|
60
|
-
# ~/.termtter
|
65
|
+
# ~/.termtter/config
|
61
66
|
# plugin 'uri-open'
|
62
67
|
#
|
63
|
-
# see also: http://ujihisa.
|
68
|
+
# see also: http://ujihisa.blogspot.com/2009/05/fixed-uri-open-of-termtter.html
|
64
69
|
#
|
65
70
|
# KNOWN BUG
|
66
|
-
# * In Debian, exit or C-c in the termtter
|
71
|
+
# * In Debian, exit or C-c in the termtter would kill your firefox.
|
data/lib/termtter/client.rb
CHANGED
@@ -21,6 +21,9 @@ module Termtter
|
|
21
21
|
config.set_default(:update_interval, 300)
|
22
22
|
config.set_default(:prompt, '> ')
|
23
23
|
config.set_default(:devel, false)
|
24
|
+
config.set_default(:stdout, true)
|
25
|
+
config.set_default(:standard_commands, true)
|
26
|
+
config.set_default(:auto_reload, true)
|
24
27
|
|
25
28
|
Thread.abort_on_exception = true
|
26
29
|
|
@@ -74,18 +77,33 @@ module Termtter
|
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
77
|
-
def register_command(arg)
|
80
|
+
def register_command(arg, opts = {}, &block)
|
78
81
|
command = case arg
|
79
82
|
when Command
|
80
83
|
arg
|
81
84
|
when Hash
|
82
85
|
Command.new(arg)
|
86
|
+
when String
|
87
|
+
options = { :name => arg }
|
88
|
+
options.merge!(opts)
|
89
|
+
options[:exec_proc] = block
|
90
|
+
Command.new(options)
|
83
91
|
else
|
84
|
-
raise ArgumentError, 'must be given Termtter::Command or
|
92
|
+
raise ArgumentError, 'must be given Termtter::Command, Hash or String with block'
|
85
93
|
end
|
86
94
|
@commands[command.name] = command
|
87
95
|
end
|
88
96
|
|
97
|
+
def add_command(name)
|
98
|
+
if block_given?
|
99
|
+
command = Command.new(:name => name)
|
100
|
+
yield command
|
101
|
+
@commands[command.name] = command
|
102
|
+
else
|
103
|
+
raise ArgumentError, 'must be given block to set parameters'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
89
107
|
def clear_command
|
90
108
|
@commands.clear
|
91
109
|
end
|
@@ -120,11 +138,11 @@ module Termtter
|
|
120
138
|
statuses = statuses.sort_by{|s|s.id}
|
121
139
|
call_hooks(:pre_filter, statuses, event)
|
122
140
|
|
123
|
-
filtered = statuses.map(&:dup)
|
141
|
+
filtered = apply_filters_for_hook(:filter_for_output, statuses.map(&:dup), event)
|
142
|
+
|
124
143
|
@filters.each do |f| # TODO: code for compatibility. delete someday.
|
125
|
-
|
144
|
+
filtered = f.call(filtered, event)
|
126
145
|
end
|
127
|
-
apply_filters_for_hook(:filter_for_output, statuses, event)
|
128
146
|
|
129
147
|
call_hooks(:post_filter, filtered, event)
|
130
148
|
get_hooks(:output).each do |hook|
|
@@ -325,12 +343,9 @@ module Termtter
|
|
325
343
|
|
326
344
|
@init_block.call(self) if @init_block
|
327
345
|
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
plug 'auto_reload'
|
332
|
-
end
|
333
|
-
|
346
|
+
plug 'stdout' if config.stdout
|
347
|
+
plug 'standard_commands' if config.standard_commands
|
348
|
+
plug 'auto_reload' if config.auto_reload
|
334
349
|
plug 'devel' if config.devel
|
335
350
|
|
336
351
|
config.system.load_plugins.each do |plugin|
|
data/lib/termtter/command.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
module Termtter
|
4
|
-
|
5
4
|
class Command
|
6
|
-
|
7
5
|
attr_accessor :name, :aliases, :exec_proc, :completion_proc, :help
|
8
6
|
|
9
7
|
# args
|
10
|
-
# name: Symbol as command name
|
8
|
+
# name: (required) Symbol as command name
|
11
9
|
# aliases: Array of command alias (ex. ['u', 'up'])
|
12
10
|
# exec_proc: Proc for procedure of the command. If need the proc must return object for hook.
|
13
11
|
# completion_proc: Proc for input completion. The proc must return Array of candidates (Optional)
|
14
12
|
# help: help text for the command (Optional)
|
15
13
|
def initialize(args)
|
16
14
|
raise ArgumentError, ":name is not given." unless args.has_key?(:name)
|
15
|
+
args = args.dup
|
17
16
|
args[:exec_proc] ||= args[:exec]
|
18
17
|
args[:completion_proc] ||= args[:completion]
|
19
18
|
args[:aliases] ||= [args[:alias]].compact
|
@@ -27,14 +26,16 @@ module Termtter
|
|
27
26
|
set cfg
|
28
27
|
end
|
29
28
|
|
29
|
+
# set :: Hash -> ()
|
30
30
|
def set(cfg)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
self.name = cfg[:name].to_sym
|
32
|
+
self.aliases = cfg[:aliases]
|
33
|
+
self.exec_proc = cfg[:exec_proc]
|
34
|
+
self.completion_proc = cfg[:completion_proc]
|
35
|
+
self.help = cfg[:help]
|
36
36
|
end
|
37
37
|
|
38
|
+
# complement :: String -> [String]
|
38
39
|
def complement(input)
|
39
40
|
if match?(input) && input =~ /^[^\s]+\s/
|
40
41
|
if completion_proc
|
@@ -48,6 +49,7 @@ module Termtter
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
52
|
+
# call :: ???
|
51
53
|
def call(cmd = nil, arg = nil, original_text = nil)
|
52
54
|
arg = case arg
|
53
55
|
when nil
|
@@ -60,19 +62,32 @@ module Termtter
|
|
60
62
|
exec_proc.call(arg)
|
61
63
|
end
|
62
64
|
|
65
|
+
# match? :: String -> Boolean
|
63
66
|
def match?(input)
|
64
|
-
(pattern
|
67
|
+
!(pattern !~input)
|
65
68
|
end
|
66
69
|
|
70
|
+
# pattern :: Regexp
|
67
71
|
def pattern
|
68
72
|
commands_regex = commands.map {|name| Regexp.quote(name.to_s) }.join('|')
|
69
73
|
/^((#{commands_regex})|(#{commands_regex})\s+(.*?))\s*$/
|
70
74
|
end
|
71
75
|
|
76
|
+
# commands :: [Symbol]
|
72
77
|
def commands
|
73
78
|
[name] + aliases
|
74
79
|
end
|
75
80
|
|
81
|
+
def aliases=(as)
|
82
|
+
@aliases = as.map { |a| a.to_sym }
|
83
|
+
end
|
84
|
+
|
85
|
+
# alias= :: Symbol -> ()
|
86
|
+
def alias=(a)
|
87
|
+
self.aliases = [a]
|
88
|
+
end
|
89
|
+
|
90
|
+
# split_command_line :: String -> (String, String)
|
76
91
|
def self.split_command_line(line)
|
77
92
|
line.strip.split(/\s+/, 2)
|
78
93
|
end
|
data/lib/termtter/config.rb
CHANGED
@@ -9,10 +9,7 @@ config.password = '<%= password %>'
|
|
9
9
|
#config.proxy.password = 'proxy password'
|
10
10
|
|
11
11
|
Termtter::Client.init do |t|
|
12
|
-
<%- standard_plugins.each do |plugin| -%>
|
13
|
-
t.plug '<%= plugin %>'
|
14
|
-
<%- end -%>
|
15
12
|
<%- (plugins - standard_plugins).each do |plugin| -%>
|
16
|
-
|
13
|
+
# t.plug '<%= plugin %>'
|
17
14
|
<%- end -%>
|
18
15
|
end
|
data/lib/termtter/version.rb
CHANGED
@@ -21,6 +21,47 @@ module Termtter
|
|
21
21
|
Client.get_command(:test).name.should == :test
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'should take register_command as block' do
|
25
|
+
process = lambda {}
|
26
|
+
Client.register_command('test', &process)
|
27
|
+
command = Client.get_command(:test)
|
28
|
+
command.name.should == :test
|
29
|
+
command.exec_proc.should == process
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should take register_command as block with options' do
|
33
|
+
process = lambda {}
|
34
|
+
Client.register_command('test', :help => 'help', &process)
|
35
|
+
command = Client.get_command(:test)
|
36
|
+
command.name.should == :test
|
37
|
+
command.exec_proc.should == process
|
38
|
+
command.help.should == 'help'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should take add_command as block' do
|
42
|
+
Client.add_command('test') do |c|
|
43
|
+
c.aliases = ['t']
|
44
|
+
c.help = 'test command is a test'
|
45
|
+
end
|
46
|
+
command = Client.get_command(:test)
|
47
|
+
command.name.should == :test
|
48
|
+
command.aliases.should == [:t]
|
49
|
+
command.help.should == 'test command is a test'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should take add_command as block without past config' do
|
53
|
+
Client.add_command('past') do |c|
|
54
|
+
c.help = 'past help'
|
55
|
+
end
|
56
|
+
Client.get_command(:past).help.should == 'past help'
|
57
|
+
Client.add_command('new') {}
|
58
|
+
Client.get_command(:new).help.should_not == 'past help'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'raises ArgumentError when call add_command without block' do
|
62
|
+
lambda { Client.add_command('past') }.should raise_error(ArgumentError)
|
63
|
+
end
|
64
|
+
|
24
65
|
it 'should call command' do
|
25
66
|
command_arg = nil
|
26
67
|
command = Command.new(:name => :test, :exec_proc => lambda {|arg| command_arg = arg})
|
@@ -3,52 +3,73 @@
|
|
3
3
|
require File.dirname(__FILE__) + '/../spec_helper'
|
4
4
|
|
5
5
|
module Termtter
|
6
|
+
describe 'Command#initialize' do
|
7
|
+
it 'requires the name element in the argument hash' do
|
8
|
+
lambda { Command.new(:nama => 1) }.should raise_error(ArgumentError)
|
9
|
+
lambda { Command.new(:name => 1) }.should_not raise_error(ArgumentError)
|
10
|
+
end
|
6
11
|
|
7
|
-
|
12
|
+
it 'does not destroy the argument hash' do
|
13
|
+
hash = {
|
14
|
+
:name => 1,
|
15
|
+
:exec => 3
|
16
|
+
}
|
17
|
+
Command.new hash
|
18
|
+
|
19
|
+
hash.should eql(hash)
|
20
|
+
hash[:name].should == 1
|
21
|
+
hash[:exec].should == 3
|
22
|
+
hash[:exec_proc].should be_nil
|
23
|
+
end
|
24
|
+
end
|
8
25
|
|
26
|
+
describe Command do
|
9
27
|
before do
|
10
28
|
params = {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
29
|
+
:name => 'update',
|
30
|
+
:aliases => ['u', 'up'],
|
31
|
+
:exec_proc => lambda {|arg| arg },
|
32
|
+
:completion_proc => lambda {|command, arg| %w[complete1 complete2] },
|
33
|
+
:help => ['update,u TEXT', 'test command']
|
16
34
|
}
|
17
35
|
@command = Command.new(params)
|
18
36
|
end
|
19
37
|
|
20
|
-
|
21
|
-
|
38
|
+
describe '#pattern' do
|
39
|
+
it 'returns command regex' do
|
40
|
+
@command.pattern.
|
41
|
+
should == /^((update|u|up)|(update|u|up)\s+(.*?))\s*$/
|
42
|
+
end
|
22
43
|
end
|
23
44
|
|
24
|
-
it '
|
45
|
+
it 'is given name as String or Symbol' do
|
25
46
|
Command.new(:name => 'foo').name.should == :foo
|
26
47
|
Command.new(:name => :foo).name.should == :foo
|
27
48
|
end
|
28
49
|
|
29
|
-
it '
|
50
|
+
it 'returns name' do
|
30
51
|
@command.name.should == :update
|
31
52
|
end
|
32
53
|
|
33
|
-
it '
|
54
|
+
it 'returns aliases' do
|
34
55
|
@command.aliases.should == [:u, :up]
|
35
56
|
end
|
36
57
|
|
37
|
-
it '
|
58
|
+
it 'returns commands' do
|
38
59
|
@command.commands.should == [:update, :u, :up]
|
39
60
|
end
|
40
61
|
|
41
|
-
it '
|
62
|
+
it 'returns help' do
|
42
63
|
@command.help.should == ['update,u TEXT', 'test command']
|
43
64
|
end
|
44
65
|
|
45
|
-
it '
|
66
|
+
it 'returns candidates for completion' do
|
46
67
|
# complement
|
47
68
|
[
|
48
69
|
['upd', ['update']],
|
49
70
|
[' upd', []],
|
50
71
|
[' upd ', []],
|
51
|
-
['update a',
|
72
|
+
['update a', ['complete1', 'complete2']],
|
52
73
|
[' update ', []],
|
53
74
|
['u foo', ['complete1', 'complete2']],
|
54
75
|
].each do |input, comp|
|
@@ -56,7 +77,7 @@ module Termtter
|
|
56
77
|
end
|
57
78
|
end
|
58
79
|
|
59
|
-
it '
|
80
|
+
it 'returns command_info when call method "match?"' do
|
60
81
|
[
|
61
82
|
['update', true],
|
62
83
|
['up', true],
|
@@ -75,33 +96,45 @@ module Termtter
|
|
75
96
|
end
|
76
97
|
end
|
77
98
|
|
78
|
-
it '
|
79
|
-
lambda { Command.new }.should raise_error(ArgumentError)
|
80
|
-
lambda { Command.new(:exec_proc => lambda {|args|}) }.should raise_error(ArgumentError)
|
81
|
-
lambda { Command.new(:aliases => ['u']) }.should raise_error(ArgumentError)
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should call exec_proc when call method "call"' do
|
99
|
+
it 'calls exec_proc when call method "call"' do
|
85
100
|
@command.call('foo', 'test', 'foo test').should == 'test'
|
86
101
|
@command.call('foo', ' test', 'foo test').should == ' test'
|
87
102
|
@command.call('foo', ' test ', 'foo test ').should == ' test '
|
88
103
|
@command.call('foo', 'test test', 'foo test test').should == 'test test'
|
89
104
|
end
|
90
105
|
|
91
|
-
it '
|
92
|
-
lambda { @command.call('foo', nil, 'foo') }.
|
93
|
-
|
94
|
-
lambda { @command.call('foo',
|
95
|
-
|
106
|
+
it 'raises ArgumentError at call' do
|
107
|
+
lambda { @command.call('foo', nil, 'foo') }.
|
108
|
+
should_not raise_error(ArgumentError)
|
109
|
+
lambda { @command.call('foo', 'foo', 'foo') }.
|
110
|
+
should_not raise_error(ArgumentError)
|
111
|
+
lambda { @command.call('foo', false, 'foo') }.
|
112
|
+
should raise_error(ArgumentError)
|
113
|
+
lambda { @command.call('foo', Array.new, 'foo') }.
|
114
|
+
should raise_error(ArgumentError)
|
96
115
|
end
|
97
116
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
117
|
+
describe '#alias=' do
|
118
|
+
it 'wraps aliases=' do
|
119
|
+
a = :ujihisa
|
120
|
+
@command.should_receive(:aliases=).with([a])
|
121
|
+
@command.alias = a
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '.split_command_line' do
|
126
|
+
it 'splits from a command line string to the command name and the arg' do
|
127
|
+
Command.split_command_line('test foo bar').
|
128
|
+
should == ['test', 'foo bar']
|
129
|
+
Command.split_command_line('test foo bar').
|
130
|
+
should == ['test', 'foo bar']
|
131
|
+
Command.split_command_line('test foo bar').
|
132
|
+
should == ['test', 'foo bar']
|
133
|
+
Command.split_command_line(' test foo bar').
|
134
|
+
should == ['test', 'foo bar']
|
135
|
+
Command.split_command_line(' test foo bar ').
|
136
|
+
should == ['test', 'foo bar']
|
137
|
+
end
|
104
138
|
end
|
105
139
|
end
|
106
140
|
end
|
107
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: termtter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-05-17 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/plugins/post_exec_hook_sample.rb
|
115
115
|
- lib/plugins/pre_exec_hook_sample.rb
|
116
116
|
- lib/plugins/primes.rb
|
117
|
+
- lib/plugins/protected_filter.rb
|
117
118
|
- lib/plugins/quicklook.rb
|
118
119
|
- lib/plugins/random.rb
|
119
120
|
- lib/plugins/reblog.rb
|