Class: BladeRunner::Console::Tab

Inherits:
Model
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/blade_runner/interface/console_tab.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

all, create, find, models, size

Class Attribute Details

.content_windowObject (readonly)

Returns the value of attribute content_window.



9
10
11
# File 'lib/blade_runner/interface/console_tab.rb', line 9

def content_window
  @content_window
end

.status_windowObject (readonly)

Returns the value of attribute status_window.



9
10
11
# File 'lib/blade_runner/interface/console_tab.rb', line 9

def status_window
  @status_window
end

.windowObject (readonly)

Returns the value of attribute window.



9
10
11
# File 'lib/blade_runner/interface/console_tab.rb', line 9

def window
  @window
end

Class Method Details

.activeObject



37
38
39
# File 'lib/blade_runner/interface/console_tab.rb', line 37

def active
  all.detect(&:active?)
end

.drawObject



23
24
25
26
27
# File 'lib/blade_runner/interface/console_tab.rb', line 23

def draw
  window.clear
  window.noutrefresh
  all.each(&:draw)
end

.install(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/blade_runner/interface/console_tab.rb', line 11

def install(options = {})
  top = options[:top]
  @window = create_window(top: top, height: 3)

  top = @window.begy + @window.maxy + 1
  @status_window = create_window(top: top, height: 1)

  top = @status_window.begy + @status_window.maxy + 1
  @content_window = create_window(top: top)
  @content_window.scrollok(true)
end

.remove(id) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/blade_runner/interface/console_tab.rb', line 29

def remove(id)
  tab = find(id)
  tab.deactivate
  tab.window.close
  super
  draw
end

.staleObject



41
42
43
44
# File 'lib/blade_runner/interface/console_tab.rb', line 41

def stale
  threshold = Time.now - 2
  all.select { |t| t.last_ping_at && t.last_ping_at < threshold }
end

Instance Method Details

#activateObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/blade_runner/interface/console_tab.rb', line 115

def activate
  return if active?

  if tab = tabs.active
    tab.deactivate
  end

  self.active = true
  draw

  tabs.status_window.addstr(session.to_s)
  tabs.status_window.noutrefresh

  tabs.content_window.addstr(session.test_results.to_s)
  tabs.content_window.noutrefresh
end

#activate_nextObject



145
146
147
148
149
150
151
152
153
# File 'lib/blade_runner/interface/console_tab.rb', line 145

def activate_next
  tabs = tabs.all

  if tabs.last == self
    tabs.first.activate
  elsif tab = tabs[index + 1]
    tab.activate
  end
end

#activate_previousObject



155
156
157
158
159
160
161
162
163
# File 'lib/blade_runner/interface/console_tab.rb', line 155

def activate_previous
  tabs = tabs.all

  if tabs.first == self
    tabs.last.activate
  elsif tab = tabs[index - 1]
    tab.activate
  end
end

#active?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/blade_runner/interface/console_tab.rb', line 111

def active?
  active
end

#colorObject



165
166
167
168
169
170
171
172
# File 'lib/blade_runner/interface/console_tab.rb', line 165

def color
  case status
  when "running"  then colors.yellow
  when "finished" then colors.green
  when /fail/     then colors.red
  else                 colors.white
  end
end

#deactivateObject



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/blade_runner/interface/console_tab.rb', line 132

def deactivate
  return unless active?

  self.active = false
  draw

  tabs.status_window.clear
  tabs.status_window.noutrefresh

  tabs.content_window.clear
  tabs.content_window.noutrefresh
end

#dotObject



95
96
97
# File 'lib/blade_runner/interface/console_tab.rb', line 95

def dot
  status == "pending" ? "" : ""
end

#drawObject



71
72
73
74
75
# File 'lib/blade_runner/interface/console_tab.rb', line 71

def draw
  window.clear
  active? ? draw_active : draw_inactive
  window.noutrefresh
end

#draw_activeObject



77
78
79
80
81
82
83
84
85
# File 'lib/blade_runner/interface/console_tab.rb', line 77

def draw_active
  window.addstr "╔═══╗"
  window.addstr ""
  window.attron(color)
  window.addstr(dot)
  window.attroff(color)
  window.addstr("")
  window.addstr "╝   ╚"
end

#draw_inactiveObject



87
88
89
90
91
92
93
# File 'lib/blade_runner/interface/console_tab.rb', line 87

def draw_inactive
  window.addstr "\n"
  window.attron(color)
  window.addstr("  #{dot}\n")
  window.attroff(color)
  window.addstr "═════"
end

#heightObject



51
52
53
# File 'lib/blade_runner/interface/console_tab.rb', line 51

def height
  3
end

#indexObject



99
100
101
# File 'lib/blade_runner/interface/console_tab.rb', line 99

def index
  tabs.all.index(self)
end

#leftObject



63
64
65
# File 'lib/blade_runner/interface/console_tab.rb', line 63

def left
  tabs.window.begx + index * width
end

#sessionObject



103
104
105
# File 'lib/blade_runner/interface/console_tab.rb', line 103

def session
  BR::Session.find(id)
end

#statusObject



107
108
109
# File 'lib/blade_runner/interface/console_tab.rb', line 107

def status
  session.test_results.status
end

#tabsObject



47
48
49
# File 'lib/blade_runner/interface/console_tab.rb', line 47

def tabs
  self.class
end

#topObject



59
60
61
# File 'lib/blade_runner/interface/console_tab.rb', line 59

def top
  tabs.window.begy
end

#widthObject



55
56
57
# File 'lib/blade_runner/interface/console_tab.rb', line 55

def width
  5
end

#windowObject



67
68
69
# File 'lib/blade_runner/interface/console_tab.rb', line 67

def window
  @window ||= create_window(height: height, width: width, top: top, left: left)
end