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 adds an optional widthfn callback alongside edgefn so that callers
to displaygraph() can enable it to pass the computed graph width into the
template. The new argument is added so as to avoid breaking any extensions
calling the current displaygraph(). The stock asciiedges() gets a stock
asciiwidth() 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.
Just a nit. Is there any practical benefit to compute edges lazy?
I think edges can be simply converted to a list.