require 'pluginscan/printer' module Pluginscan class CLOCPrinter < Printer def print(cloc) print_headline print_results(cloc) print_blank_line end private def print_headline @output.puts "SLOC counts from the 'CLOC' tool:".color(:blue) end def print_results(cloc) print_no_result if cloc.language_counts.empty? cloc.language_counts.each{ |language_count| print_result language_count } end def print_result(language_count) data = { language: language_count.language.color(:green), sloc: language_count.sloc.to_s.color(:red), file_count: language_count.file_count, } # Field widths need to account for the colouring characters: 9 of them in total # e.g. for red this is \e[31m at the beginning and \e[0m at the end, # with \e counting as one character: # pad sloc to 5 (+9 = 14) # pad language to 12 (+9 = 21) @output.puts format(" %-21s %14s lines across %2d files\n", data) end def print_no_result sadface = ":(".color(:red) @output.puts " CLOC didn't find any code #{sadface}" end end end