exe/gloc in gloc-0.4.0 vs exe/gloc in gloc-0.5.0
- old
+ new
@@ -118,10 +118,16 @@
when $comment then :comment_count
when $code then :code_count
else :code_count
end
+file_stats = Hash[
+ STATS_FOR_FILE.sort_by { |_, stats|
+ stats.send(sort_metric)
+ }.reverse
+]
+
source_stats = Hash[
STATS_FOR.sort_by { |_, stats|
stats.send(sort_metric)
}.reverse
]
@@ -174,17 +180,10 @@
stats_for_ext.blank_count = stats_for_ext.blank_count.commify
stats_for_ext.comment_count = stats_for_ext.comment_count.commify
stats_for_ext.code_count = stats_for_ext.code_count.commify
end
-# widest_file_ext = source_stats.keys.map(&:length).max
-# widest_file_count = source_stats.values.map(&:file_count).map(&:length).max
-# widest_line_count = source_stats.values.map(&:line_count).map(&:length).max
-# widest_blank_count = source_stats.values.map(&:blank_count).map(&:length).max
-# widest_comment_count = source_stats.values.map(&:comment_count).map(&:length).max
-# widest_code_count = source_stats.values.map(&:code_count).map(&:length).max
-
DIVIDER = ('-' * 80) # because loc uses 80 columns
TEMPLATE = ' %-13s %12s %12s %12s %12s %12s'.freeze
puts format(
"#{DIVIDER}\n#{TEMPLATE}\n#{DIVIDER}",
@@ -205,9 +204,33 @@
puts format(
"#{DIVIDER}\n#{TEMPLATE}\n#{DIVIDER}",
'Total', *source_stats.delete('TOTAL').to_h.values
)
+
+exit unless $visual # show summary stats only
+
+require 'rainbow'
+require 'io/console'
+
+max_line_count = file_stats.values.map(&:line_count).max
+longest_filename = file_stats.keys.map(&:first).map(&:length).max
+_, console_width = IO.console.winsize
+available_width = Float(console_width - longest_filename - 5)
+
+file_stats.each_pair do |(file, _, _), stats|
+ code_width = (available_width * stats.code_count / max_line_count)
+ comment_width = (available_width * stats.comment_count / max_line_count)
+ blank_width = (available_width * stats.blank_count / max_line_count)
+
+ puts format(
+ " %-#{longest_filename}<file>s | %<code>s%<comment>s%<blank>s",
+ file: file,
+ code: Rainbow('+' * code_width).green,
+ comment: Rainbow('-' * comment_width).red,
+ blank: Rainbow('⍽' * blank_width).blue,
+ )
+end
#
# rubocop:enable Style/RegexpLiteral
# rubocop:enable Style/GlobalVars
# rubocop:enable Style/EmptyCaseCondition