From c34f56d62f4b367546ff6fb6cd80f6afebfdd99b Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Sat, 4 Sep 2021 18:54:02 +1000 Subject: [PATCH] Allow removing outer borders from TableStyles. In TableStyle, split vertical separators into left, centre, and right variants. groupV -> groupL, groupC, and groupR headerV -> headerL, headerC, and headerR --- src/Test.hs | 1 + src/Text/Layout/Table.hs | 4 +- src/Text/Layout/Table/Style.hs | 85 ++++++++++++++++++++++++++++------ 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/src/Test.hs b/src/Test.hs index 299629f..accfb01 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -30,6 +30,7 @@ main = putStrLn $ tableString [ column (expandUntil 30) left (charAlign ':') def , asciiDoubleS , asciiRoundS , unicodeS + , withoutBorders unicodeS , unicodeRoundS , unicodeBoldS , unicodeBoldStripedS diff --git a/src/Text/Layout/Table.hs b/src/Text/Layout/Table.hs index c956ebf..1ef8bc4 100644 --- a/src/Text/Layout/Table.hs +++ b/src/Text/Layout/Table.hs @@ -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 diff --git a/src/Text/Layout/Table/Style.hs b/src/Text/Layout/Table/Style.hs index 30638c1..fc2fca9 100644 --- a/src/Text/Layout/Table/Style.hs +++ b/src/Text/Layout/Table/Style.hs @@ -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 @@ -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 @@ -40,8 +69,12 @@ asciiRoundS = TableStyle , headerTopR = "." , headerTopC = "." , headerTopH = "-" - , headerV = "|" - , groupV = "|" + , headerL = "|" + , headerR = "|" + , headerC = "|" + , groupL = "|" + , groupR = "|" + , groupC = "|" , groupSepH = "-" , groupSepC = "+" , groupSepLC = ":" @@ -67,8 +100,12 @@ asciiS = TableStyle , headerTopR = "+" , headerTopC = "+" , headerTopH = "-" - , headerV = "|" - , groupV = "|" + , headerL = "|" + , headerR = "|" + , headerC = "|" + , groupL = "|" + , groupR = "|" + , groupC = "|" , groupSepH = "-" , groupSepC = "+" , groupSepLC = "+" @@ -94,8 +131,12 @@ asciiDoubleS = TableStyle , headerTopR = "++" , headerTopC = "++" , headerTopH = "-" - , headerV = "||" - , groupV = "||" + , headerL = "||" + , headerR = "||" + , headerC = "||" + , groupL = "||" + , groupR = "||" + , groupC = "||" , groupSepH = "-" , groupSepC = "++" , groupSepLC = "++" @@ -121,8 +162,12 @@ unicodeS = TableStyle , headerTopR = "┐" , headerTopC = "┬" , headerTopH = "─" - , headerV = "│" - , groupV = "│" + , headerL = "│" + , headerR = "│" + , headerC = "│" + , groupL = "│" + , groupR = "│" + , groupC = "│" , groupSepH = "─" , groupSepC = "┼" , groupSepLC = "├" @@ -148,7 +193,9 @@ unicodeBoldHeaderS = unicodeS , headerTopR = "┓" , headerTopC = "┳" , headerTopH = "━" - , headerV = "┃" + , headerL = "┃" + , headerR = "┃" + , headerC = "┃" } -- | Same as 'unicodeS' but uses round edges. @@ -178,8 +225,12 @@ unicodeBoldS = TableStyle , headerTopR = "┓" , headerTopC = "┳" , headerTopH = "━" - , headerV = "┃" - , groupV = "┃" + , headerL = "┃" + , headerR = "┃" + , headerC = "┃" + , groupL = "┃" + , groupR = "┃" + , groupC = "┃" , groupSepH = "━" , groupSepC = "╋" , groupSepLC = "┣" @@ -209,8 +260,12 @@ unicodeDoubleFrameS = TableStyle , headerTopR = "╗" , headerTopC = "╦" , headerTopH = "═" - , headerV = "║" - , groupV = "║" + , headerL = "║" + , headerR = "║" + , headerC = "║" + , groupL = "║" + , groupR = "║" + , groupC = "║" , groupSepH = "═" , groupSepC = "╬" , groupSepLC = "╠"