From 41a8a08e4c79e1f8775e3292a7117cd4899ae02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Cie=C5=9Bnik?= Date: Mon, 26 Oct 2020 17:33:21 +0100 Subject: [PATCH 1/2] semicolon fix --- lib/spielbash/model/session.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/spielbash/model/session.rb b/lib/spielbash/model/session.rb index c2baa03..a41b52c 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 From a908671c6bfd7173e8d7f97e5aae30584c35e363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Cie=C5=9Bnik?= Date: Mon, 26 Oct 2020 20:43:03 +0100 Subject: [PATCH 2/2] tmux commands --- lib/spielbash/interactor/record_interactor.rb | 3 +++ .../model/action/tmux_command_action.rb | 16 ++++++++++++++++ lib/spielbash/model/session.rb | 8 ++++---- lib/spielbash/spielbash.rb | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 lib/spielbash/model/action/tmux_command_action.rb 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 a41b52c..c4c9875 100644 --- a/lib/spielbash/model/session.rb +++ b/lib/spielbash/model/session.rb @@ -58,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) @@ -69,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'