class Mani::Window

This class contains methods to handle operations run within windows.

Public Class Methods

new(windowing_system) click to toggle source

Initializes the window.

@param [Object] windowing_system The windowing system

# File lib/mani/window.rb, line 36
def initialize(windowing_system)
  @windowing_system = windowing_system
end

Public Instance Methods

browser_tab(tab, options = {}, &block) click to toggle source

Creates a new tab, or switches to the supplied tab.

@param [Symbol, Integer] tab The tab. If :new is specified, a new tab

will be created and the window will switch to it. If an integer is
specified, the window will switch to that (previously existing) tab.

@param [Hash] options The options

* :delay (Numeric) _Optional_ The amount of time, in seconds, to delay
  after handling the tab (defaults to 0.5)

@param [Proc] block The code to execute after handling the tab

# File lib/mani/window.rb, line 13
def browser_tab(tab, options = {}, &block)
  @windowing_system.focus_window @pid

  if tab == :new
    @windowing_system.type_keysequence 'ctrl+t'
    @windowing_system.type_keysequence 'alt+9'
  elsif tab >= 1 && tab <= 8
    @windowing_system.type_keysequence "alt+#{tab}"
  elsif tab > 8
    @windowing_system.type_keysequence 'alt+8'
    (tab - 8).times { @windowing_system.type_keysequence 'ctrl+Tab' }
  else
    return
  end

  sleep options[:delay] || 0.5

  instance_eval(&block) if block
end
launch(program, options = {}, &block) click to toggle source

Launches the supplied program.

@param [String] program The program @param [Hash] options The options

* :delay (Numeric) _Optional_ The amount of time, in seconds, to delay
  after launching the program (defaults to 0.5)

@param [Proc] block The code to execute after launching the program

# File lib/mani/window.rb, line 47
def launch(program, options = {}, &block)
  return if @pid

  @pid = Process.spawn program
  Process.detach @pid

  sleep options[:delay] || 0.5

  instance_eval(&block) if block
end
run(command, options = {}) click to toggle source

Runs the supplied command within the current window.

@param [String] command The command @param [Hash] options The options

* :delay (Numeric) _Optional_ The amount of time, in seconds, to delay
  after running the command (defaults to 0.5)
# File lib/mani/window.rb, line 64
def run(command, options = {})
  @windowing_system.focus_window @pid
  @windowing_system.type_combination command
  @windowing_system.type_keysequence 'Return'

  sleep options[:delay] || 0.5
end
type(text, options = {}) click to toggle source

Types the supplied text into the current window.

@param [String] text The text @param [Hash] options The options

* :delay (Numeric) _Optional_ The amount of time, in seconds, to delay
  after typing the text (defaults to 0.5)
# File lib/mani/window.rb, line 78
def type(text, options = {})
  @windowing_system.focus_window @pid
  @windowing_system.type_combination text

  sleep options[:delay] || 0.5
end
visit(url, options = {}) click to toggle source

Enters the supplied url into the current window.

@param [String] url The url @param [Hash] options The options

* :delay (Numeric) _Optional_ The amount of time, in seconds, to delay
  after entering the url (defaults to 0.5)
# File lib/mani/window.rb, line 91
def visit(url, options = {})
  run url, options
end