Skip to content

Doesn't tabulate correctly with zero-width characters (Devanagari) #68

Closed

Description

@siddhpant

This is how it renders

Name            Score
------------  -------
राष्ट्र परीक्षण    19.25
Test             0

versus

Name               Score
---------------  -------
Devanagari here    19.25
Test                0

How it should render:

Name            Score
------------  -------
राष्ट्र परीक्षण         19.25
Test             0

I have the extra widechars libs installed.

Activity

  1. Delta456 commented on Jul 8, 2020

    @Delta456

    wcwidth doesn't supports Devangari yet.

  2. astanin commented on Feb 20, 2021

    @astanin
    Owner

    I tried your example (copy-pasting Devangari text, on Windows, tabulate 0.8.8), at it seems to work just fine:

    In [28]: tbl = [["रषटर परकषण", 19.25],["123456789A", 0]]
    
    In [29]: print(tabulate(tbl, headers=["Name","Score"]))
    Name          Score
    ----------  -------
    रषटर परकषण    19.25
    123456789A     0
    
    In [30]: wcwidth.__version__
    Out[30]: '0.2.5'
    

    Maybe some zero-width characters were lost in copy-and-paste operation? Just in case, this is the hex dump of the string:

    In [41]: [ "0x%04x"%ord(c) for c in tbl[0][0] ]
    Out[41]:
    ['0x0930',
     '0x0937',
     '0x091f',
     '0x0930',
     '0x0020',
     '0x092a',
     '0x0930',
     '0x0915',
     '0x0937',
     '0x0923']
    

    And the length of the first column is calculated to be 10:

    In [43]: wcwidth.wcswidth(tbl[0][0])
    Out[43]: 10
    

    I don't read Devangari, and cannot tell if it is correct. If it's not, then you should report a bug to https://github.com/jquast/wcwidth/issues

    If the issue is resolved, please let me know. There was a bug with the alignment of the wide characters fixed in 0.8.8.

  3. added
    invalid
    question
    on Feb 20, 2021
  4. siddhpant commented on Feb 26, 2021

    @siddhpant
    Author

    Unfortunately the Devanagari you copied was wrong. Even in that, you can see that the 0 in the second column is more to the right, or equivalently the Devanagari entry is to the left. Here's another test with the same string as yours on v0.8.9:

    Name          Points
    ----------  --------
    रषटर परकषण        20
    123456789A         0
    

    The previous example:

    Name            Points
    ------------  --------
    राष्ट्र परीक्षण     19.25
    Test              0
    

    Another example:

    Name              Points
    --------------  --------
    एक उत्तम उदाहरण      0.00
    A nice example      0.00
    
  5. removed
    invalid
    on Feb 26, 2021
  6. astanin commented on Feb 26, 2021

    @astanin
    Owner

    I took a look at https://docs.microsoft.com/en-us/typography/script-development/devanagari The writing system is complicated. And this begs a question, do monospaced Devanagari fonts even exist?

    According to a random blog post from 2015:

    There are also scripts like Devanagari that just don't seem to have a monospace representation. I was unable to get Windows to display Devanagari characters in console. They do display in Notepad, but they don't obey any kind of monospace font rules, at all.

    If this is still true, then tabulate won't be able to format Devanagari tables as plain text.

    As a workaround I suggest to use an output format which does not assume that all letters are the same width, like HTML.

  7. siddhpant commented on Mar 1, 2021

    @siddhpant
    Author

    I think it's just the problem of calculating visible length and formatting properly, probably the wcwidth devs would look into it better. HTML is not an option for me, so I use codeblocks to format it on the UX side (and also internally for docs).

    Thank you for taking out your time!

  8. jquast commented on Nov 13, 2023

    @jquast
    Contributor

    This is resolved in the latest releases of wcwidth, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions