class Blade::Runner::Tab

Attributes

content_window[R]
state_window[R]
window[R]

Public Class Methods

active() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 35
def active
  all.detect(&:active?)
end
draw() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 21
def draw
  window.clear
  window.noutrefresh
  all.each(&:draw)
end
install(options = {}) click to toggle source
# File lib/blade/interface/runner/tab.rb, line 9
def install(options = {})
  top = options[:top]
  @window = create_window(top: top, height: 3)

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

  top = @state_window.begy + @state_window.maxy + 1
  @content_window = create_window(top: top)
  @content_window.scrollok(true)
end
remove(id) click to toggle source
Calls superclass method Blade::Model::remove
# File lib/blade/interface/runner/tab.rb, line 27
def remove(id)
  tab = find(id)
  tab.deactivate
  tab.window.close
  super
  draw
end
stale() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 39
def stale
  threshold = Time.now - 2
  all.select { |t| t.last_ping_at && t.last_ping_at < threshold }
end

Public Instance Methods

activate() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 140
def activate
  return if active?

  if tab = tabs.active
    tab.deactivate
  end

  self.active = true
  draw

  tabs.state_window.addstr(session.to_s)
  tabs.state_window.noutrefresh
end
activate_next() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 167
def activate_next
  all = tabs.all

  if all.last == self
    all.first.activate
  elsif tab = all[index + 1]
    tab.activate
  end
end
activate_previous() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 177
def activate_previous
  all = tabs.all

  if all.first == self
    all.last.activate
  elsif tab = all[index - 1]
    tab.activate
  end
end
active?() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 136
def active?
  active
end
color() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 187
def color
  case state
  when "running"  then colors.yellow
  when "finished" then colors.green
  when /fail/     then colors.red
  else                 colors.white
  end
end
deactivate() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 154
def deactivate
  return unless active?

  self.active = false
  draw

  tabs.state_window.clear
  tabs.state_window.noutrefresh

  tabs.content_window.clear
  tabs.content_window.noutrefresh
end
dot() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 116
def dot
  state == "pending" ? "○" : "●"
end
draw() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 69
def draw
  window.clear
  active? ? draw_active : draw_inactive
  window.noutrefresh
end
draw_active() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 75
def draw_active
  window.addstr "╔═══╗"
  window.addstr "║ "
  window.attron(color)
  window.addstr(dot)
  window.attroff(color)
  window.addstr(" ║")
  window.addstr "╝   ╚"
  draw_test_results
end
draw_inactive() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 86
def draw_inactive
  window.addstr "\n"
  window.attron(color)
  window.addstr("  #{dot}\n")
  window.attroff(color)
  window.addstr "═════"
end
draw_test_results() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 94
def draw_test_results
  tabs.content_window.clear
  failures = []

  session.test_results.results.each do |result|
    tabs.content_window.addstr(status_dot(result))
    failures << result if result[:status] == "fail"
  end

  failures.each do |result|
    tabs.content_window.addstr("\n\n")
    tabs.content_window.attron(Curses::A_BOLD)
    tabs.content_window.attron(colors.red)
    tabs.content_window.addstr("#{status_dot(result)} #{result[:name]}\n")
    tabs.content_window.attroff(colors.red)
    tabs.content_window.attroff(Curses::A_BOLD)
    tabs.content_window.addstr(result[:message])
  end

  tabs.content_window.noutrefresh
end
height() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 49
def height
  3
end
index() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 124
def index
  tabs.all.index(self)
end
left() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 61
def left
  tabs.window.begx + index * width
end
session() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 128
def session
  Blade::Session.find(id)
end
state() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 132
def state
  session.test_results.state
end
status_dot(result) click to toggle source
# File lib/blade/interface/runner/tab.rb, line 120
def status_dot(result)
  Blade::TestResults::STATUS_DOTS[result[:status]]
end
tabs() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 45
def tabs
  self.class
end
top() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 57
def top
  tabs.window.begy
end
width() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 53
def width
  5
end
window() click to toggle source
# File lib/blade/interface/runner/tab.rb, line 65
def window
  @window ||= create_window(height: height, width: width, top: top, left: left)
end