Class: Screen::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/screen/window.rb

Instance Method Summary collapse

Constructor Details

#initialize(window, window_number, session, first) ⇒ Window

Returns a new instance of Window.



10
11
12
13
14
15
16
17
18
# File 'lib/screen/window.rb', line 10

def initialize(window, window_number, session, first)
    @session = session
    @window_number = window_number
    if first
        Kernel.system "screen -X -S #{@session} title #{window}"
    else
        Kernel.system "screen -X -S #{@session} screen -t #{window} #{@window_number}"
    end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(command, *args) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/screen/window.rb', line 43

def method_missing(command, *args)
    unix_command = "screen -X -S #{@session} -p #{@window_number} #{command}"
    if !args.size.zero?
        args = args.map {|a| a.class == String ? a : a.to_s }
        unix_command << " #{args.join(' ')}"
    end
    Kernel.system unix_command
end

Instance Method Details

#exec(*args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/screen/window.rb', line 20

def exec(*args)
    if args.all? {|a| a.class == String }
        stuffed = args
    elsif args[0].class == Array and args[0].all? {|a| a.class == String }
        stuffed = args[0]
    else
        raise ArgumentError, 'not unix command'
    end
    stuffed = %Q|"#{stuffed.join("\n")}\n"|
    Kernel.system "screen -X -S #{@session} -p #{@window_number} stuff #{stuffed}"
end

#ssh(hostname, password = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/screen/window.rb', line 33

def ssh(hostname, password=nil)
    stuffed = %Q|"ssh #{hostname}\r\n"|
    Kernel.system "screen -X -S #{@session} -p #{@window_number} stuff #{stuffed}"
    sleep 1
    if(password)
        stuffed = %Q|"#{password}\r\n"|
        Kernel.system "screen -X -S #{@session} -p #{@window_number} stuff #{stuffed}"
    end
end