Module: Lab42::Tmux::Session::Commands

Included in:
Lab42::Tmux::Session
Defined in:
lib/lab42/tmux/session/commands.rb

Instance Method Summary collapse

Instance Method Details

#goto(dest) ⇒ Object



7
8
9
10
# File 'lib/lab42/tmux/session/commands.rb', line 7

def goto dest
  return unless dest
  send_keys "cd #{dest}"
end

#new_window(window_name, &block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/lab42/tmux/session/commands.rb', line 11

def new_window window_name, &block
  @window_number += 1
  command 'new-window', '-t', session_name, '-n', "'#{window_name}'"
  goto configuration.project_home
  instance_exec( &@after_new_window_hook ) if @after_new_window_hook
  instance_exec( &block ) if block
end

#really_wait_for(match_rgx, in_pane:, dependent_actions:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/lab42/tmux/session/commands.rb', line 38

def really_wait_for( match_rgx, in_pane:, dependent_actions: )
  loop do
    text = capture_pane in_pane
    if match_rgx === text
      conditional_sleep configuration.post_wait_interval
      return instance_exec( &dependent_actions )
    end
    sleep configuration.wait_interval
  end
end

#send_keys(*keys) ⇒ Object



19
20
21
# File 'lib/lab42/tmux/session/commands.rb', line 19

def send_keys *keys
  command( 'send-keys', '-t', [session_name, window_number].join(':'), *keys.map(&:inspect), 'C-m' )
end

#send_keys_raw(*keys) ⇒ Object



23
24
25
# File 'lib/lab42/tmux/session/commands.rb', line 23

def send_keys_raw *keys
  command( 'send-keys', '-t', [session_name, window_number].join(':'), *keys.map(&:inspect) )
end

#wait_for(text_or_rgx, alternate_pane_addr = nil, &blk) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/lab42/tmux/session/commands.rb', line 27

def wait_for text_or_rgx, alternate_pane_addr=nil, &blk
  require 'timeout'
  pane_addr = alternate_pane_addr || window_address
  text_or_rgx = %r{#{text_or_rgx}}m unless Regexp === text_or_rgx
  conditional_sleep configuration.pre_wait_interval
  Timeout.timeout configuration.wait_timeout do
    really_wait_for text_or_rgx, in_pane: pane_addr, dependent_actions: blk
  end
rescue Timeout::Error 
end