epitools 0.5.51 → 0.5.54
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/epitools/core_ext/hash.rb +25 -4
- data/lib/epitools/path.rb +5 -0
- data/lib/epitools/term.rb +19 -2
- data/lib/epitools/wm.rb +35 -70
- data/spec/wm_spec.rb +3 -3
- metadata +3 -3
- data/spec/spec_helper.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcddb5cf0745cf3cbedb55debe44c07d22447cdb
|
4
|
+
data.tar.gz: 8bdb45f8597932ab24e74624932257d6674c9199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbee97e02411f51380fbc21ba849d257a0bbb44eb932b72e22ac9d9610db4d9183ca4a3179919d85b5e61375900cf736d81549390278d0d4d2c3ce4ccad12fe3
|
7
|
+
data.tar.gz: ed5a46223323cadb816d17ef137a176a0429c4637d225efcca647adecd5f3357e7e000c44f9aa1cfaf9dbdc253d4e6aa21d33eab9d4c4d89e61206c9dc162b09
|
data/README.rdoc
CHANGED
@@ -12,7 +12,7 @@ Enhanced base classes: {Enumerable}[http://rdoc.info/github/epitron/epitools/mas
|
|
12
12
|
|
13
13
|
Extras:
|
14
14
|
|
15
|
-
* {Path}[http://rdoc.info/github/epitron/epitools/master/Path] (
|
15
|
+
* {Path}[http://rdoc.info/github/epitron/epitools/master/Path] (an object-oriented interface to the filessytem -- like File, Dir, Pathname, and FileUtils all rolled into one)
|
16
16
|
* {TypedStruct}[http://rdoc.info/github/epitron/epitools/master/TypedStruct] (like Struct, but setters always coerce input to a certain type, eg: boolean, integer, etc.)
|
17
17
|
* {WM}[http://rdoc.info/github/epitron/epitools/master/WM] (control/query desktop windows in X. Note: `wmctrl` must be installed)
|
18
18
|
* {Sys}[http://rdoc.info/github/epitron/epitools/master/Sys] (system tools -- determine operating system, list processes, view network statistics, etc.)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.54
|
@@ -109,6 +109,23 @@ class Hash
|
|
109
109
|
new(0)
|
110
110
|
end
|
111
111
|
|
112
|
+
#
|
113
|
+
# Returns a new Hash which automatically assigns each unique key to an increasing counter.
|
114
|
+
#
|
115
|
+
# eg:
|
116
|
+
# > h = Hash.of_unique_ids
|
117
|
+
# => {}
|
118
|
+
# > h["Person"] #=> 0
|
119
|
+
# > h["Another Person"] #=> 1
|
120
|
+
# > h["Yet Another Person"] #=> 2
|
121
|
+
# > h["Person"] #=> 0
|
122
|
+
# > h
|
123
|
+
# => {"Person"=>0, "Another Person"=>1, "Yet Another Person"=>2}
|
124
|
+
#
|
125
|
+
def self.of_unique_ids
|
126
|
+
new { |h,k| h[k] = h.size }
|
127
|
+
end
|
128
|
+
|
112
129
|
#
|
113
130
|
# Hash keys become methods, kinda like OpenStruct. These methods have the lowest priority,
|
114
131
|
# so be careful. They will be overridden by any methods on Hash.
|
@@ -155,7 +172,7 @@ class Hash
|
|
155
172
|
result = []
|
156
173
|
dent = indent * level
|
157
174
|
each do |key, val|
|
158
|
-
result << dent+key
|
175
|
+
result << dent+key.to_s
|
159
176
|
result += val.tree(level+1) if val.any?
|
160
177
|
end
|
161
178
|
result
|
@@ -164,9 +181,13 @@ class Hash
|
|
164
181
|
#
|
165
182
|
# Print the result of `tree`
|
166
183
|
#
|
167
|
-
def print_tree
|
168
|
-
|
169
|
-
|
184
|
+
def print_tree(level=0, indent=" ", &block)
|
185
|
+
dent = indent * level
|
186
|
+
|
187
|
+
each do |key, val|
|
188
|
+
puts block_given? ? yield(key, level) : "#{dent}#{key}"
|
189
|
+
val.print_tree(level+1, indent, &block) if val.any?
|
190
|
+
end
|
170
191
|
end
|
171
192
|
|
172
193
|
#
|
data/lib/epitools/path.rb
CHANGED
data/lib/epitools/term.rb
CHANGED
@@ -87,6 +87,12 @@ module Term
|
|
87
87
|
@columns = options[:columns]
|
88
88
|
@padding = options[:padding] || 1
|
89
89
|
|
90
|
+
if (options.keys & [:horiz, :horizontal, :horizontally]).any?
|
91
|
+
@direction = :horizontal
|
92
|
+
else
|
93
|
+
@direction = :vertical
|
94
|
+
end
|
95
|
+
|
90
96
|
# Update the terminal size
|
91
97
|
@width, @height = Term.size
|
92
98
|
end
|
@@ -129,15 +135,26 @@ module Term
|
|
129
135
|
elems
|
130
136
|
end
|
131
137
|
|
132
|
-
def
|
138
|
+
def in_columns
|
133
139
|
return '' if @data.empty?
|
134
140
|
render sliced_into(num_rows).transpose
|
135
141
|
end
|
142
|
+
alias_method :by_columns, :in_columns
|
136
143
|
|
137
|
-
def
|
144
|
+
def in_rows
|
138
145
|
return '' if @data.empty?
|
139
146
|
render sliced_into(num_columns)
|
140
147
|
end
|
148
|
+
alias_method :by_rows, :in_rows
|
149
|
+
|
150
|
+
def display #(opts={})
|
151
|
+
case @direction
|
152
|
+
when :horizontal
|
153
|
+
puts in_rows
|
154
|
+
when :vertical
|
155
|
+
puts in_columns
|
156
|
+
end
|
157
|
+
end
|
141
158
|
|
142
159
|
def to_s
|
143
160
|
by_rows
|
data/lib/epitools/wm.rb
CHANGED
@@ -102,17 +102,8 @@ module WM
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def activate!
|
105
|
-
system "wmctrl", "-i", "-a", window_id
|
106
|
-
|
107
|
-
|
108
|
-
#
|
109
|
-
# string is made up of regular text, plus <>'d keypresses
|
110
|
-
# eg: "Hello<Ctrl-T><Ctrl-L><Ctrl-Shift-K><Return>!!!"
|
111
|
-
#
|
112
|
-
# TODO: add `xdotool` support
|
113
|
-
#
|
114
|
-
def send_keys(keys)
|
115
|
-
xse(keys)
|
105
|
+
#system "wmctrl", "-i", "-a", window_id
|
106
|
+
system "xdotool", "windowactivate", window_id
|
116
107
|
end
|
117
108
|
|
118
109
|
#
|
@@ -318,9 +309,9 @@ module WM
|
|
318
309
|
# thorn 0x00fe /* U+00FE LATIN SMALL LETTER THORN */
|
319
310
|
# ydiaeresis 0x00ff /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
|
320
311
|
#
|
321
|
-
def keys_to_events(keys)
|
322
312
|
|
323
|
-
|
313
|
+
if Path.which("xdotool")
|
314
|
+
KEYMAP = {
|
324
315
|
"`" => "grave",
|
325
316
|
" " => "space",
|
326
317
|
"~" => "asciitilde",
|
@@ -329,71 +320,45 @@ module WM
|
|
329
320
|
'"' => "quotedbl",
|
330
321
|
}
|
331
322
|
|
332
|
-
|
323
|
+
def string_to_keys(s)
|
333
324
|
|
334
|
-
|
335
|
-
mods = []
|
325
|
+
tokens = s.scan(/(<[^>]+>|.)/).flatten
|
336
326
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
if special =~ /^(Ctrl|Shift|Alt)$/i
|
346
|
-
mods << $1
|
347
|
-
else
|
348
|
-
raise "Error: unknown modifier #{special}"
|
349
|
-
end
|
327
|
+
tokens.map do |token|
|
328
|
+
if token =~ /^<(.+)>$/
|
329
|
+
mods = $1.split(/[-+]/)
|
330
|
+
key = mods.pop
|
331
|
+
# mods.each { |mod| raise "Error: unknown modifier #{mod}" unless mod =~ /^(Ctrl|Shift|Alt)$/i }
|
332
|
+
else
|
333
|
+
mods = []
|
334
|
+
key = token
|
350
335
|
end
|
351
336
|
|
352
|
-
|
353
|
-
|
354
|
-
|
337
|
+
if key =~ /^[A-Z0-9]$/i or key.size > 1
|
338
|
+
# key is good!
|
339
|
+
else
|
340
|
+
key = KEYMAP[key] || ("0x%x" % key.ord)
|
341
|
+
end
|
355
342
|
|
356
|
-
|
357
|
-
keyname = key
|
358
|
-
else
|
359
|
-
keyname = keymap[key] || ("0x%x" % key.ord)
|
343
|
+
[*mods, key].join("+")
|
360
344
|
end
|
361
|
-
|
362
|
-
"#{mods.join(" ")}<Key>#{keyname}"
|
363
345
|
end
|
364
|
-
end
|
365
|
-
|
366
|
-
def xdotool_keys(keys)
|
367
|
-
# --window windowid
|
368
|
-
# Send keystrokes to a specific window id. See "SENDEVENT NOTES" below. The default, if no
|
369
|
-
# window is given, depends on the window stack. If the window stack is empty the current
|
370
|
-
# window is typed at using XTEST. Otherwise, the default is "%1" (see "WINDOW STACK").
|
371
|
-
|
372
|
-
# --delay milliseconds
|
373
|
-
# Delay between keystrokes. Default is 12ms.
|
374
|
-
|
375
|
-
# --clearmodifiers
|
376
|
-
# Clear modifiers before sending keystrokes. See CLEARMODIFIERS below.
|
377
|
-
# xdotool key k1 k2 k3
|
378
|
-
# xdotool type string
|
379
|
-
end
|
380
|
-
|
381
|
-
def xse(keys)
|
382
|
-
temp = Tempfile.new("xse")
|
383
|
-
events = keys_to_events(keys)
|
384
|
-
|
385
|
-
# p events
|
386
|
-
eventstring = events.map { |e| e + "\n" }.join("")
|
387
|
-
|
388
|
-
temp.write eventstring
|
389
|
-
temp.flush
|
390
|
-
temp.seek 0
|
391
|
-
# p [:temp, temp.read]
|
392
346
|
|
393
|
-
|
394
|
-
#
|
395
|
-
|
396
|
-
|
347
|
+
#
|
348
|
+
# Send keypresses to this window, using xdotool.
|
349
|
+
# (`delay` specifies how long to pause between each keystroke, default: 12ms)
|
350
|
+
#
|
351
|
+
# Examples:
|
352
|
+
# > window.send_keys("Hello Everybo<Ctrl-W>World!<Return>!!!")
|
353
|
+
# > browser.send_keys("<Ctrl-T>http://google.com/<Return>")
|
354
|
+
#
|
355
|
+
def send_keys(keystring, delay=nil)
|
356
|
+
keys = string_to_keys(keystring)
|
357
|
+
cmd = ["xdotool", "key", "--clearmodifiers", "--window", window_id]
|
358
|
+
cmd += ["--delay", delay.to_s] if delay
|
359
|
+
cmd += keys
|
360
|
+
|
361
|
+
system(*cmd)
|
397
362
|
end
|
398
363
|
end
|
399
364
|
|
data/spec/wm_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe WM do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_events(keys)
|
15
|
-
|
15
|
+
WM::Window.new.keys_to_events(keys)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "parses X keys-string" do
|
@@ -24,8 +24,8 @@ describe WM do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "sends keys to this window" do
|
27
|
-
|
28
|
-
|
27
|
+
sublime_window = WM.current_desktop.windows.select{|w| w.title =~ /wm_spec\.rb.+Sublime/ }.first
|
28
|
+
sublime_window.send_keys('<Ctrl-`>print("Hello from send_keys()!")<Return>')
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.54
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -99,7 +99,6 @@ files:
|
|
99
99
|
- spec/permutations_spec.rb
|
100
100
|
- spec/rash_spec.rb
|
101
101
|
- spec/ratio_spec.rb
|
102
|
-
- spec/spec_helper.rb
|
103
102
|
- spec/sys_spec.rb
|
104
103
|
- spec/term_spec.rb
|
105
104
|
- spec/typed_struct_spec.rb
|
@@ -130,3 +129,4 @@ signing_key:
|
|
130
129
|
specification_version: 3
|
131
130
|
summary: Not utils... METILS!
|
132
131
|
test_files: []
|
132
|
+
has_rdoc:
|
data/spec/spec_helper.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'spork'
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 'epitools'))
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
-
p $:
|
8
|
-
|
9
|
-
|
10
|
-
Spork.prefork do
|
11
|
-
# Loading more in this block will cause your tests to run faster. However,
|
12
|
-
# if you change any configuration or code from libraries loaded here, you'll
|
13
|
-
# need to restart spork for it take effect.
|
14
|
-
|
15
|
-
require 'rspec'
|
16
|
-
require 'epitools'
|
17
|
-
|
18
|
-
Rspec.configure do |c|
|
19
|
-
c.mock_with :rspec
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
Spork.each_run do
|
24
|
-
# This code will be run each time you run your specs.
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
# --- Instructions ---
|
29
|
-
# - Sort through your spec_helper file. Place as much environment loading
|
30
|
-
# code that you don't normally modify during development in the
|
31
|
-
# Spork.prefork block.
|
32
|
-
# - Place the rest under Spork.each_run block
|
33
|
-
# - Any code that is left outside of the blocks will be ran during preforking
|
34
|
-
# and during each_run!
|
35
|
-
# - These instructions should self-destruct in 10 seconds. If they don't,
|
36
|
-
# feel free to delete them.
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|