Class: Mani::Window
- Inherits:
-
Object
- Object
- Mani::Window
- Defined in:
- lib/mani/window.rb
Overview
This class contains methods to handle operations run within windows.
Instance Method Summary collapse
-
#browser_tab(tab, options = {}, &block) ⇒ Object
Creates a new tab, or switches to the supplied tab.
-
#initialize(windowing_system) ⇒ Window
constructor
Initializes the window.
-
#launch(program, options = {}, &block) ⇒ Object
Launches the supplied program.
-
#run(command, options = {}) ⇒ Object
Runs the supplied command within the current window.
-
#type(text, options = {}) ⇒ Object
Types the supplied text into the current window.
-
#visit(url, options = {}) ⇒ Object
Enters the supplied url into the current window.
Constructor Details
#initialize(windowing_system) ⇒ Window
Initializes the window.
36 37 38 |
# File 'lib/mani/window.rb', line 36 def initialize(windowing_system) @windowing_system = windowing_system end |
Instance Method Details
#browser_tab(tab, options = {}, &block) ⇒ Object
Creates a new tab, or switches to the supplied tab.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mani/window.rb', line 13 def browser_tab(tab, = {}, &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 [:delay] || 0.5 instance_eval(&block) if block end |
#launch(program, options = {}, &block) ⇒ Object
Launches the supplied program.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mani/window.rb', line 47 def launch(program, = {}, &block) return if @pid @pid = Process.spawn program Process.detach @pid sleep [:delay] || 0.5 instance_eval(&block) if block end |
#run(command, options = {}) ⇒ Object
Runs the supplied command within the current window.
64 65 66 67 68 69 70 |
# File 'lib/mani/window.rb', line 64 def run(command, = {}) @windowing_system.focus_window @pid @windowing_system.type_combination command @windowing_system.type_keysequence 'Return' sleep [:delay] || 0.5 end |
#type(text, options = {}) ⇒ Object
Types the supplied text into the current window.
78 79 80 81 82 83 |
# File 'lib/mani/window.rb', line 78 def type(text, = {}) @windowing_system.focus_window @pid @windowing_system.type_combination text sleep [:delay] || 0.5 end |
#visit(url, options = {}) ⇒ Object
Enters the supplied url into the current window.
91 92 93 |
# File 'lib/mani/window.rb', line 91 def visit(url, = {}) run url, end |