muesli4 / table-layout

Layout data in grids and pretty tables. Provides a lot of tools to get the cell formatting right (positional alignment, alignment on specific characters and limiting of cell width)..
BSD 3-Clause "New" or "Revised" License
37 stars 11 forks source link

How to adjust whitespace between columns in gridString #10

Closed hasufell closed 4 years ago

hasufell commented 4 years ago
  let
    formatted =
      gridString
          [ column expand left def def
          , column expand left def def
          , column expand left def def
          , column expand left def def
          , column expand left def def
          ]
        . ([color Green "", "Tool", "Version", "Tag", "Notes"]:)
        . fmap
            (\ListResult {..} ->
              [ if
                | lSet       -> (color Green "✔✔")
                | lInstalled -> (color Green "✓")
                | otherwise  -> (color Red "✗")
              , fmap toLower . show $ lTool
              , T.unpack . prettyVer $ lVer
              , intercalate "," $ ((fmap . fmap) toLower . fmap show $ lTag)
              , if fromSrc then (color Blue "compiled") else mempty
              ]
            )
         $ lr
  putStrLn $ formatted

Trying to figure out how to make the columns a little farther from each other. Neither fixedUntil, nor expandUntil is what I'm looking for. What I'm looking for is: setting the minimum whitespace between two columns.

muesli4 commented 4 years ago

fixedUntil and expandUntil are just for the cell-internal layout. Basically, gridString will use a default of one space and one newline as horizontal and vertical separators respectively. The documentation should probably be improved here.

What you can do instead is using the grid function in combination with unlines and fmap $ concat . intercalate (replicate n ' '). These simple functions should probably be in the library.

If there is a high demand for more flexible spacing then the respective functions for grids (and perhaps tables) should also be provided.

Also in regard to colors: With the most recent version from hackage, color formatting characters are detected as printable character. The result is wrong length measurements. The bug has been fixed recently. See here on how to use it. I will probably release a new version soon™. This will introduce quite a few changes to the API and I'm still not clear about all of the details and lack the time at the moment.

muesli4 commented 4 years ago

Fixed as of f243821a3e5c5935903bb03fee1992c6109be3c2.