spielbash 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2dda7f053211da0e400d7d97ae8c5b525c86ac39
4
- data.tar.gz: 949124904f77ce130434565a98274a918c2af07f
3
+ metadata.gz: '09da61edc3e1a9325354e616ad9d9dd031828469'
4
+ data.tar.gz: 106b73657f6a99e63b584981f0bc9a77f73c5447
5
5
  SHA512:
6
- metadata.gz: e0f9f2d705c2f6fbe9bae098802ecf094104310b9d85a06d920f6c4ade2cda9450caa1429c3ef53f10631e7ab6bd0b88ff857965ae2e311b0bb76d855d29e172
7
- data.tar.gz: 994acbeabd2adbd3bfcd5d586ba45af64fe8f424966584bf1eff6a0a29aa7329b2128aedaa2a9e47a8fe1532df72184c2b9a8e64a81fa861971944f975da89c3
6
+ metadata.gz: 959d24a54faaebe57e0f9ddd75c81baf61e07eed707a075d48f6f3ca532e754fe73e7dbd195c067771c7afd9347b14e9aa9e3d7777f26680572374f125b873d5
7
+ data.tar.gz: f9baca5a0481b7f322aca9490497916d63aa929531ea5d87039804eea777b880c16a9a680f80d15a88d1fe69221bfb39a78d4e354395cb73c3f99a901aa5398f
@@ -12,8 +12,9 @@ module Spielbash
12
12
  wait = opts['wait']
13
13
  width = opts['width']
14
14
  height = opts['height']
15
+ wait_check_cmd = opts['wait_check_cmd']
15
16
 
16
- context = Spielbash::Context.new(typing_delay_s, reading_delay_s, wait, width, height)
17
+ context = Spielbash::Context.new(typing_delay_s, reading_delay_s, wait, width, height, wait_check_cmd)
17
18
 
18
19
  actions = create_actions(context, script['scenes'])
19
20
  pre_run_actions = create_actions(context, script['pre-run'])
@@ -24,6 +25,7 @@ module Spielbash
24
25
  end
25
26
 
26
27
  private
28
+
27
29
  def create_actions(context, scenes)
28
30
  actions = []
29
31
  for scene in scenes do
@@ -36,27 +38,34 @@ module Spielbash
36
38
  action_opts['height'])
37
39
 
38
40
  action = case
39
- when scene.has_key?('message') then
40
- value = scene['message']
41
- message_context = Spielbash::MessageContext.new(context,
42
- action_opts['typing_delay_s'],
43
- action_opts['reading_delay_s'],
44
- action_opts['wait'],
45
- action_opts['width'],
46
- action_opts['height'],
47
- action_opts['delete'].nil? ? true : action_opts['delete'])
48
- Spielbash::MessageAction.new(value, message_context)
49
- when scene.has_key?('command') then
50
- value = scene['command']
51
- Spielbash::CommandAction.new(value, action_context)
52
- when scene.has_key?('pause') then
53
- value = scene['pause']
54
- Spielbash::PauseAction.new(value, action_context)
55
- when scene.has_key?('key') then
56
- value = scene['key']
57
- Spielbash::PressKeyAction.new(value, action_context)
58
- else
59
- not_implemented
41
+ when scene.has_key?('message') then
42
+ value = scene['message']
43
+ message_context = Spielbash::MessageContext.new(context,
44
+ action_opts['typing_delay_s'],
45
+ action_opts['reading_delay_s'],
46
+ action_opts['wait'],
47
+ action_opts['width'],
48
+ action_opts['height'],
49
+ action_opts['delete'].nil? ? true : action_opts['delete'])
50
+ Spielbash::MessageAction.new(value, message_context)
51
+ when scene.has_key?('command') then
52
+ value = scene['command']
53
+ Spielbash::CommandAction.new(value, action_context)
54
+ when scene.has_key?('pause') then
55
+ value = scene['pause']
56
+ Spielbash::PauseAction.new(value, action_context)
57
+ when scene.has_key?('key') then
58
+ value = scene['key']
59
+ Spielbash::PressKeyAction.new(value, action_context)
60
+ when scene.has_key?('new_env') then
61
+ cmd = scene['new_env']
62
+ wait_cmd = scene['wait_check_cmd']
63
+ Spielbash::NewEnvironmentAction.new(cmd, wait_cmd, context)
64
+ when scene.has_key?('delete_env') then
65
+ cmd = scene['delete_env']
66
+ Spielbash::DeleteEnvironmentAction.new(cmd, context)
67
+ else
68
+ not_implemented
60
69
  end
61
70
 
62
71
  actions << action
@@ -0,0 +1,22 @@
1
+ module Spielbash
2
+ class DeleteEnvironmentAction < Spielbash::BaseAction
3
+ attr_accessor :command
4
+
5
+ def initialize(command, root_context)
6
+ super(root_context)
7
+ @command = command
8
+ end
9
+
10
+ def execute(session)
11
+ command.each_char do |c|
12
+ session.send_key(c)
13
+ sleep(action_context.typing_delay_s)
14
+ end
15
+ session.send_key('C-m')
16
+
17
+ sleep(action_context.reading_delay_s)
18
+
19
+ action_context.wait_check_cmd = nil
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ module Spielbash
2
+ class NewEnvironmentAction < Spielbash::BaseAction
3
+ attr_accessor :command, :wait_check_cmd
4
+
5
+ def initialize(command, wait_check_cmd, root_context)
6
+ super(root_context)
7
+ @command = command
8
+ @wait_check_cmd = wait_check_cmd
9
+ end
10
+
11
+ def execute(session)
12
+ command.each_char do |c|
13
+ session.send_key(c)
14
+ sleep(action_context.typing_delay_s)
15
+ end
16
+ session.send_key('C-m')
17
+
18
+ sleep(action_context.reading_delay_s)
19
+
20
+ action_context.wait_check_cmd = wait_check_cmd
21
+ end
22
+ end
23
+ end
@@ -1,13 +1,14 @@
1
1
  module Spielbash
2
2
  class Context
3
- attr_accessor :typing_delay_s, :reading_delay_s, :wait, :width, :height
3
+ attr_accessor :typing_delay_s, :reading_delay_s, :wait, :width, :height, :wait_check_cmd
4
4
 
5
- def initialize(typinig_delay_s, reading_delay_s, wait, width, height)
5
+ def initialize(typinig_delay_s, reading_delay_s, wait, width, height, wait_check_cmd = nil)
6
6
  @typing_delay_s = typinig_delay_s
7
7
  @reading_delay_s = reading_delay_s
8
8
  @wait = wait
9
9
  @width = width
10
10
  @height = height
11
+ @wait_check_cmd = wait_check_cmd
11
12
  end
12
13
  end
13
14
  end
@@ -39,7 +39,7 @@ module Spielbash
39
39
  return if pid.empty?
40
40
 
41
41
  loop do
42
- execute_with('pgrep', "-P #{pid}", true)
42
+ exec_wait_check_cmd(pid)
43
43
  children = last_stdout
44
44
  break if children.empty?
45
45
  end
@@ -59,6 +59,15 @@ module Spielbash
59
59
 
60
60
  private
61
61
 
62
+ def exec_wait_check_cmd(pid)
63
+ if context.wait_check_cmd.nil?
64
+ execute_with('pgrep', "-P #{pid}", true)
65
+ else
66
+ cmd = context.wait_check_cmd.split
67
+ execute_with_exactly(cmd.first, true, false, true, *cmd.drop(1))
68
+ end
69
+ end
70
+
62
71
  def execute_tmux_with(arguments, wait = false)
63
72
  execute_with('tmux', arguments, wait)
64
73
  end
@@ -9,3 +9,5 @@ require 'spielbash/model/action/command_action'
9
9
  require 'spielbash/model/action/pause_action'
10
10
  require 'spielbash/model/action/action_context'
11
11
  require 'spielbash/model/action/message_context'
12
+ require 'spielbash/model/action/new_environment_action'
13
+ require 'spielbash/model/action/delete_environment_action'
@@ -1,3 +1,3 @@
1
1
  module Spielbash
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spielbash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Malinskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -148,8 +148,10 @@ files:
148
148
  - lib/spielbash/model/action/action_context.rb
149
149
  - lib/spielbash/model/action/base_action.rb
150
150
  - lib/spielbash/model/action/command_action.rb
151
+ - lib/spielbash/model/action/delete_environment_action.rb
151
152
  - lib/spielbash/model/action/message_action.rb
152
153
  - lib/spielbash/model/action/message_context.rb
154
+ - lib/spielbash/model/action/new_environment_action.rb
153
155
  - lib/spielbash/model/action/pause_action.rb
154
156
  - lib/spielbash/model/action/press_key_action.rb
155
157
  - lib/spielbash/model/context.rb