module Blade::Runner
Constants
- COLOR_NAMES
- PADDING
Public Instance Methods
colors()
click to toggle source
# File lib/blade/interface/runner.rb, line 12 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 = {})
click to toggle source
# File lib/blade/interface/runner.rb, line 22 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
run()
click to toggle source
# File lib/blade/interface/runner.rb, line 41 def run start_screen init_windows handle_keys handle_stale_tabs Blade.subscribe("/results") do |details| session = Blade::Session.find(details[:session_id]) unless tab = Tab.find(session.id) tab = Tab.create(id: session.id) tab.activate if Tab.size == 1 end tab.draw Curses.doupdate end end
start()
click to toggle source
# File lib/blade/interface/runner.rb, line 32 def start run Blade::Assets.watch_logical_paths end
stop()
click to toggle source
# File lib/blade/interface/runner.rb, line 37 def stop Curses.close_screen end
Private Instance Methods
handle_keys()
click to toggle source
# File lib/blade/interface/runner.rb, line 82 def handle_keys EM.defer do while ch = Curses.getch case ch when Curses::KEY_LEFT Tab.active.try(:activate_previous) Curses.doupdate when Curses::KEY_RIGHT Tab.active.try(:activate_next) Curses.doupdate when "q" Blade.stop end end end end
handle_stale_tabs()
click to toggle source
# File lib/blade/interface/runner.rb, line 99 def handle_stale_tabs Blade.subscribe("/browsers") do |details| if details["message"] = "ping" if tab = Tab.find(details["session_id"]) tab.last_ping_at = Time.now end end end EM.add_periodic_timer(1) do Tab.stale.each { |t| remove_tab(t) } end end
init_windows()
click to toggle source
# File lib/blade/interface/runner.rb, line 69 def init_windows header_window = create_window(height: 3) header_window.attron(Curses::A_BOLD) header_window.addstr "BLADE RUNNER [press 'q' to quit]\n" header_window.attroff(Curses::A_BOLD) header_window.addstr "Open #{Blade.url} to start" header_window.noutrefresh Tab.install(top: header_window.maxy) Curses.doupdate end
remove_tab(tab)
click to toggle source
# File lib/blade/interface/runner.rb, line 113 def remove_tab(tab) Tab.remove(tab.id) Curses.doupdate end
start_screen()
click to toggle source
# File lib/blade/interface/runner.rb, line 61 def start_screen Curses.init_screen Curses.start_color Curses.noecho Curses.curs_set(0) Curses.stdscr.keypad(true) end