stratis-storage/stratis-cli

Column alignment fails with non-ascii characters

Closed this issue · 7 comments

# stratis filesystem
Pool Name    Name  Used     Created            Device                       
yes_you_can  ☺     546 MiB  Oct 05 2018 16:24  /dev/stratis/yes_you_can/☺   
yes_you_can  漢字    546 MiB  Oct 10 2018 09:37  /dev/stratis/yes_you_can/漢字

I tried experimenting with wcwidth and the widths seem to be calculated correctly, however things do not align because the characters are not 1 column width wide. This seems to be more of a font issue than a calculating widths issue. Not sure if we can fix this one.

--- a/src/stratis_cli/_actions/_formatting.py
+++ b/src/stratis_cli/_actions/_formatting.py
@@ -16,6 +16,7 @@ Formatting for tables.
 """
 
 import sys
+from wcwidth import wcswidth
 
 
 def print_table(column_headings, row_entries, alignment, file=sys.stdout):
@@ -38,7 +39,7 @@ def print_table(column_headings, row_entries, alignment, file=sys.stdout):
 
     column_lengths = [
         max(
-            max((len(e[index]) for e in row_entries), default=0),
+            max((wcswidth(e[index]) for e in row_entries), default=0),
             len(column_headings[index])) + 2 for index in range(num_columns)
     ]

And this is how unicode standard defines it https://www.unicode.org/reports/tr11/

This seems like:

  • Not a fundamental correctness issue.
  • Kind of challenging to fix.

Can we postpone it?

The rule has been that the PRs get put in the "Review" slot, but issue are supposed to remain in "In Progress" until they clear.

The rule has been that the PRs get put in the "Review" slot, but issue are supposed to remain in "In Progress" until they clear.

Indeed, I've corrected things, thanks.

Resolved by #245.