Module: BladeRunner::Console

Extended by:
Console, Forwardable
Includes:
Component
Included in:
Console
Defined in:
lib/blade_runner/interface/console.rb

Defined Under Namespace

Classes: Tab

Constant Summary collapse

COLOR_NAMES =
%w( white yellow green red )
PADDING =
1

Instance Method Summary collapse

Methods included from Component

included

Instance Method Details

#colorsObject



15
16
17
18
19
20
21
22
23
# File 'lib/blade_runner/interface/console.rb', line 15

def colors
  @colors ||= OpenStruct.new.tap do |colors|
    COLOR_NAMES.each do |name|
      const = Curses.const_get("COLOR_#{name.upcase}")
      Curses.init_pair(const, const, Curses::COLOR_BLACK)
      colors[name] = Curses.color_pair(const)
    end
  end
end

#create_window(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/blade_runner/interface/console.rb', line 25

def create_window(options = {})
  height = options[:height] || 0
  width  = options[:width]  || 0
  top    = options[:top]    || 0
  left   = options[:left]   || PADDING
  parent = options[:parent] || Curses.stdscr

  parent.subwin(height, width, top, left)
end

#runObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/blade_runner/interface/console.rb', line 44

def run
  start_screen
  init_windows
  handle_keys
  handle_stale_tabs

  BR.subscribe("/results") do |details|
    session = BR::Session.find(details["session_id"])

    if tab = Tab.find(session.id)
      if details["line"] && tab.active?
        Tab.content_window.addstr(details["line"] + "\n")
        Tab.content_window.noutrefresh
      end
      tab.draw
    else
      tab = Tab.create(id: session.id)
      tab.activate if Tab.size == 1
    end

    Curses.doupdate
  end
end

#startObject



35
36
37
38
# File 'lib/blade_runner/interface/console.rb', line 35

def start
  run
  BR::Assets.watch_logical_paths
end

#stopObject



40
41
42
# File 'lib/blade_runner/interface/console.rb', line 40

def stop
  Curses.close_screen
end