Skip to content

Commit

Permalink
Allow removing outer borders from TableStyles.
Browse files Browse the repository at this point in the history
In TableStyle, split vertical separators into left, centre, and right variants.

groupV -> groupL, groupC, and groupR
headerV -> headerL, headerC, and headerR
  • Loading branch information
Xitian9 committed Sep 4, 2021
1 parent 3197bba commit c34f56d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ main = putStrLn $ tableString [ column (expandUntil 30) left (charAlign ':') def
, asciiDoubleS
, asciiRoundS
, unicodeS
, withoutBorders unicodeS
, unicodeRoundS
, unicodeBoldS
, unicodeBoldStripedS
Expand Down
4 changes: 2 additions & 2 deletions src/Text/Layout/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ tableLines specs TableStyle { .. } header rowGroups =
-- Vertical content lines
rowGroupLines =
(if hasGroupSep then intercalate [groupSepLine] else concat)
$ map (map (hLineContent groupV) . applyRowMods . rows) rowGroups
$ map (map (fst . hLineDetail " " groupL groupC groupR) . applyRowMods . rows) rowGroups

-- Optional values for the header
(addHeaderLines, fitHeaderIntoCMIs, realTopH, realTopL, realTopC, realTopR)
= case header of
HeaderHS headerColSpecs hTitles
->
let headerLine = hLineContent headerV (zipWith ($) headerRowMods hTitles)
let headerLine = fst . hLineDetail " " headerL headerC headerR $ zipWith ($) headerRowMods hTitles
headerRowMods = zipWith3 headerCellModifier
headerColSpecs
cMSs
Expand Down
85 changes: 70 additions & 15 deletions src/Text/Layout/Table/Style.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ data TableStyle = TableStyle
, headerTopR :: String
, headerTopC :: String
, headerTopH :: String
, headerV :: String
, groupV :: String
, headerL :: String
, headerR :: String
, headerC :: String
, groupL :: String
, groupR :: String
, groupC :: String
, groupSepH :: String
, groupSepC :: String
, groupSepLC :: String
Expand All @@ -29,6 +33,31 @@ data TableStyle = TableStyle
, groupBottomH :: String
}

-- | Remove the outer borders from a style.
withoutBorders :: TableStyle -> TableStyle
withoutBorders tstyle = tstyle
{ headerSepLC = ""
, headerSepRC = ""
, headerTopL = ""
, headerTopR = ""
, headerTopC = ""
, headerTopH = ""
, headerL = ""
, headerR = ""
, groupL = ""
, groupR = ""
, groupSepLC = ""
, groupSepRC = ""
, groupTopC = ""
, groupTopL = ""
, groupTopR = ""
, groupTopH = ""
, groupBottomC = ""
, groupBottomL = ""
, groupBottomR = ""
, groupBottomH = ""
}

-- | My usual ASCII table style.
asciiRoundS :: TableStyle
asciiRoundS = TableStyle
Expand All @@ -40,8 +69,12 @@ asciiRoundS = TableStyle
, headerTopR = "."
, headerTopC = "."
, headerTopH = "-"
, headerV = "|"
, groupV = "|"
, headerL = "|"
, headerR = "|"
, headerC = "|"
, groupL = "|"
, groupR = "|"
, groupC = "|"
, groupSepH = "-"
, groupSepC = "+"
, groupSepLC = ":"
Expand All @@ -67,8 +100,12 @@ asciiS = TableStyle
, headerTopR = "+"
, headerTopC = "+"
, headerTopH = "-"
, headerV = "|"
, groupV = "|"
, headerL = "|"
, headerR = "|"
, headerC = "|"
, groupL = "|"
, groupR = "|"
, groupC = "|"
, groupSepH = "-"
, groupSepC = "+"
, groupSepLC = "+"
Expand All @@ -94,8 +131,12 @@ asciiDoubleS = TableStyle
, headerTopR = "++"
, headerTopC = "++"
, headerTopH = "-"
, headerV = "||"
, groupV = "||"
, headerL = "||"
, headerR = "||"
, headerC = "||"
, groupL = "||"
, groupR = "||"
, groupC = "||"
, groupSepH = "-"
, groupSepC = "++"
, groupSepLC = "++"
Expand All @@ -121,8 +162,12 @@ unicodeS = TableStyle
, headerTopR = ""
, headerTopC = ""
, headerTopH = ""
, headerV = ""
, groupV = ""
, headerL = ""
, headerR = ""
, headerC = ""
, groupL = ""
, groupR = ""
, groupC = ""
, groupSepH = ""
, groupSepC = ""
, groupSepLC = ""
Expand All @@ -148,7 +193,9 @@ unicodeBoldHeaderS = unicodeS
, headerTopR = ""
, headerTopC = ""
, headerTopH = ""
, headerV = ""
, headerL = ""
, headerR = ""
, headerC = ""
}

-- | Same as 'unicodeS' but uses round edges.
Expand Down Expand Up @@ -178,8 +225,12 @@ unicodeBoldS = TableStyle
, headerTopR = ""
, headerTopC = ""
, headerTopH = ""
, headerV = ""
, groupV = ""
, headerL = ""
, headerR = ""
, headerC = ""
, groupL = ""
, groupR = ""
, groupC = ""
, groupSepH = ""
, groupSepC = ""
, groupSepLC = ""
Expand Down Expand Up @@ -209,8 +260,12 @@ unicodeDoubleFrameS = TableStyle
, headerTopR = ""
, headerTopC = ""
, headerTopH = ""
, headerV = ""
, groupV = ""
, headerL = ""
, headerR = ""
, headerC = ""
, groupL = ""
, groupR = ""
, groupC = ""
, groupSepH = ""
, groupSepC = ""
, groupSepLC = ""
Expand Down

0 comments on commit c34f56d

Please sign in to comment.