Skip to content

Commit

Permalink
Merge pull request #4 from go-labs/cols_failover
Browse files Browse the repository at this point in the history
Column width failover
  • Loading branch information
crojasaragonez committed Apr 12, 2018
2 parents 0c836b2 + 75f3229 commit 376f889
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
46 changes: 22 additions & 24 deletions lib/rspec_pacman_formatter/pacman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,34 @@

module RspecPacmanFormatter
class Pacman < RSpec::Core::Formatters::BaseTextFormatter
RSpec::Core::Formatters.register(
self, :start, :close, :example_started,
:example_passed, :example_failed, :example_pending
)
CI_TERMINAL_WIDTH = 80
RSpec::Core::Formatters.register(self, :start, :close, :example_started,
:example_passed, :example_failed,
:example_pending)

attr_accessor :progress_line, :failed

def initialize(*args)
super
@progress_line = ''
@failed = 0
@cols = 0
@notification = 0
@repetitions = 0
@failed = 0
@notification = 0
@repetitions = 0
end

def cols
@cols ||= begin
width = `tput cols`.chomp.to_i
width.nil? || width.zero? ? CI_TERMINAL_WIDTH : width
end
end

def start(notification)
puts 'GAME STARTED'
@cols = terminal_width
@notification = notification.count
update_progress_line
end

def terminal_width
`tput cols`.chomp.to_i
rescue StandardError
CI_TERMINAL_WIDTH
end

def example_started(_)
step(Characters::PACMAN)
end
Expand All @@ -54,12 +53,12 @@ def close(_)
end

def update_progress_line
if @notification > @cols
if (@notification / @cols).eql?(@repetitions)
@progress_line = Characters::PACDOT * (@notification - (@cols * @repetitions))
if @notification > cols
if (@notification / cols).eql?(@repetitions)
@progress_line = Characters::PACDOT * (@notification - (cols * @repetitions))
return
end
@progress_line = Characters::PACDOT * @cols
@progress_line = Characters::PACDOT * cols
return
end
@progress_line = Characters::PACDOT * @notification
Expand All @@ -70,11 +69,10 @@ def update_progress_line
def step(character)
@progress_line = @progress_line.sub(/#{Regexp.quote(Characters::PACMAN)}|#{Regexp.quote(Characters::PACDOT)}/, character)
print format("%s\r", @progress_line)
if @progress_line[-1] =~ /ᗣ|\./
@repetitions += 1
puts
update_progress_line
end
return unless @progress_line[-1] =~ /ᗣ|\./
@repetitions += 1
puts
update_progress_line
end
end
end
2 changes: 1 addition & 1 deletion lib/rspec_pacman_formatter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RspecPacmanFormatter
VERSION = '0.1.4'.freeze
VERSION = '0.1.5'.freeze
end

0 comments on commit 376f889

Please sign in to comment.