Navigation Menu

Skip to content

Commit

Permalink
Truncate long suite name
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 11, 2012
1 parent 3657643 commit 778774d
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/groonga/tester.rb
Expand Up @@ -1321,6 +1321,16 @@ def report_test_result(result, label)
puts(message)
end

def justify(message, width)
return " " * width if message.nil?
return message.ljust(width) if message.bytesize <= width
half_width = width / 2.0
elision_mark = "..."
left = message[0, half_width.ceil - elision_mark.size]
right = message[(message.size - half_width.floor)..-1]
"#{left}#{elision_mark}#{right}"
end

def print(message)
@current_column += message.to_s.size
@output.print(message)
Expand Down Expand Up @@ -1362,7 +1372,11 @@ def start_worker(worker)
end

def start_suite(worker)
puts(worker.suite_name)
if worker.suite_name.bytesize <= @term_width
puts(worker.suite_name)
else
puts(justify(worker.suite_name, @term_width))
end
@output.flush
end

Expand Down Expand Up @@ -1469,7 +1483,12 @@ def draw

def draw_status_line(worker)
clear_line
puts("[#{worker.id}] (#{worker.status}) #{worker.suite_name}")
left = "[#{worker.id}] "
right = " [#{worker.status}]"
rest_width = @term_width - @current_column
center_width = rest_width - left.bytesize - right.bytesize
center = justify(worker.suite_name, center_width)
puts("#{left}#{center}#{right}")
end

def draw_test_line(worker)
Expand Down Expand Up @@ -1499,6 +1518,7 @@ def up_n_lines(n)
def clear_line
print(" " * @term_width)
print("\r")
reset_current_column
end

def n_using_lines
Expand Down

0 comments on commit 778774d

Please sign in to comment.