Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

A Table method to get each line, instead of to_string which returns just 1 line #35

Closed
dmaahs2017 opened this issue Jun 27, 2021 · 2 comments

Comments

@dmaahs2017
Copy link
Contributor

dmaahs2017 commented Jun 27, 2021

Table::lines() -> impl Iterator<item=String>

I would like to add a method that returns an iterator of table lines.

For my specific use case, I would use this to output multiple similar tables side by side.

Here is an example of my use case: I would append the line of each table and handle the edge case's if one table has less lines than the next (haven't quite figured that out)

+--------+---------+---------+-----------+----------+--------+----------+    +--------+--------+---------+-----------+------------+--------+----------+
| Sunday | Monday  | Tuesday | Wednesday | Thursday | Friday | Saturday |    | Sunday | Monday | Tuesday | Wednesday | Thursday   | Friday | Saturday |
+=======================================================================+    +========================================================================+
|        |         |         |           | 1.       | 2.     | 3.       |    |        |        |         | 1.        | 2.         | 3.     | 4.       |
|        |         |         |           |          |        |          |    |        |        |         |           | stats hw 3 |        |          |
|--------+---------+---------+-----------+----------+--------+----------|    |--------+--------+---------+-----------+------------+--------+----------|
| 4.     | 5.      | 6.      | 7.        | 8.       | 9.     | 10.      |    | 5.     | 6.     | 7.      | 8.        | 9.         | 10.    | 11.      |
|        |         |         |           |          |        |          |    |        |        |         |           | stats hw 4 |        |          |
|--------+---------+---------+-----------+----------+--------+----------|    |        |        |         |           | test 5     |        |          |
| 11.    | 12.     | 13.     | 14.       | 15.      | 16.    | 17.      |    |--------+--------+---------+-----------+------------+--------+----------|
|        | do work |         |           |          |        |          |    | 12.    | 13.    | 14.     | 15.       | 16.        | 17.    | 18.      |
|--------+---------+---------+-----------+----------+--------+----------|    |        |        |         |           |            |        |          |
| 18.    | 19.     | 20.     | 21.       | 22.      | 23.    | 24.      |    |--------+--------+---------+-----------+------------+--------+----------|
|        |         |         |           |          |        |          |    | 19.    | 20.    | 21.     | 22.       | 23.        | 24.    | 25.      |
|--------+---------+---------+-----------+----------+--------+----------|    |        |        |         |           |            |        |          |
| 25.    | 26.     | 27.     | 28.       | 29.      | 30.    | 31.      |    |--------+--------+---------+-----------+------------+--------+----------|
|        |         |         |           |          |        |          |    | 26.    | 27.    | 28.     | 29.       | 30.        | 31.    |          |
+--------+---------+---------+-----------+----------+--------+----------+    |        |        |         |           |            |        |          |
                                                                             +--------+--------+---------+-----------+------------+--------+----------+

Thoughts on adding this to the Table API @Nukesor @spenserblack

see PR #36

@Nukesor
Copy link
Owner

Nukesor commented Jun 27, 2021

I really like the idea of adding an iterator over all lines of a table.

To be honest, If we add this, I would prefer to not add fmt_with_margin as it's quite easy to write that helper yourself.

I'm a huge fan of sleek APIs and I try to strictly follow a simple rule (in the context of comfy_table):
"Everything up to the rendering of the table belongs into the project, everything outside of that doesn't."

This might be a little nitpicky, but the formatting around the table is something the user should take care of.
However, we should definitely give the user every possibility to easily work with the table output, so they can achieve whatever they're planning to do.

So yes, I'm a fan of the lines() function, but I'm against the margin format. I think this isn't in the scope of this library and can easily be achieved by the user after the addition of lines() :)

@Nukesor
Copy link
Owner

Nukesor commented Jun 27, 2021

Closed via #36

@Nukesor Nukesor closed this as completed Jun 27, 2021
Nukesor added a commit that referenced this issue Jun 28, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants