gloc 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +16 -0
  4. data/exe/gloc +65 -59
  5. data/lib/gloc/version.rb +1 -1
  6. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9597ef8cbe66bd1bbabd842ce14ec2f704480ceaadf0dd31c378b6e9d5c9e32
4
- data.tar.gz: 20fc8dd502a50480c0432f6b7261da11217e1c8d74e4d33a29a2f2c2deeba60e
3
+ metadata.gz: 8a54a3fda53607841e4ebd43bd11ca75497650dda5ca6499b8b6c03df1f7cbb5
4
+ data.tar.gz: 2ecdf050623c6e8ed1668683013e18dad09453d0966dac53f7b8661cf12a6984
5
5
  SHA512:
6
- metadata.gz: 8c071d0a4803d928cd37d6394c084449776ed7f9162248fc5dcbdf61890ff46f4353a30673d6fefff1ae386ff921d840580dc3949ee0454fdffeb215269010fb
7
- data.tar.gz: 463124056b75f7099654b03d338d94c0be65789d54058eed901c8bbd39ef89745fb262dc327c0538ad127058f394b1f2d3f1dcfa5285ce82d5de914b94303d77
6
+ metadata.gz: bb59760f48ef824d7aeadfbe305badf9e6c94e662f6c63ae94e5f92f5624eaeea883a4848e1102357e1d7324fd66d38cec900bbf1dbe0886ea4df4d328c269b5
7
+ data.tar.gz: '08f53b35d6e344913dcf6401dc7a282b25f95204074e961d755535f493a96256f5e16112da95a6fe026412fd32e67884db78106bfc52d0765b317fc6a0ed026a'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gloc (0.5.0)
4
+ gloc (0.6.0)
5
5
  rainbow (~> 3.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -99,6 +99,22 @@ The results are sorted by "lines of code" by default _(with "lines of code" defi
99
99
  gloc -comment # sort by the number of comment lines
100
100
  gloc -code # sort by lines of code (default)
101
101
 
102
+ ## Processing
103
+
104
+ When `gloc`'s STDOUT isn't a TTY, it outputs the LoC stats in JSON format, for further parsing and processing.
105
+
106
+ This also means you can pretty-print the LoC stats as follows:
107
+
108
+ gloc | jq
109
+
110
+ ... which uses the [the indispensable jq utility][jq] (`brew install jq`) for processing the JSON output.
111
+
112
+ To "force" the typical TTY output even when STDOUT isn't a TTY, you can use the `-tty` option as follows:
113
+
114
+ gloc -tty | pbcopy
115
+
116
+ ... which copies the non-JSON version of the LoC stats to the clipboard.
117
+
102
118
  ## Known Issues and Possible Enhancements
103
119
 
104
120
  * identify comment-only lines for a lot more languages
data/exe/gloc CHANGED
@@ -144,7 +144,7 @@ source_stats['TOTAL'] = OpenStruct.new(
144
144
  # JSON formatting for non-TTY output
145
145
  #
146
146
 
147
- unless STDOUT.tty? || $tty
147
+ unless STDOUT.tty? || $tty || $visual
148
148
  require 'json'
149
149
 
150
150
  class OpenStruct
@@ -158,79 +158,85 @@ unless STDOUT.tty? || $tty
158
158
  exit
159
159
  end
160
160
 
161
- #
162
- # fancy formatting for TTY output
163
- #
164
-
165
- class String
166
- def commify
167
- gsub(/(\d)(?=(\d{3})+(\..*)?$)/, '\1,')
161
+ unless $visual
162
+ class String
163
+ def commify
164
+ gsub(/(\d)(?=(\d{3})+(\..*)?$)/, '\1,')
165
+ end
168
166
  end
169
- end
170
167
 
171
- class Numeric
172
- def commify
173
- to_s.commify
168
+ class Numeric
169
+ def commify
170
+ to_s.commify
171
+ end
174
172
  end
175
- end
176
173
 
177
- source_stats.values.each do |stats_for_ext|
178
- stats_for_ext.file_count = stats_for_ext.file_count.commify
179
- stats_for_ext.line_count = stats_for_ext.line_count.commify
180
- stats_for_ext.blank_count = stats_for_ext.blank_count.commify
181
- stats_for_ext.comment_count = stats_for_ext.comment_count.commify
182
- stats_for_ext.code_count = stats_for_ext.code_count.commify
183
- end
174
+ #
175
+ # fancy formatting for TTY output
176
+ #
184
177
 
185
- DIVIDER = ('-' * 80) # because loc uses 80 columns
186
- TEMPLATE = ' %-13s %12s %12s %12s %12s %12s'.freeze
178
+ source_stats.values.each do |stats_for_ext|
179
+ stats_for_ext.file_count = stats_for_ext.file_count.commify
180
+ stats_for_ext.line_count = stats_for_ext.line_count.commify
181
+ stats_for_ext.blank_count = stats_for_ext.blank_count.commify
182
+ stats_for_ext.comment_count = stats_for_ext.comment_count.commify
183
+ stats_for_ext.code_count = stats_for_ext.code_count.commify
184
+ end
187
185
 
188
- puts format(
189
- "#{DIVIDER}\n#{TEMPLATE}\n#{DIVIDER}",
190
- 'Language', 'Files', 'Lines', 'Blank', 'Comment', 'Code'
191
- )
186
+ DIVIDER = ('-' * 80) # because loc uses 80 columns
187
+ TEMPLATE = ' %-13s %12s %12s %12s %12s %12s'.freeze
192
188
 
193
- source_stats.each do |file_ext, stats|
194
189
  puts format(
195
- TEMPLATE,
196
- file_ext,
197
- stats.file_count,
198
- stats.line_count,
199
- stats.blank_count,
200
- stats.comment_count,
201
- stats.code_count,
190
+ "#{DIVIDER}\n#{TEMPLATE}\n#{DIVIDER}",
191
+ 'Language', 'Files', 'Lines', 'Blank', 'Comment', 'Code'
202
192
  )
203
- end
204
-
205
- puts format(
206
- "#{DIVIDER}\n#{TEMPLATE}\n#{DIVIDER}",
207
- 'Total', *source_stats.delete('TOTAL').to_h.values
208
- )
209
-
210
- exit unless $visual # show summary stats only
211
-
212
- require 'rainbow'
213
- require 'io/console'
214
193
 
215
- max_line_count = file_stats.values.map(&:line_count).max
216
- longest_filename = file_stats.keys.map(&:first).map(&:length).max
217
- _, console_width = IO.console.winsize
218
- available_width = Float(console_width - longest_filename - 5)
219
-
220
- file_stats.each_pair do |(file, _, _), stats|
221
- code_width = (available_width * stats.code_count / max_line_count)
222
- comment_width = (available_width * stats.comment_count / max_line_count)
223
- blank_width = (available_width * stats.blank_count / max_line_count)
194
+ source_stats.each do |file_ext, stats|
195
+ next if file_ext == 'TOTAL'
196
+
197
+ puts format(
198
+ TEMPLATE,
199
+ file_ext,
200
+ stats.file_count,
201
+ stats.line_count,
202
+ stats.blank_count,
203
+ stats.comment_count,
204
+ stats.code_count,
205
+ )
206
+ end
224
207
 
225
208
  puts format(
226
- " %-#{longest_filename}<file>s | %<code>s%<comment>s%<blank>s",
227
- file: file,
228
- code: Rainbow('+' * code_width).green,
229
- comment: Rainbow('-' * comment_width).red,
230
- blank: Rainbow('⍽' * blank_width).blue,
209
+ "#{DIVIDER}\n#{TEMPLATE}\n#{DIVIDER}",
210
+ 'Total', *source_stats.fetch('TOTAL').to_h.values
231
211
  )
232
212
  end
233
213
 
214
+ if $visual
215
+ require 'rainbow'
216
+ require 'io/console'
217
+
218
+ max_line_count = file_stats.values.map(&:line_count).max
219
+ longest_filename = file_stats.keys.map(&:first).map(&:length).max
220
+ _, console_width = IO.console.winsize
221
+ available_width = Float(console_width - longest_filename - 5)
222
+
223
+ abort 'Terminal not wide enough... aborting!' if available_width.negative?
224
+
225
+ file_stats.each_pair do |(file, _, _), stats|
226
+ code_width = (available_width * stats.code_count / max_line_count)
227
+ comment_width = (available_width * stats.comment_count / max_line_count)
228
+ blank_width = (available_width * stats.blank_count / max_line_count)
229
+
230
+ puts format(
231
+ " %-#{longest_filename}<file>s | %<code>s%<comment>s%<blank>s",
232
+ file: file,
233
+ code: Rainbow('+' * code_width).green,
234
+ comment: Rainbow('-' * comment_width).red,
235
+ blank: Rainbow('⍽' * blank_width).blue,
236
+ )
237
+ end
238
+ end
239
+
234
240
  #
235
241
  # rubocop:enable Style/RegexpLiteral
236
242
  # rubocop:enable Style/GlobalVars
@@ -1,6 +1,6 @@
1
1
  module GLOC
2
2
  NAME = 'gloc'.freeze
3
- VERSION = '0.5.0'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
 
5
5
  def self.version
6
6
  "#{NAME} v#{VERSION}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Vandenberk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-23 00:00:00.000000000 Z
11
+ date: 2019-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  requirements: []
154
- rubygems_version: 3.0.2
154
+ rubygems_version: 3.0.4
155
155
  signing_key:
156
156
  specification_version: 4
157
157
  summary: Not `loc`, not `cloc`, not `tokei`, not `SLOCCOUNT`, ...