AlDanial / cloc

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
GNU General Public License v2.0
19.78k stars 1.02k forks source link

narrow columns for short values #727

Closed mcandre closed 1 year ago

mcandre commented 1 year ago

When the longest value in a column is still short, then the output could be tidied up by dynamically selecting a narrower column padding size.

E.g. when the only programming language found is Go, the file count is single digit, etc.

The tidiest text padding, is the length of the longest entry in the previous column, plus one space.

As a bonus, dynamic padding would help cloc to format correctly in case of experiencing incredibly large directory trees, beyond what the current static padding supports.

AlDanial commented 1 year ago

The function that handles cloc's output tries to pad text to 79 columns. Making columns as tight as possible... I don't know, that doesn't really grab me. Having said that, it is straightforward to wrap cloc in a script that will squeeze the columns as tight as possible. Not just that, but with a wrapper you can satisfy #726 as well. The wrapper would just need to ingest one of cloc's programmer-friendly outputs (YAML, XML, or JSON) then format the results however you wish.

I've attached a sample wrapper to get you started. cloc_tidy.py.txt (in Python; added a .txt extension to allow the attachment)

Here's sample output from it:

---------------------------------------
Language     nFiles comment blank  code
---------------------------------------
Perl            164    6739  2770 26032
HTML             30     207   151  8866
Bourne Shell     35     107    48   447
Python            5     218    34   275
C                 1      19     4    50
MATLAB            1       1     0    22
---------------------------------------
SUM             236    7291  3007 35692
---------------------------------------
Language     nFiles comment blank  code
---------------------------------------