Skip to content
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

AsciiTable does not respect newlines as elements #36

Open
Martmists-GH opened this issue Feb 3, 2021 · 1 comment
Open

AsciiTable does not respect newlines as elements #36

Martmists-GH opened this issue Feb 3, 2021 · 1 comment

Comments

@Martmists-GH
Copy link

Martmists-GH commented Feb 3, 2021

Sample code (kotlin):

    val s1 = "0 0\n0 0"
    val s2 = "1 1\n1 1"
    val s3 = "2 2\n2 2"
    val s4 = "┌─────┬─────┐\n" +
            "│3 3 3│3 3 3│\n" +
            "│3 3 3│3 3 3│\n" +
            "│3 3 3│3 3 3│\n" +
            "│3 3 3│3 3 3│\n" +
            "├─────┼─────┤\n" +
            "│3 3 3│3 3 3│\n" +
            "│3 3 3│3 3 3│\n" +
            "│3 3 3│3 3 3│\n" +
            "│3 3 3│3 3 3│\n" +
            "└─────┴─────┘"

    val at = AsciiTable()
    at.renderer.cwc = CWC_LongestLine()

    at.addRule()
    at.addRow(s1, s2)
    at.addRule()
    at.addRow(s3, s4)
    at.addRule()
    println(at.render())

Expected output:

┌───┬─────────────┐
│0 0│1 1          │
│0 0│1 1          │
├───┼─────────────┤
│2 2│┌─────┬─────┐│
│2 2││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   │├─────┼─────┤│
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   │└─────┴─────┘│
└───┴─────────────┘

Actual output:

┌───┬─────────────┐
│0 0│1 1 1 1      │
│0 0│             │
├───┼─────────────┤
│2 2│┌─────┬─────┐│
│2 2││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   │├─────┼─────┤│
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   ││3 3 3│3 3 3││
│   │└─────┴─────┘│
└───┴─────────────┘

Not setting CWC_LongestLine() results in the top left and bottom left being expanded to 0 0 0 0 and 2 2 2 2 respectively

Similarly, replacing the 3 3 3 ... with

3 4 5
6 7 8
9 10 11
12 13 14

Results in strange output too:

┌───┬───────────────────┐
│0 0│1 1 1 1            │
│0 0│                   │
├───┼───────────────────┤
│2 2│┌────────┬────────┐│
│2 2││3 4 5 6│3 4  5  6││
│   ││7 8 9 10│7 8 9 10││
│   ││11 12 13│11 12 13││
│   ││14      │14      ││
│   │├────────┼────────┤│
│   ││3 4 5 6│3 4  5  6││
│   ││7 8 9 10│7 8 9 10││
│   ││11 12 13│11 12 13││
│   ││14      │14      ││
│   │└────────┴────────┘│
└───┴───────────────────┘

Though this only happens in nested tables; Using the bottom right table alone gives "proper" output (despite 14 being on a new line):

┌────────┬────────┐
│3 4 5  6│3 4 5  6│
│7 8 9 10│7 8 9 10│
│11 12 13│11 12 13│
│14      │14      │
├────────┼────────┤
│3 4 5  6│3 4 5  6│
│7 8 9 10│7 8 9 10│
│11 12 13│11 12 13│
│14      │14      │
└────────┴────────┘

Replacing newlines with <br> does not help much:

┌───┬───────────────────┐
│0 0│1                 1│
│0 0│1 1                │
├───┼───────────────────┤
│2 2│┌────────┬────────┐│
│2 2││3  4  5│3   4   5││
│   ││6  7  8│6   7   8││
│   ││9 10 11│9  10  11││
│   ││12 13 14│12 13 14││
│   │├────────┼────────┤│
│   ││3  4  5│3   4   5││
│   ││6  7  8│6   7   8││
│   ││9 10 11│9  10  11││
│   ││12 13 14│12 13 14││
│   │└────────┴────────┘│
└───┴───────────────────┘

@CreateChance
Copy link

same problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants