Archived
1
0
Fork 0

Add basic code

This commit is contained in:
Braiden Vasco 2017-07-21 06:48:04 +00:00
parent 5c7982c561
commit c798d4c06f
3 changed files with 73 additions and 0 deletions

View file

@ -8,6 +8,9 @@ Layout/AccessModifierIndentation:
Metrics/LineLength:
Max: 120
Style/Documentation:
Enabled: false
Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma

View file

@ -1,2 +1,9 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
lib = File.expand_path('../lib', __dir__).freeze
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
require 'main'
Main.new

63
lib/main.rb Normal file
View file

@ -0,0 +1,63 @@
# frozen_string_literal: true
require 'thread'
require 'curses'
class Main
def self.inherited(_base)
raise "#{self} is final"
end
def self.mutex
(@mutex ||= Mutex.new).tap { freeze }
end
def initialize
raise "#{self.class} is singleton" unless self.class.mutex.try_lock
call
end
private
def call
before_loop
loop do
before_iteration
sleep
after_iteration
end
after_loop
end
def sleep
super 0.01
end
def before_loop
Curses.init_screen
Curses.start_color
Curses.noecho # do no echo input
Curses.curs_set 0 # invisible cursor
Curses.timeout = 0 # non-blocking input
Curses.stdscr.keypad = true
Curses.init_pair 1, Curses::COLOR_WHITE, Curses::COLOR_BLACK
Curses.init_pair 2, Curses::COLOR_BLACK, Curses::COLOR_WHITE
end
def after_loop
Curses.close_screen
end
def before_iteration; end
def after_iteration
loop do
event = Curses.getch
break if event.nil?
handle event
end
end
def handle(event); end
end