gloc 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +16 -0
- data/exe/gloc +65 -59
- data/lib/gloc/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a54a3fda53607841e4ebd43bd11ca75497650dda5ca6499b8b6c03df1f7cbb5
|
4
|
+
data.tar.gz: 2ecdf050623c6e8ed1668683013e18dad09453d0966dac53f7b8661cf12a6984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb59760f48ef824d7aeadfbe305badf9e6c94e662f6c63ae94e5f92f5624eaeea883a4848e1102357e1d7324fd66d38cec900bbf1dbe0886ea4df4d328c269b5
|
7
|
+
data.tar.gz: '08f53b35d6e344913dcf6401dc7a282b25f95204074e961d755535f493a96256f5e16112da95a6fe026412fd32e67884db78106bfc52d0765b317fc6a0ed026a'
|
data/Gemfile.lock
CHANGED
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
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
-
|
173
|
-
|
168
|
+
class Numeric
|
169
|
+
def commify
|
170
|
+
to_s.commify
|
171
|
+
end
|
174
172
|
end
|
175
|
-
end
|
176
173
|
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
186
|
-
|
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
|
-
|
189
|
-
|
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
|
-
|
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
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
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
|
-
"
|
227
|
-
|
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
|
data/lib/gloc/version.rb
CHANGED
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.
|
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-
|
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.
|
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`, ...
|