Commit graph

6 commits

Author SHA1 Message Date
Yuya Nishihara
b380ca0cf7 templater: move split_email() to text_util module
It's not specific to templating.
2023-03-13 11:45:17 +09:00
Yuya Nishihara
ec554f6df2 cli: implement word wrapping function for labeled output 2023-03-10 16:07:55 +09:00
Yuya Nishihara
1c852b7fb9 cli: implement word wrapping function for bytes
wrap_bytes() is similar to textwrap::wrap(), but can process arbitrary bytes.
More importantly, it guarantees that byte offsets can be reconstructed from
the split slices. This allows us to interleave push/pop_label()s with split
text fragments.

We could calculate byte offsets upfront, but using slice API is more
convenient. That's why I didn't add inner function returning Vec<Range>.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
c5046235b5 formatter: pass data range to replay callback instead of data slice
New word-wrap function will be implemented in two passes. The first pass
splits byte slice to lines, and the second pass inserts "\n" based on that
while interleaving push/pop_label() calls and text fragments. Since the second
pass combines multiple data sources, byte indices are more convenient than
slices there.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
2af2aca7ff templater: extract indent function to text_util module
This prepares for adding generic template object for reformatting.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
82604eda02 cli: extract complete_newline() to text_util module
I'll add more text formatting functions there.
2023-03-10 16:07:55 +09:00