vdmeer/asciitable

AsciiTable does not respect newlines as elements

Opened this issue · 1 comments

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││
│   │└────────┴────────┘│
└───┴───────────────────┘

same problem here.