Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/spielbash/interactor/record_interactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def create_actions(context, scenes)
when scene.has_key?('tmux_command') then
cmd = scene['tmux_command']
Spielbash::TmuxCommandAction.new(cmd, action_context)
when scene.has_key?('read_file') then
cmd = scene['read_file']
Spielbash::ReadFileAction.new(cmd, action_context)
when scene.has_key?('background_command') then
cmd = scene['background_command']
Spielbash::BackgroundCommandAction.new(cmd, action_context)
else
not_implemented
end
Expand Down
14 changes: 14 additions & 0 deletions lib/spielbash/model/action/background_command_action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Spielbash
class BackgroundCommandAction < Spielbash::BaseAction
attr_accessor :command

def initialize(command, action_context)
super(action_context)
@command = command
end

def execute(session)
session.execute_with_exactly('tmux', action_context.wait, false, true, '-c', command)
end
end
end
3 changes: 1 addition & 2 deletions lib/spielbash/model/action/command_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ def execute(session)
session.send_key(c)
sleep(action_context.typing_delay_s)
end
sleep(action_context.reading_delay_s)
session.send_key('C-m')

session.wait if action_context.wait

sleep(action_context.reading_delay_s)
end
end
end
21 changes: 21 additions & 0 deletions lib/spielbash/model/action/read_file_action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Spielbash
class ReadFileAction < Spielbash::BaseAction
attr_accessor :filePath

def initialize(file_path, action_context)
super(action_context)
@filePath = file_path
end

def execute(session)
File.open(filePath, "r").each_line do |row|
row.each_char do |c|
session.send_key(c)
sleep(action_context.typing_delay_s)
end
session.send_key('Enter')
end
sleep(action_context.reading_delay_s)
end
end
end
34 changes: 18 additions & 16 deletions lib/spielbash/model/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def send_key(key, count=1)
key = case key
when ' ' then 'Space'
when ';' then '\\;'
when '\t' then 'Tab'
when ' ' then 'Tab'
else key
end
execute_tmux_with("send-keys -t #{name} -N #{count} #{key}", true)
Expand All @@ -62,22 +64,6 @@ def execute_tmux_with(arguments, wait = false)
execute_with('tmux', arguments, wait)
end

private

def exec_wait_check_cmd(pid)
if is_real_environment
execute_with('pgrep', "-P #{pid}", true)
else
cmd = context.wait_check_cmd.split
execute_with_exactly(cmd.first, true, false, true, *cmd.drop(1))
end
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
end

def execute_with_exactly(cmd, wait, io_inherit, leader, *arguments)
raise "Please install #{cmd}" if is_real_environment && which(cmd).nil?

Expand All @@ -99,6 +85,22 @@ def execute_with_exactly(cmd, wait, io_inherit, leader, *arguments)
process
end

private

def exec_wait_check_cmd(pid)
if is_real_environment
execute_with('pgrep', "-P #{pid}", true)
else
cmd = context.wait_check_cmd.split
execute_with_exactly(cmd.first, true, false, true, *cmd.drop(1))
end
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
end

def is_real_environment
context.wait_check_cmd.nil?
end
Expand Down
2 changes: 2 additions & 0 deletions lib/spielbash/spielbash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
require 'spielbash/model/action/new_environment_action'
require 'spielbash/model/action/delete_environment_action'
require 'spielbash/model/action/tmux_command_action'
require 'spielbash/model/action/read_file_action'
require 'spielbash/model/action/background_command_action'
2 changes: 1 addition & 1 deletion lib/spielbash/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Spielbash
VERSION = "0.1.4"
VERSION = "0.1.5"
end