diff --git a/lib/spielbash/interactor/record_interactor.rb b/lib/spielbash/interactor/record_interactor.rb index e1300dc..a98f926 100644 --- a/lib/spielbash/interactor/record_interactor.rb +++ b/lib/spielbash/interactor/record_interactor.rb @@ -64,6 +64,9 @@ def create_actions(context, scenes) when scene.has_key?('delete_env') then cmd = scene['delete_env'] Spielbash::DeleteEnvironmentAction.new(cmd, context) + when scene.has_key?('tmux_command') then + cmd = scene['tmux_command'] + Spielbash::TmuxCommandAction.new(cmd, action_context) else not_implemented end diff --git a/lib/spielbash/model/action/tmux_command_action.rb b/lib/spielbash/model/action/tmux_command_action.rb new file mode 100644 index 0000000..7621da3 --- /dev/null +++ b/lib/spielbash/model/action/tmux_command_action.rb @@ -0,0 +1,16 @@ +module Spielbash + class TmuxCommandAction < Spielbash::BaseAction + attr_accessor :command + + def initialize(command, action_context) + super(action_context) + @command = command + end + + def execute(session) + session.execute_tmux_with(command, action_context.wait) + + sleep(action_context.reading_delay_s) + end + end +end \ No newline at end of file diff --git a/lib/spielbash/model/session.rb b/lib/spielbash/model/session.rb index c2baa03..c4c9875 100644 --- a/lib/spielbash/model/session.rb +++ b/lib/spielbash/model/session.rb @@ -43,7 +43,11 @@ def wait end def send_key(key, count=1) - key = 'Space' if key == ' ' + key = case key + when ' ' then 'Space' + when ';' then '\\;' + else key + end execute_tmux_with("send-keys -t #{name} -N #{count} #{key}", true) end @@ -54,6 +58,10 @@ def start_recording execute_with_exactly('asciinema', false, true, false, "rec", "-y", "-c", "tmux attach -t #{name}", "#{output_path}") end + def execute_tmux_with(arguments, wait = false) + execute_with('tmux', arguments, wait) + end + private def exec_wait_check_cmd(pid) @@ -65,10 +73,6 @@ def exec_wait_check_cmd(pid) end end - def execute_tmux_with(arguments, wait = false) - execute_with('tmux', arguments, wait) - end - def execute_with(cmd, arguments, wait = false, leader = true, io_inherit = false) args = arguments.split execute_with_exactly cmd, wait, io_inherit, leader, *args diff --git a/lib/spielbash/spielbash.rb b/lib/spielbash/spielbash.rb index 6a6ca70..0728250 100644 --- a/lib/spielbash/spielbash.rb +++ b/lib/spielbash/spielbash.rb @@ -11,3 +11,4 @@ require 'spielbash/model/action/message_context' require 'spielbash/model/action/new_environment_action' require 'spielbash/model/action/delete_environment_action' +require 'spielbash/model/action/tmux_command_action'