_ _ _ _
| |_ __ _| |__ _ _| | __ _| |_ ___
| __/ _` | '_ \| | | | |/ _` | __/ _ \
| || (_| | |_) | |_| | | (_| | || __/
\__\__,_|_.__/ \__,_|_|\__,_|\__\___|
Format plaintext into fixed-width table with multiline cells.
copied from
tabulate --help
:
Format plain text into fixed-width table with multi-line cell by wrapping text
in each field
Usage: tabulate [OPTIONS] [FILENAME]
Arguments:
[FILENAME] The input stream, default to stdin
Options:
-W, --widths <WIDTHS> The column widths
-T, --table-width <TABLE_WIDTH> The table total width, default to terminal
width
-L, --layout <TABLE_LAYOUT> The table layout, default to "grid_no_header"
-S, --strict Specify to enable strict mode
-d, --delimiter <DELIMITER> The field delimiter in the input data,
default to <TAB>
-e, --escape Specify to enable escape sequence as
`echo -e` in input data
-h, --help Print help
See synopsis.md for details.
See column_planner.md for more about automatic allocation of column widths.
Download the pre-built binary from the release page, or clone and build using cargo
:
git clone https://github.com/kkew3/tabulate.git
cd tabulate
cargo install --path .
Type tabulate -T35 example-texts/lipsum.txt
to format lipsum.txt:
lipsum.txt
Duis facilisis. Quisque ex nibh, auctor eu sodales.
Maecenas blandit elit.
Sed lobortis, nibh vitae. Mauris enim.
Output:
+-----------------+---------------+
| Duis facilisis. | Quisque ex |
| | nibh, auctor |
| | eu sodales. |
+-----------------+---------------+
| Maecenas | |
| blandit elit. | |
+-----------------+---------------+
| Sed lobortis, | Mauris enim. |
| nibh vitae. | |
+-----------------+---------------+
Type tabulate -T35 -e example-texts/lipsum_escape.txt
to format lipsum_escape.txt:
lipsum_escape.txt
Duis facilisis. Quisque ex nibh, auctor eu sodales.
Maecenas blandit elit.
Nunc blandit augue sed eros euismod maximus. \xf0\x9f\x98\x82\n\n- Nunc blandit augue sed eros euismod maximus.\n- Praesent aliquet, tellus laoreet. Mauris enim.
Output:
+---------------------+-----------+
| Duis facilisis. | Quisque |
| | ex nibh, |
| | auctor eu |
| | sodales. |
+---------------------+-----------+
| Maecenas blandit | |
| elit. | |
+---------------------+-----------+
| Nunc blandit augue | Mauris |
| sed eros euismod | enim. |
| maximus. 😂 | |
| | |
| - Nunc blandit | |
| augue sed eros | |
| euismod maximus. | |
| - Praesent aliquet, | |
| tellus laoreet. | |
+---------------------+-----------+
Type tabulate -T35 example-texts/lipsum_zh.txt
to format lipsum_zh.txt:
lipsum_zh.txt
衫峪笋诡卵 贷焚粗淮覆态该
凤闲折。碍敏轴扑前瑟驾精践兽油华刊宵迫赏队拧枝!钛嵌匆煞考映!
待临;辑醉揉? 皱柿托露。
(generated by sooxin/Chinese-Lorem-Ipsum)
Output (better viewed in fixed-width font where 1 CJK character is as wide as 2 ASCII characters):
+--------------------+------------+
| 衫峪笋诡卵 | 贷焚粗淮覆 |
| | 态该 |
+--------------------+------------+
| 凤闲折。碍敏轴扑前 | |
| 瑟驾精践兽油华刊宵 | |
| 迫赏队拧枝!钛嵌匆 | |
| 煞考映! | |
+--------------------+------------+
| 待临;辑醉揉? | 皱柿托露。 |
+--------------------+------------+
PrettyTable
and python-tabulate
are awesome packages to draw plaintext table.
However, while sharing some table layout with python-tabulate
, this utility solves a different problem.
The focus of this utility lies in fixed-width table, facilitating users to specify the width of each column themselves (or let the program decide the column widths).
This way, multiline cell has builtin support.
This utility is not the right tool to display single line data in good alignment.
To test locally, run
cargo test
Note that randomized property tests are included, so it may take some time to finish the tests.
Either benchmark the bisect algorithm with:
cargo bench --bench complete_user_widths -F bench-bisect
or the brute-force algorithm with:
cargo bench --bench complete_user_widths -F bench-brute