1212 -v, --version Print module version and exit.
1313 --branch=<b> Branch or tag [default: HEAD] up to which to check.
1414 --sort=<key> [default: loc]|commits|files|hours|months.
15+ --min=<val> Minimum value (of `--sort` key) to show [default: 0:int].
1516 --loc=<type> surv(iving)|ins(ertions)|del(etions)
1617 What `loc` represents. Use 'ins,del' to count both.
1718 defaults to 'surviving' unless `--cost` is specified.
5051 --ignore-revs-file=<f> Ignore revisions listed in the given file
5152 (requires `--loc=surviving`).
5253 --format=<format> Table format
53- [default: pipe]|md|markdown|yaml|yml|json|csv|tsv|tabulate.
54+ svg| [default: pipe]|md|markdown|yaml|yml|json|csv|tsv|tabulate.
5455 May require `git-fame[<format>]`, e.g. `pip install git-fame[yaml]`.
5556 Any `tabulate.tabulate_formats` is also accepted.
5657 --manpath=<path> Directory in which to install git-fame man pages.
@@ -123,7 +124,7 @@ def hours(dates, maxCommitDiffInSec=120 * 60, firstCommitAdditionInMinutes=120):
123124
124125
125126def tabulate (auth_stats , stats_tot , sort = 'loc' , bytype = False , backend = 'md' , cost = None ,
126- row_nums = False , width = TERM_WIDTH ):
127+ row_nums = False , min_sort_val = 0 , width = TERM_WIDTH ):
127128 """
128129 backends : [default: md]|yaml|json|csv|tsv|tabulate|
129130 `in tabulate.tabulate_formats`
@@ -154,6 +155,8 @@ def tabulate(auth_stats, stats_tot, sort='loc', bytype=False, backend='md', cost
154155
155156 for i , j in (("commits" , "coms" ), ("files" , "fils" ), ("hours" , "hrs" ), ("months" , "mths" )):
156157 sort = sort .replace (i , j )
158+ if min_sort_val :
159+ tab = [i for i in tab if i [COL_NAMES .index (sort )] >= min_sort_val ]
157160 tab .sort (key = lambda i : i [COL_NAMES .index (sort )], reverse = True )
158161 if row_nums :
159162 tab = [[str (i )] + j for i , j in enumerate (tab , 1 )]
@@ -163,6 +166,9 @@ def tabulate(auth_stats, stats_tot, sort='loc', bytype=False, backend='md', cost
163166
164167 if (backend := backend .lower ()) in ("tabulate" , "md" , "markdown" ):
165168 backend = "pipe"
169+ svg = backend == 'svg'
170+ if svg :
171+ backend = 'rounded_outline'
166172
167173 if backend in ('yaml' , 'yml' , 'json' , 'csv' , 'tsv' ):
168174 tab = [i [:- 1 ] + [float (pc .strip ()) for pc in i [- 1 ].split ('/' )] for i in tab ]
@@ -194,13 +200,25 @@ def tabulate(auth_stats, stats_tot, sort='loc', bytype=False, backend='md', cost
194200 raise RuntimeError ("Should be unreachable" )
195201 else :
196202 import tabulate as tabber
203+
197204 if backend not in tabber .tabulate_formats :
198205 raise ValueError (f"Unknown backend:{ backend } " )
199206 log .debug ("backend:tabulate:%s" , backend )
200207 COL_LENS = [max (len (Str (i [j ])) for i in [COL_NAMES ] + tab ) for j in range (len (COL_NAMES ))]
201208 COL_LENS [0 ] = min (width - sum (COL_LENS [1 :]) - len (COL_LENS ) * 3 - 4 , COL_LENS [0 ])
202209 tab = [[i [0 ][:COL_LENS [0 ]]] + i [1 :] for i in tab ]
203- return totals + tabber .tabulate (tab , COL_NAMES , tablefmt = backend , floatfmt = '.0f' )
210+ table = tabber .tabulate (tab , COL_NAMES , tablefmt = backend , floatfmt = '.0f' )
211+ if svg :
212+ rows = table .split ('\n ' )
213+ return ('<svg xmlns="http://www.w3.org/2000/svg"'
214+ f' width="{ len (rows [0 ]) / 2 + 1 } em" height="{ len (rows )} em">'
215+ '<rect x="0" y="0" width="100%" height="100%"'
216+ ' fill="white" fill-opacity="0.5" rx="5"/>'
217+ '<text x="0" y="-0.5em" font-size="15"'
218+ ' font-family="monospace" style="white-space: pre">' +
219+ '' .join (f'<tspan x="0" dy="1em">{ row } </tspan>'
220+ for row in rows ) + '</text></svg>' )
221+ return totals + table
204222
205223 # from ._utils import tighten
206224 # return totals + tighten(tabber(...), max_width=TERM_WIDTH)
@@ -467,7 +485,8 @@ def run(args):
467485 # log.debug(extns)
468486
469487 print_unicode (
470- tabulate (auth_stats , stats_tot , args .sort , args .bytype , args .format , cost , args .enum ))
488+ tabulate (auth_stats , stats_tot , args .sort , args .bytype , args .format , cost , args .enum ,
489+ args .min ))
471490
472491
473492def get_main_parser ():
0 commit comments