Class: BladeRunner::Console::Tab
- Inherits:
-
Model
- Object
- OpenStruct
- Model
- BladeRunner::Console::Tab
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_window ⇒ Object
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_window ⇒ Object
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
|
.window ⇒ Object
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
.active ⇒ Object
37
38
39
|
# File 'lib/blade_runner/interface/console_tab.rb', line 37
def active
all.detect(&:active?)
end
|
.draw ⇒ Object
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
|
.stale ⇒ Object
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
#activate ⇒ Object
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_next ⇒ Object
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_previous ⇒ Object
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
111
112
113
|
# File 'lib/blade_runner/interface/console_tab.rb', line 111
def active?
active
end
|
#color ⇒ Object
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
|
#deactivate ⇒ Object
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
|
#dot ⇒ Object
95
96
97
|
# File 'lib/blade_runner/interface/console_tab.rb', line 95
def dot
status == "pending" ? "○" : "●"
end
|
#draw ⇒ Object
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_active ⇒ Object
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_inactive ⇒ Object
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
|
#height ⇒ Object
51
52
53
|
# File 'lib/blade_runner/interface/console_tab.rb', line 51
def height
3
end
|
#index ⇒ Object
99
100
101
|
# File 'lib/blade_runner/interface/console_tab.rb', line 99
def index
tabs.all.index(self)
end
|
#left ⇒ Object
63
64
65
|
# File 'lib/blade_runner/interface/console_tab.rb', line 63
def left
tabs.window.begx + index * width
end
|
#session ⇒ Object
103
104
105
|
# File 'lib/blade_runner/interface/console_tab.rb', line 103
def session
BR::Session.find(id)
end
|
#status ⇒ Object
107
108
109
|
# File 'lib/blade_runner/interface/console_tab.rb', line 107
def status
session.test_results.status
end
|
#tabs ⇒ Object
47
48
49
|
# File 'lib/blade_runner/interface/console_tab.rb', line 47
def tabs
self.class
end
|
#top ⇒ Object
59
60
61
|
# File 'lib/blade_runner/interface/console_tab.rb', line 59
def top
tabs.window.begy
end
|
#width ⇒ Object
55
56
57
|
# File 'lib/blade_runner/interface/console_tab.rb', line 55
def width
5
end
|
#window ⇒ Object
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
|