tabulate
tabulate copied to clipboard
Option to not strip leading (or trailing) whitespace in line-wrapped text?
I believe this is a feature request, but a workaround or solution would be great if one exists: an option/method to preserve leading whitespace would be desirable when markup (XML, JSON) snippets are the cell contents.
Perhaps we could have:
Format::enable_trim(bool en) { enable_trim_left(en); enable_trim_right(en) };
Format::enable_trim_left(bool);
Format::enable_trim_right(bool);
// or
enum class TrimDir{ none = 0, left = 1, right = 2, both = left | right /* remains default */};
Format::enable_trim(TrimDir);
// example usage
universal_contants.format()
.width(50)
.enable_trim(false);
// or
universal_contants.format()
.width(50)
.enable_trim(TrimDir::right); // better for JSON formatting
?
Not sure I can think of a good use case for keeping trailing whitespace... but there's probably one somewhere?
I don't think there's any existing solution. I came across exactly the same problem. The way I dealt with it is commenting the invocation of trim_left
functions.
What you proposed seems good.