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 2d3b036..4862bc2 100644 --- a/src/Text/Layout/Table.hs +++ b/src/Text/Layout/Table.hs @@ -254,14 +254,14 @@ tableLines specs TableStyle { .. } header rowGroups = -- Vertical content lines rowGroupLines = maybe concat (\seps -> intercalate [seps]) optGroupSepLine linesPerRowGroup linesPerRowGroup = map rowGroupToLines rowGroups - rowGroupToLines = map (horizontalContentLine groupV) . applyRowMods . rows + rowGroupToLines = map (horizontalContentLine groupL groupC groupR) . applyRowMods . rows -- Optional values for the header (addHeaderLines, fitHeaderIntoCMIs, realTopH, realTopL, realTopC, realTopR) = case header of HeaderHS headerColSpecs hTitles -> - let headerLine = horizontalContentLine headerV (zipWith ($) headerRowMods hTitles) + let headerLine = horizontalContentLine headerL headerC headerR (zipWith ($) headerRowMods hTitles) headerRowMods = zipWith3 headerCellModifier headerColSpecs cMSs diff --git a/src/Text/Layout/Table/Primitives/Table.hs b/src/Text/Layout/Table/Primitives/Table.hs index d91046b..9b9cef0 100644 --- a/src/Text/Layout/Table/Primitives/Table.hs +++ b/src/Text/Layout/Table/Primitives/Table.hs @@ -41,20 +41,12 @@ horizontalDetailLine horizontalDetailLine hSpace delimL delimM delimR cells = mconcat . intersperse (stringB hSpace) $ stringB delimL : intersperse (stringB delimM) cells ++ [stringB delimR] --- | A simplified version of 'hLineDetail' that will use the same delimiter --- for everything. -hLine - :: StringBuilder b - => String -- ^ The space characters that are used as padding. - -> String -- ^ The delimiter that is used for everything. - -> Row b -- ^ A row of builders. - -> b -- ^ The formatted line as a 'StringBuilder'. -hLine hSpace delim = horizontalDetailLine hSpace delim delim delim - -- | Render a line with actual content. horizontalContentLine :: StringBuilder b - => String -- ^ The delimiter that is used for everything. + => String -- ^ The delimiter that is used on the left side. + -> String -- ^ The delimeter that is used in between cells. + -> String -- ^ The delimeter that is used on the right side. -> Row b -- ^ A row of builders. -> b -horizontalContentLine = hLine " " +horizontalContentLine = horizontalDetailLine " " diff --git a/src/Text/Layout/Table/Style.hs b/src/Text/Layout/Table/Style.hs index 09970f9..0913eab 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,32 @@ data TableStyle = TableStyle , groupBottomH :: String } +-- | Remove the top, bottom, left, and right borders from a 'TableStyle'. +withoutBorders :: TableStyle -> TableStyle +withoutBorders = withoutTopBorder . withoutBottomBorder . withoutLeftBorder . withoutRightBorder + +-- | Remove the top border from a 'TableStyle'. +withoutTopBorder :: TableStyle -> TableStyle +withoutTopBorder ts = ts { headerTopL = "", headerTopR = "", headerTopC = "", headerTopH = "" + , groupTopL = "", groupTopR = "", groupTopC = "", groupTopH = "" + } + +-- | Remove the bottom border from a 'TableStyle'. +withoutBottomBorder :: TableStyle -> TableStyle +withoutBottomBorder ts = ts { groupBottomC = "", groupBottomL = "", groupBottomR = "", groupBottomH = "" } + +-- | Remove the left border from a 'TableStyle'. +withoutLeftBorder :: TableStyle -> TableStyle +withoutLeftBorder ts = ts { headerTopL = "", headerSepLC = "", headerL = "" + , groupL = "", groupSepLC = "", groupTopL = "", groupBottomL = "" + } + +-- | Remove the right border from a 'TableStyle'. +withoutRightBorder :: TableStyle -> TableStyle +withoutRightBorder ts = ts { headerTopR = "", headerSepRC = "", headerR = "" + , groupR = "", groupSepRC = "", groupTopR = "", groupBottomR = "" + } + -- | My usual ASCII table style. asciiRoundS :: TableStyle asciiRoundS = TableStyle @@ -40,8 +70,12 @@ asciiRoundS = TableStyle , headerTopR = "." , headerTopC = "." , headerTopH = "-" - , headerV = "|" - , groupV = "|" + , headerL = "|" + , headerR = "|" + , headerC = "|" + , groupL = "|" + , groupR = "|" + , groupC = "|" , groupSepH = "-" , groupSepC = "+" , groupSepLC = ":" @@ -67,8 +101,12 @@ asciiS = TableStyle , headerTopR = "+" , headerTopC = "+" , headerTopH = "-" - , headerV = "|" - , groupV = "|" + , headerL = "|" + , headerR = "|" + , headerC = "|" + , groupL = "|" + , groupR = "|" + , groupC = "|" , groupSepH = "-" , groupSepC = "+" , groupSepLC = "+" @@ -94,8 +132,12 @@ asciiDoubleS = TableStyle , headerTopR = "++" , headerTopC = "++" , headerTopH = "-" - , headerV = "||" - , groupV = "||" + , headerL = "||" + , headerR = "||" + , headerC = "||" + , groupL = "||" + , groupR = "||" + , groupC = "||" , groupSepH = "-" , groupSepC = "++" , groupSepLC = "++" @@ -121,8 +163,12 @@ unicodeS = TableStyle , headerTopR = "┐" , headerTopC = "┬" , headerTopH = "─" - , headerV = "│" - , groupV = "│" + , headerL = "│" + , headerR = "│" + , headerC = "│" + , groupL = "│" + , groupR = "│" + , groupC = "│" , groupSepH = "─" , groupSepC = "┼" , groupSepLC = "├" @@ -148,7 +194,9 @@ unicodeBoldHeaderS = unicodeS , headerTopR = "┓" , headerTopC = "┳" , headerTopH = "━" - , headerV = "┃" + , headerL = "┃" + , headerR = "┃" + , headerC = "┃" } -- | Same as 'unicodeS' but uses round edges. @@ -178,8 +226,12 @@ unicodeBoldS = TableStyle , headerTopR = "┓" , headerTopC = "┳" , headerTopH = "━" - , headerV = "┃" - , groupV = "┃" + , headerL = "┃" + , headerR = "┃" + , headerC = "┃" + , groupL = "┃" + , groupR = "┃" + , groupC = "┃" , groupSepH = "━" , groupSepC = "╋" , groupSepLC = "┣" @@ -209,8 +261,12 @@ unicodeDoubleFrameS = TableStyle , headerTopR = "╗" , headerTopC = "╦" , headerTopH = "═" - , headerV = "║" - , groupV = "║" + , headerL = "║" + , headerR = "║" + , headerC = "║" + , groupL = "║" + , groupR = "║" + , groupC = "║" , groupSepH = "═" , groupSepC = "╬" , groupSepLC = "╠"