jaguar 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +16 -2
- data/e2e/main.rb +14 -0
- data/exe/jaguar +20 -0
- data/jaguar.gemspec +4 -1
- data/lib/jaguar.rb +41 -2
- data/lib/jaguar/cli.rb +25 -0
- data/lib/jaguar/dsl.rb +9 -0
- data/lib/jaguar/dsl/keyboard.rb +15 -0
- data/lib/jaguar/dsl/keyboard/type.rb +118 -0
- data/lib/jaguar/dsl/mouse.rb +24 -0
- data/lib/jaguar/helpers.rb +15 -0
- data/lib/jaguar/version.rb +1 -1
- metadata +45 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1a3277e51f9c13b9ea0a9c211538fe0421ea29a43c274fd190251e322647793
|
4
|
+
data.tar.gz: 87f4b67695bfd3b4b59b68b7d9ad29416d2b0e7ec0393f535a25bd126bdbada6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db2b7295bada2ed2e1725c59d7f041e876fd04b96675a847e0ce0163f15e01765be4bdfa1b239f5d8eeca6e86da253e47de1685a1326a9fba160106b40850537
|
7
|
+
data.tar.gz: 840e816d31d623dbf19e13daab534f119a4b65fb38e9461d14fbee8992a6c4897a5a388b17ecda33eaf3177a47b4d86ed50b901b83df1a5b1b3bf8e8ba9f5507
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jaguar
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.3
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,25 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../delirium
|
3
|
+
specs:
|
4
|
+
delirium (0.2.0)
|
5
|
+
|
1
6
|
PATH
|
2
7
|
remote: .
|
3
8
|
specs:
|
4
|
-
jaguar (0.1.
|
9
|
+
jaguar (0.1.1)
|
10
|
+
contracts
|
11
|
+
pry
|
5
12
|
|
6
13
|
GEM
|
7
14
|
remote: https://rubygems.org/
|
8
15
|
specs:
|
16
|
+
coderay (1.1.2)
|
17
|
+
contracts (0.16.0)
|
9
18
|
diff-lcs (1.3)
|
19
|
+
method_source (0.9.2)
|
20
|
+
pry (0.12.2)
|
21
|
+
coderay (~> 1.1.0)
|
22
|
+
method_source (~> 0.9.0)
|
10
23
|
rake (10.5.0)
|
11
24
|
rspec (3.8.0)
|
12
25
|
rspec-core (~> 3.8.0)
|
@@ -26,7 +39,8 @@ PLATFORMS
|
|
26
39
|
ruby
|
27
40
|
|
28
41
|
DEPENDENCIES
|
29
|
-
bundler (~> 1.
|
42
|
+
bundler (~> 1.16)
|
43
|
+
delirium!
|
30
44
|
jaguar!
|
31
45
|
rake (~> 10.0)
|
32
46
|
rspec (~> 3.0)
|
data/e2e/main.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "jaguar/dsl"
|
2
|
+
include Jaguar::DSL
|
3
|
+
|
4
|
+
did_receive_ctrl_c = false
|
5
|
+
|
6
|
+
Signal.trap("INT") {
|
7
|
+
puts "
|
8
|
+
ctrl+c received!"
|
9
|
+
did_receive_ctrl_c = true
|
10
|
+
}
|
11
|
+
|
12
|
+
Mouse.move(10,10)
|
13
|
+
Keyboard.type "hello", :enter, [:ctrl, "c"]
|
14
|
+
Keyboard.type [:cmd, [:tab]], [:cmd, [:tab]]
|
data/exe/jaguar
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# add lib to libpath (only needed when running from the sources)
|
5
|
+
require 'pathname'
|
6
|
+
lib_path = File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
|
7
|
+
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
8
|
+
|
9
|
+
STDOUT.sync = true
|
10
|
+
|
11
|
+
require 'jaguar'
|
12
|
+
require 'jaguar/cli'
|
13
|
+
|
14
|
+
eval_string = if ARGV.any?
|
15
|
+
ARGV.join " "
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
Jaguar::CLI::RootCommand.run eval_string: eval_string
|
data/jaguar.gemspec
CHANGED
@@ -21,7 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.
|
24
|
+
spec.add_dependency "pry"
|
25
|
+
spec.add_dependency "contracts"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
30
|
end
|
data/lib/jaguar.rb
CHANGED
@@ -1,6 +1,45 @@
|
|
1
|
-
require "
|
1
|
+
require "delirium"
|
2
|
+
require "contracts"
|
2
3
|
|
3
4
|
module Jaguar
|
5
|
+
include Contracts::Core
|
6
|
+
include Contracts::Builtin
|
7
|
+
C = Contracts
|
8
|
+
|
4
9
|
class Error < StandardError; end
|
5
|
-
|
10
|
+
|
11
|
+
@@driver = Delirium::Platform.class_for_current_platform.new
|
12
|
+
|
13
|
+
Contract nil => Delirium::Platform::Base
|
14
|
+
def self.driver
|
15
|
+
@@driver
|
16
|
+
end
|
17
|
+
|
18
|
+
Contract Delirium::Platform::Base => nil
|
19
|
+
def self.driver=(d)
|
20
|
+
@@driver = d
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
Contract Jaguar::C::Args[Any] => nil
|
25
|
+
def self.debug(*args)
|
26
|
+
return unless ENV["JAGUAR_DEBUG"] == "yes"
|
27
|
+
|
28
|
+
print "JAGUAR DEBUG: "
|
29
|
+
for arg in args
|
30
|
+
arg_formatted = case arg
|
31
|
+
when String
|
32
|
+
arg
|
33
|
+
else
|
34
|
+
arg.inspect
|
35
|
+
end
|
36
|
+
print arg_formatted
|
37
|
+
print " "
|
38
|
+
end
|
39
|
+
puts ""
|
40
|
+
nil
|
41
|
+
end
|
6
42
|
end
|
43
|
+
|
44
|
+
require_relative "jaguar/version"
|
45
|
+
require_relative "jaguar/helpers"
|
data/lib/jaguar/cli.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "../jaguar" # if required only "jaguar/cli"
|
2
|
+
require_relative "dsl"
|
3
|
+
require "pry"
|
4
|
+
|
5
|
+
module Jaguar
|
6
|
+
module CLI
|
7
|
+
class RootCommand
|
8
|
+
include Contracts::Core
|
9
|
+
|
10
|
+
Contract ({ eval_string: Jaguar::C::Maybe[String] }) => nil
|
11
|
+
def self.run(eval_string:nil)
|
12
|
+
TOPLEVEL_BINDING.eval """
|
13
|
+
include Jaguar::DSL
|
14
|
+
"""
|
15
|
+
if eval_string
|
16
|
+
TOPLEVEL_BINDING.eval eval_string
|
17
|
+
else
|
18
|
+
TOPLEVEL_BINDING.eval "Pry.start"
|
19
|
+
end
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/jaguar/dsl.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Jaguar
|
2
|
+
module DSL
|
3
|
+
module Keyboard
|
4
|
+
include Contracts::Core
|
5
|
+
|
6
|
+
Contract Jaguar::C::Args[Jaguar::C::Or[String,Array,Symbol,Hash]] => self.class
|
7
|
+
def self.type(*string_or_arrays_or_symbol_or_hashes)
|
8
|
+
Type.type *string_or_arrays_or_symbol_or_hashes
|
9
|
+
self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require_relative "keyboard/type"
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module Jaguar
|
2
|
+
module DSL
|
3
|
+
module Keyboard
|
4
|
+
module Type
|
5
|
+
include Contracts::Core
|
6
|
+
|
7
|
+
Contract Jaguar::C::Args[Jaguar::C::Or[String,Array,Symbol,Hash]] => self.class
|
8
|
+
def self.type(*string_or_arrays_or_symbol_or_hashes)
|
9
|
+
opts, type_sequence = parse_type_args_to_opts_and_type_sequence string_or_arrays_or_symbol_or_hashes
|
10
|
+
|
11
|
+
sequence = unpack_type_sequence type_sequence
|
12
|
+
delay = opts[:delay]
|
13
|
+
|
14
|
+
Jaguar.debug "sequence", sequence, "delay", delay
|
15
|
+
|
16
|
+
sequence.each do |s|
|
17
|
+
already_delayed = false
|
18
|
+
|
19
|
+
case s
|
20
|
+
when String
|
21
|
+
Jaguar.debug "direct_write_instead_of_key_presses?(delay)", direct_write_instead_of_key_presses?(delay)
|
22
|
+
|
23
|
+
if direct_write_instead_of_key_presses?(delay)
|
24
|
+
Jaguar.driver.do device: :keyboard, action: :write, params: {string: s}
|
25
|
+
else
|
26
|
+
s.split('').each do |k|
|
27
|
+
Jaguar.driver.do device: :keyboard, action: :write, params: {string: s}
|
28
|
+
Jaguar::Helpers.delay delay if delay
|
29
|
+
already_delayed = true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
when Array
|
33
|
+
non_mods = s.pop
|
34
|
+
Jaguar.debug "non_mods", non_mods
|
35
|
+
for mod in s do
|
36
|
+
Jaguar.driver.do device: :keyboard, action: :key_down, params: {key: mod}
|
37
|
+
end
|
38
|
+
|
39
|
+
case non_mods
|
40
|
+
when String,Symbol
|
41
|
+
# [:alt, "d"]
|
42
|
+
# [:cmd, :tab]
|
43
|
+
Jaguar.driver.do device: :keyboard, action: :key_press, params: {key: non_mods}
|
44
|
+
when Array
|
45
|
+
# [:alt, [:tab, :tab]]
|
46
|
+
non_mods.each do |non_mod|
|
47
|
+
Jaguar.driver.do device: :keyboard, action: :key_press, params: {key: non_mod}
|
48
|
+
Jaguar::Helpers.delay delay if delay
|
49
|
+
already_delayed = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
for mod in s do
|
54
|
+
Jaguar.driver.do device: :keyboard, action: :key_up, params: {key: mod}
|
55
|
+
end
|
56
|
+
when Symbol
|
57
|
+
Jaguar.driver.do device: :keyboard, action: :key_press, params: {key: s}
|
58
|
+
end
|
59
|
+
|
60
|
+
unless already_delayed
|
61
|
+
Jaguar::Helpers.delay delay if delay
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
Contract Jaguar::C::Args[Jaguar::C::Or[String,Array,Symbol,Hash]] => Array[Hash,Array]
|
71
|
+
def self.parse_type_args_to_opts_and_type_sequence(args)
|
72
|
+
opts = {}
|
73
|
+
type_sequence = []
|
74
|
+
args.each do |string_or_array_or_symbol_or_hash|
|
75
|
+
case string_or_array_or_symbol_or_hash.class.name
|
76
|
+
when "String", "Array", "Symbol"
|
77
|
+
type_sequence << string_or_array_or_symbol_or_hash
|
78
|
+
when "Hash"
|
79
|
+
opts.merge!(string_or_array_or_symbol_or_hash)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
[opts, type_sequence]
|
83
|
+
end
|
84
|
+
|
85
|
+
Contract Jaguar::C::Or[Integer,Float,Range,NilClass] => Jaguar::C::Bool
|
86
|
+
def self.direct_write_instead_of_key_presses?(delay)
|
87
|
+
case delay
|
88
|
+
when Integer
|
89
|
+
delay == 0
|
90
|
+
when Float
|
91
|
+
delay == 0.0
|
92
|
+
when Range
|
93
|
+
delay.first == 0 && delay.last == 0
|
94
|
+
when NilClass
|
95
|
+
true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
Contract Jaguar::C::Or[String,Array,Symbol] => Array
|
100
|
+
def self.unpack_type_sequence(type_sequence)
|
101
|
+
case type_sequence
|
102
|
+
when String
|
103
|
+
# type "hello"
|
104
|
+
type_sequence.split ''
|
105
|
+
when Array
|
106
|
+
# type "hello", :enter
|
107
|
+
# type [:ctrl, :c]
|
108
|
+
# type [:alt, [:tab, :tab]]
|
109
|
+
type_sequence
|
110
|
+
when Symbol
|
111
|
+
# type :enter
|
112
|
+
[type_sequence]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Jaguar
|
2
|
+
module DSL
|
3
|
+
module Mouse
|
4
|
+
include Contracts::Core
|
5
|
+
|
6
|
+
Contract Jaguar::C::KeywordArgs[
|
7
|
+
x: Integer, y: Integer
|
8
|
+
] => self.class
|
9
|
+
def self.move(x:nil, y:nil)
|
10
|
+
Jaguar.driver.do({
|
11
|
+
device: :mouse,
|
12
|
+
action: :move,
|
13
|
+
params: { x: x, y: y }
|
14
|
+
})
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
Contract Integer, Integer => self.class
|
19
|
+
def self.move(x,y)
|
20
|
+
move x:x, y:y
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Jaguar
|
2
|
+
module Helpers
|
3
|
+
include Contracts::Core
|
4
|
+
Contract Jaguar::C::Or[Range,Integer,Float] => self.class
|
5
|
+
def self.delay(d=0.0..0.0)
|
6
|
+
case d
|
7
|
+
when Range
|
8
|
+
sleep rand(d) # gotta love ruby
|
9
|
+
when Integer, Float
|
10
|
+
sleep d
|
11
|
+
end
|
12
|
+
self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/jaguar/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jaguar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Superbot HQ
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: contracts
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
45
|
- - "~>"
|
18
46
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
47
|
+
version: '1.16'
|
20
48
|
type: :development
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
52
|
- - "~>"
|
25
53
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
54
|
+
version: '1.16'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rake
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,12 +82,15 @@ dependencies:
|
|
54
82
|
version: '3.0'
|
55
83
|
description:
|
56
84
|
email:
|
57
|
-
executables:
|
85
|
+
executables:
|
86
|
+
- jaguar
|
58
87
|
extensions: []
|
59
88
|
extra_rdoc_files: []
|
60
89
|
files:
|
61
90
|
- ".gitignore"
|
62
91
|
- ".rspec"
|
92
|
+
- ".ruby-gemset"
|
93
|
+
- ".ruby-version"
|
63
94
|
- ".travis.yml"
|
64
95
|
- Gemfile
|
65
96
|
- Gemfile.lock
|
@@ -68,8 +99,16 @@ files:
|
|
68
99
|
- Rakefile
|
69
100
|
- bin/console
|
70
101
|
- bin/setup
|
102
|
+
- e2e/main.rb
|
103
|
+
- exe/jaguar
|
71
104
|
- jaguar.gemspec
|
72
105
|
- lib/jaguar.rb
|
106
|
+
- lib/jaguar/cli.rb
|
107
|
+
- lib/jaguar/dsl.rb
|
108
|
+
- lib/jaguar/dsl/keyboard.rb
|
109
|
+
- lib/jaguar/dsl/keyboard/type.rb
|
110
|
+
- lib/jaguar/dsl/mouse.rb
|
111
|
+
- lib/jaguar/helpers.rb
|
73
112
|
- lib/jaguar/version.rb
|
74
113
|
homepage: https://github.com/superbothq/jaguar
|
75
114
|
licenses:
|
@@ -91,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
130
|
version: '0'
|
92
131
|
requirements: []
|
93
132
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.7.
|
133
|
+
rubygems_version: 2.7.8
|
95
134
|
signing_key:
|
96
135
|
specification_version: 4
|
97
136
|
summary: jaguar eats capybaras
|