Class: Spielbash::Session
- Inherits:
-
Object
- Object
- Spielbash::Session
- Defined in:
- lib/spielbash/model/session.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#last_stderr ⇒ Object
readonly
Returns the value of attribute last_stderr.
-
#last_stdout ⇒ Object
readonly
Returns the value of attribute last_stdout.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
Instance Method Summary collapse
- #close_session ⇒ Object
-
#initialize(name, output_path, context) ⇒ Session
constructor
A new instance of Session.
- #new_session ⇒ Object
- #send_key(key, count = 1) ⇒ Object
- #start_recording ⇒ Object
- #stop_recording ⇒ Object
-
#wait ⇒ Object
This will wait for tmux session pid to not have any child processes.
Constructor Details
#initialize(name, output_path, context) ⇒ Session
Returns a new instance of Session.
10 11 12 13 14 15 16 |
# File 'lib/spielbash/model/session.rb', line 10 def initialize(name, output_path, context) @context = context @name = name @output_path = output_path ChildProcess.posix_spawn = true end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
7 8 9 |
# File 'lib/spielbash/model/session.rb', line 7 def context @context end |
#last_stderr ⇒ Object (readonly)
Returns the value of attribute last_stderr.
8 9 10 |
# File 'lib/spielbash/model/session.rb', line 8 def last_stderr @last_stderr end |
#last_stdout ⇒ Object (readonly)
Returns the value of attribute last_stdout.
8 9 10 |
# File 'lib/spielbash/model/session.rb', line 8 def last_stdout @last_stdout end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/spielbash/model/session.rb', line 7 def name @name end |
#output_path ⇒ Object
Returns the value of attribute output_path.
7 8 9 |
# File 'lib/spielbash/model/session.rb', line 7 def output_path @output_path end |
Instance Method Details
#close_session ⇒ Object
28 29 30 31 32 33 |
# File 'lib/spielbash/model/session.rb', line 28 def close_session send_key("exit") send_key('C-m') wait end |
#new_session ⇒ Object
18 19 20 21 22 |
# File 'lib/spielbash/model/session.rb', line 18 def new_session execute_with('resize', "-s #{context.height} #{context.width}", false, false, false) execute_tmux_with("new-session -s #{name} -d") wait end |
#send_key(key, count = 1) ⇒ Object
48 49 50 51 |
# File 'lib/spielbash/model/session.rb', line 48 def send_key(key, count=1) key = 'Space' if key == ' ' execute_tmux_with("send-keys -t #{name} -N #{count} #{key}") end |
#start_recording ⇒ Object
53 54 55 56 57 58 |
# File 'lib/spielbash/model/session.rb', line 53 def start_recording execute_tmux_with('list-panes -F #{pane_pid}' + " -t #{name}", true) pid = last_stdout.strip execute_with('pgrep', "-P #{pid}", true) execute_with_exactly('asciinema', false, true, false, "rec", "-y", "-c", "tmux attach -t #{name}", "#{output_path}") end |
#stop_recording ⇒ Object
24 25 26 |
# File 'lib/spielbash/model/session.rb', line 24 def stop_recording send_key('C-d') end |
#wait ⇒ Object
This will wait for tmux session pid to not have any child processes
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/spielbash/model/session.rb', line 36 def wait execute_tmux_with('list-panes -F #{pane_pid}' + " -t #{name}", true) pid = last_stdout.strip return if pid.empty? loop do exec_wait_check_cmd(pid) children = last_stdout break if children.empty? end end |