comparison mercurial/cmdutil.py @ 33879:6f6c87888b22

log: add a "graphwidth" template variable Wrapping text in templates for 'hg log --graph' can't be done very well, because the template doesn't know how wide the graph drawing is. The edge drawing function needs to know the number of lines in the template output, so we need to also determine how wide that drawing would be before we call the edgefn or evaluate the template. This patch makes edgefn compute the graph width and pass it into the template so that we can do something like this: COLUMNS=10 hg log --graph --template "{fill(desc, termwidth - graphwidth)}" @ a a a a | a a a a | a a a a o a a a |\ a a a | | a a a | | a a a Using extensions to do this would be relatively complicated due to a lack of hooks in this area of the code. In the future it may make sense to have a more generic "textwidth" that tells you how many columns you can expect to fill without causing the terminal to wrap your output. I'm not sure there are other situations to motivate this yet, or if it is entirely feasible. Differential Revision: https://phab.mercurial-scm.org/D360
author Danny Hooper <hooper@google.com>
date Tue, 15 Aug 2017 10:15:31 -0700
parents eae63a9e59da
children e5d104c35e51
comparison
equal deleted inserted replaced
33878:833f70277f0e 33879:6f6c87888b22
2650 if rename: 2650 if rename:
2651 copies.append((fn, rename[0])) 2651 copies.append((fn, rename[0]))
2652 revmatchfn = None 2652 revmatchfn = None
2653 if filematcher is not None: 2653 if filematcher is not None:
2654 revmatchfn = filematcher(ctx.rev()) 2654 revmatchfn = filematcher(ctx.rev())
2655 displayer.show(ctx, copies=copies, matchfn=revmatchfn) 2655 edges = edgefn(type, char, state, rev, parents)
2656 firstedge = next(edges)
2657 width = firstedge[2]
2658 displayer.show(ctx, copies=copies, matchfn=revmatchfn,
2659 _graphwidth=width)
2656 lines = displayer.hunk.pop(rev).split('\n') 2660 lines = displayer.hunk.pop(rev).split('\n')
2657 if not lines[-1]: 2661 if not lines[-1]:
2658 del lines[-1] 2662 del lines[-1]
2659 displayer.flush(ctx) 2663 displayer.flush(ctx)
2660 edges = edgefn(type, char, lines, state, rev, parents) 2664 for type, char, width, coldata in itertools.chain([firstedge], edges):
2661 for type, char, lines, coldata in edges:
2662 graphmod.ascii(ui, state, type, char, lines, coldata) 2665 graphmod.ascii(ui, state, type, char, lines, coldata)
2666 lines = []
2663 displayer.close() 2667 displayer.close()
2664 2668
2665 def graphlog(ui, repo, pats, opts): 2669 def graphlog(ui, repo, pats, opts):
2666 # Parameters are identical to log command ones 2670 # Parameters are identical to log command ones
2667 revs, expr, filematcher = getgraphlogrevs(repo, pats, opts) 2671 revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)