-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Right alignment of last column #29
Comments
Could you please provide a reproduction? Please specify inputs, actual outputs and expected outputs. |
Output:
Expected output:
|
That does not seem expected to me. Patches are welcome. |
Thanks for looking into this. I came up with that workaround of using a trailing tab by reading the original thread about alignment here: #24 (comment) Trailing tabs work for me but I think it should be mentioned in the docs if it cannot be easily fixed. |
I looked at Go's implementation of tabwriter at https://golang.org/pkg/text/tabwriter/ and it seems that it shows exactly the same behavior (look at the trailing tab example). So maybe you want to keep it that way to be compatible with the Go tabwriter. Still, I think it is kind of surprising to the user if he wants to output a table with tabwriter and the last column is not right aligned, despite specifying Alignment::Right. I guess if it is documented properly like the Go version it's ok, because the user can always output a trailing \t. |
Thanks for the bug report.
Yeah, this is an unfortunate effect of the [elastic
tabstops](http://nickgravgaard.com/elastic-tabstops/) notion of a **cell**.
Specifically, a cell is a tab-less string **to the left of** of tab.
Vertically adjacent cells are horizontally aligned. Alignment within cells is
introduced by altering where the spaces are added to a cell. This means that
spaces **are not** added to the right of the final tab.
That being said, if there's a consistent and reasonably simple way of
re-thinking elastic tabstops which results in the last column of a table being
right-aligned, I'm all for it!
One idea would be to change the notion of a cell in Right/Center modes to
include the text after the final tab.
What do you guys think about that? Is there some problem that I'm not seeing?
…On Tue, Mar 10, 2020 at 12:34:45AM -0700, Michael Jacob wrote:
I looked at Go's implementation of tabwriter at https://golang.org/pkg/text/tabwriter/ and it seems that it shows exactly the same behavior (look at the trailing tab example). So maybe you want to keep it that way to be compatible with the Go tabwriter.
Still, I think it is kind of surprising to the user if he wants to output a table with tabwriter and the last column is **not** right aligned, despite specifying Alignment::Right.
I guess if it is documented properly like the Go version it's ok, because the user can always output a trailing \t.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#29 (comment)
|
Basically we have two options:
Since the crate shares its name with the Go package, I think it is reasonable to keep it compatible with it. Also, when outputting a table row, adding a \t after each element is easier than having a special case for the first element. It is basically the same as considering \t as a cell-ending token visa a cell-separating token. I think the owner of the package should decide. |
It's been a long time since I've looked into the implementation here. If there's an easy way to fix this that doesn't involve completely rewriting everything, then we should do it. There was never any intent on my part to be specifically compatible with Go's |
Previously, a **cell** was a block of text to the left of some tab. This meant that a table like this: aa\tbb a\tb would be formatted as aa bb a b in right-alignment mode because the b's were not actually in a cell, and thus didn't get aligned. This commit modifies the notion of a "cell" in right- and center-alignment mode to also include text to the right of the last tab on the line. This text is now considered part of a cell and aligned accordingly. Implemented as describe above, this change would cause many trailing spaces to be printed in right- and center-alignment modes, including on empty lines. To alleviate this, trailing spaces in the final cell of a line are not printed. fixes BurntSushi#29
Right alignment of the last column only works when there is a trailing tab on the line. Otherwise the last column is left-aligned which looks strange.
If this is a known restriction and not a bug it could possibly be documented.
The text was updated successfully, but these errors were encountered: