Class: Rascut::Plugin::Screen

Inherits:
Base
  • Object
show all
Defined in:
lib/rascut/plugin/screen.rb

Constant Summary collapse

STATUS =
%q[%H %`%-w%{=b bw}%n %t%{-}%+w %=]
SCREEN_CMD =
'screen'
SCREEN_COLOR =
{
  :black => 'dd',
  :blue  => 'bk',
  :green => 'gk',
  :red   => 'rw',
}

Instance Method Summary collapse

Methods inherited from Base

#config, #initialize

Constructor Details

This class inherits a constructor from Rascut::Plugin::Base

Instance Method Details

#clearObject



43
44
45
# File 'lib/rascut/plugin/screen.rb', line 43

def clear
  send_cmd('')
end

#errorObject



27
28
29
# File 'lib/rascut/plugin/screen.rb', line 27

def error
  message 'E', :red
end

#message(msg, color = :black) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/rascut/plugin/screen.rb', line 35

def message(msg, color = :black)
  if run_screen_session?
    col = SCREEN_COLOR[color]
    msg = %Q[ %{=b #{col}} #{msg} %{-}]
    send_cmd(msg)
  end
end

#runObject



17
18
19
20
21
# File 'lib/rascut/plugin/screen.rb', line 17

def run
  @command.wrapper.hooks[:compile_start] << method(:start)
  @command.wrapper.hooks[:compile_error] << method(:error)
  @command.wrapper.hooks[:compile_success] << method(:success)
end

#run_screen_session?Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/rascut/plugin/screen.rb', line 47

def run_screen_session?
  str = `#{SCREEN_CMD} -ls`
  str.match(/(\d+) Socket/) && ($1.to_i > 0)
end

#send_cmd(msg) ⇒ Object



52
53
54
55
# File 'lib/rascut/plugin/screen.rb', line 52

def send_cmd(msg)
  cmd = %Q[#{SCREEN_CMD} -X eval 'hardstatus alwayslastline "#{(STATUS + msg).gsub('"', '\"')}"']
  system cmd
end

#startObject



23
24
25
# File 'lib/rascut/plugin/screen.rb', line 23

def start
  message 'C'
end

#successObject



31
32
33
# File 'lib/rascut/plugin/screen.rb', line 31

def success
  message 'S', :blue
end