mordant icon indicating copy to clipboard operation
mordant copied to clipboard

A grid with a single column and fixed width n only hold n-1 characters

Open bkahlert opened this issue 2 years ago • 3 comments

The following code should render a grid with a single cell (fixed 80 width) and its content of 80 1-width characters in a single line.

Terminal().render(
                    grid {
                        cellBorders = NONE
                        padding(0, 0, 0, 0)
                        column(0) {
                            width = ColumnWidth.Fixed(80)
                        }
                        row {
                            whitespace = PRE_LINE
                            verticalAlign = TOP
                            overflowWrap = BREAK_WORD
                            cell("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod.")
                        }
                    }
                )

Expected

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod.

Actual

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod.

Removing one character from the content string makes the grid widget consume only a single line.

bkahlert avatar Jul 20 '22 20:07 bkahlert

Here's the state of the grid widget; I suppose it might have something to do with the single spaces in the borderStyle property.

{
    tableBorders: NONE,
    rows: [
              [
                  Content(content=Text(Lorem ipsum dolor sit ame…), rowSpan=1, columnSpan=1, borderLeft=false, borderTop=false, borderRight=false, borderBottom=false, style=null, textAlign=LEFT, verticalAlign=TOP)
              ]
          ],
    rowBorders: [
                    false,
                    false
                ],
    headerRowCount: 0x00,
    footerRowCount: 0x00,
    expand: false,
    columnStyles: {
                      0x00: {
                                width: 0x50
                            }
                  },
    columnCount: 0x01,
    columnBorders: <List@40545>,
    borderWidth: 0x00,
    borderType: {
                    headBottom: {
                                    w: " ",
                                    sw: " ",
                                    s: " ",
                                    nw: " ",
                                    nsw: " ",
                                    ns: " ",
                                    new: " ",
                                    nesw: " ",
                                    nes: " ",
                                    ne: " ",
                                    n: " ",
                                    ew: " ",
                                    esw: " ",
                                    es: " ",
                                    e: " ",
                                    array: [
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " "
                                           ]
                                },
                    head: {
                              w: " ",
                              sw: " ",
                              s: " ",
                              nw: " ",
                              nsw: " ",
                              ns: " ",
                              new: " ",
                              nesw: " ",
                              nes: " ",
                              ne: " ",
                              n: " ",
                              ew: " ",
                              esw: " ",
                              es: " ",
                              e: " ",
                              array: [
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " "
                                     ]
                          },
                    foot: {
                              w: " ",
                              sw: " ",
                              s: " ",
                              nw: " ",
                              nsw: " ",
                              ns: " ",
                              new: " ",
                              nesw: " ",
                              nes: " ",
                              ne: " ",
                              n: " ",
                              ew: " ",
                              esw: " ",
                              es: " ",
                              e: " ",
                              array: [
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " "
                                     ]
                          },
                    bodyBottom: {
                                    w: " ",
                                    sw: " ",
                                    s: " ",
                                    nw: " ",
                                    nsw: " ",
                                    ns: " ",
                                    new: " ",
                                    nesw: " ",
                                    nes: " ",
                                    ne: " ",
                                    n: " ",
                                    ew: " ",
                                    esw: " ",
                                    es: " ",
                                    e: " ",
                                    array: [
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " ",
                                               " "
                                           ]
                                },
                    body: {
                              w: " ",
                              sw: " ",
                              s: " ",
                              nw: " ",
                              nsw: " ",
                              ns: " ",
                              new: " ",
                              nesw: " ",
                              nes: " ",
                              ne: " ",
                              n: " ",
                              ew: " ",
                              esw: " ",
                              es: " ",
                              e: " ",
                              array: [
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " ",
                                         " "
                                     ]
                          }
                },
    borderStyle: TxtStyle(color=null, bgColor=null, bold=false, italic=false, underline=false, dim=false, inverse=false, strikethrough=false, hyperlink=null, hyperlinkId=null)
}

bkahlert avatar Jul 20 '22 20:07 bkahlert

Thanks for the report! I don't think there's any problem with grid. If you're running on JVM, mordant doesn't automatically detect terminal width at startup, since it requires a subprocess call. So it's wrapping because the default terminal width it 79 characters.

You can call terminal.info.updateTerminalSize() to detect the size, or set it manually when you create the terminal: Terminal(width=120). On native and js, the detection is a sys call, so we do it automatically.

Let me know if that fixes the problem.

ajalt avatar Jul 21 '22 02:07 ajalt

I added the terminal.info.updateTerminalSize() call but stty size seems to exit with -1. I would have to look it up myself but could it be that you need to inherit the environment or use the absolute path to call stty? Running the command in my IntelliJ terminal outputs 25 368.

bkahlert avatar Jul 21 '22 08:07 bkahlert