Class: Rblock::Screen

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Screen

Returns a new instance of Screen.



3
4
5
6
7
# File 'lib/rblock/screen.rb', line 3

def initialize(name)
  @name = "rblock_" + name
  @short_name = name
  self
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


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

def running?
  screen_list = `screen -ls #{@name}`
  screens = screen_list.lines.to_a[1..-3] # [0],[-2], and [-1] are all info text, so ignore
  screens.each do |screen|
    if screen =~ /#{@name}\t/
      return true # found it! return from the function immediately
    end
  end

  return false # we didn't find any... :(
end

#send(cmd) ⇒ Object



26
27
28
# File 'lib/rblock/screen.rb', line 26

def send(cmd)
  system "screen -p 0 -S #{@name} -X eval \"stuff '" + cmd + "'\\015\""
end

#start(cmd = "") ⇒ Object



21
22
23
24
# File 'lib/rblock/screen.rb', line 21

def start(cmd = "")
  system "screen -d -m -S #{@name} #{cmd}" if not running?
  self
end