safe-coloured-text-layout 0.0.0.0 → 0.1.0.0
raw patch · 11 files changed
+80/−18 lines, 11 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Text.Colour.Layout: backgroundForRow :: Int -> Maybe TableBackground -> Maybe Colour
- Text.Colour.Layout: iterateLikeInPython :: (Int -> a -> b) -> [a] -> [b]
- Text.Colour.Layout: padRows :: [[Chunk]] -> [[Chunk]]
- Text.Colour.Layout: paddingChunk :: Int -> Char -> Chunk
- Text.Colour.Layout: possiblyAddBackground :: Maybe Colour -> Chunk -> Chunk
Files
- CHANGELOG.md +8/−0
- LICENSE +1/−1
- safe-coloured-text-layout.cabal +10/−2
- src/Text/Colour/Layout.hs +18/−3
- test/Text/Colour/LayoutSpec.hs +12/−12
- test_resources/background.dat +5/−0
- test_resources/bicolour-background.dat +5/−0
- test_resources/custom-column-separator.dat +10/−0
- test_resources/list.dat +4/−0
- test_resources/table-with-rows-of-unequal-length.dat +3/−0
- test_resources/two-columns.dat +4/−0
+ CHANGELOG.md view
@@ -0,0 +1,8 @@+# Changelog for safe-coloured-text-layout++## [0.1.0.0] - 2024-03-26++### Changed++* Only export the intended API+* Document the API
LICENSE view
@@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Tom Sydney Kerckhove+Copyright (c) 2021-2024 Tom Sydney Kerckhove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
safe-coloured-text-layout.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.4.+-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack name: safe-coloured-text-layout-version: 0.0.0.0+version: 0.1.0.0 synopsis: Safely layout output coloured text category: User Interfaces homepage: https://github.com/NorfairKing/safe-coloured-text#readme@@ -16,6 +16,14 @@ license: MIT license-file: LICENSE build-type: Simple+extra-source-files:+ CHANGELOG.md+ test_resources/background.dat+ test_resources/bicolour-background.dat+ test_resources/custom-column-separator.dat+ test_resources/list.dat+ test_resources/table-with-rows-of-unequal-length.dat+ test_resources/two-columns.dat source-repository head type: git
src/Text/Colour/Layout.hs view
@@ -2,7 +2,14 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -module Text.Colour.Layout where+module Text.Colour.Layout+ ( layoutAsTable,+ table,+ Table (..),+ TableBackground (..),+ renderTable,+ )+where import Control.Applicative import Data.List@@ -11,9 +18,13 @@ import GHC.Generics (Generic) import Text.Colour +-- | Render as a default-settings table. layoutAsTable :: [[Chunk]] -> [Chunk] layoutAsTable = renderTable . table +-- | Make a table with default settings+--+-- You can then update table settings by changing the fields in the resulting 'Table'. table :: [[Chunk]] -> Table table cs = Table@@ -22,6 +33,7 @@ tableBackground = Nothing } +-- | Table with separator and background settings data Table = Table { -- | A list of rows. They must be of the same length. tableCells :: [[Chunk]],@@ -35,12 +47,15 @@ data TableBackground = SingleColour Colour | Bicolour- (Maybe Colour) -- Even-numbered table rows (0-indexed)- (Maybe Colour) -- Odd-numbered table rows+ (Maybe Colour)+ -- ^ Even-numbered table rows (0-indexed)+ (Maybe Colour)+ -- ^ Odd-numbered table rows deriving (Show, Eq, Generic) instance Validity TableBackground +-- | Render a table to chunks that can be rendered to text. renderTable :: Table -> [Chunk] renderTable Table {..} = let asColumns = transpose (padRows tableCells)
test/Text/Colour/LayoutSpec.hs view
@@ -12,9 +12,9 @@ let gf = ("test_resources/" ++) describe "layoutAsTable" $ do it "outputs this list the same as before" $ do- pureGoldenByteStringFile+ pureGoldenTextFile (gf "list.dat")- ( renderChunksBS+ ( renderChunksText With24BitColours ( layoutAsTable [ ["this"],@@ -25,9 +25,9 @@ ) ) it "outputs this two-column table the same as before" $ do- pureGoldenByteStringFile+ pureGoldenTextFile (gf "two-columns.dat")- ( renderChunksBS+ ( renderChunksText With24BitColours ( layoutAsTable [ ["this", "this"],@@ -38,9 +38,9 @@ ) ) it "outputs this weird two-column table the same as before" $ do- pureGoldenByteStringFile+ pureGoldenTextFile (gf "table-with-rows-of-unequal-length.dat")- ( renderChunksBS+ ( renderChunksText With24BitColours ( layoutAsTable [ ["what", "the", ""],@@ -50,9 +50,9 @@ ) ) it "outputs this two-column table with a custom column separator the same as before" $ do- pureGoldenByteStringFile+ pureGoldenTextFile (gf "custom-column-separator.dat")- ( renderChunksBS+ ( renderChunksText With24BitColours ( renderTable $ ( table $ [[chunk (T.pack (show (x + y))) | x <- [0 :: Int .. 9]] | y <- [0 :: Int .. 9]]@@ -62,9 +62,9 @@ ) ) it "outputs this table with a background colour the same as before" $ do- pureGoldenByteStringFile+ pureGoldenTextFile (gf "background.dat")- ( renderChunksBS+ ( renderChunksText With24BitColours ( renderTable $ ( table $ [[fore red $ chunk (T.pack (show (x ^ y))) | x <- [0 :: Int .. 4]] | y <- [0 :: Int .. 4]]@@ -74,9 +74,9 @@ ) ) it "outputs this table with a bicoloured background the same as before" $ do- pureGoldenByteStringFile+ pureGoldenTextFile (gf "bicolour-background.dat")- ( renderChunksBS+ ( renderChunksText With24BitColours ( renderTable $ ( table $ [[fore red $ chunk (T.pack (show (x ^ y))) | x <- [0 :: Int .. 4]] | y <- [0 :: Int .. 4]]
+ test_resources/background.dat view
@@ -0,0 +1,5 @@+[31;40m1[m[40m[m[40m [m[31;40m1[m[40m[m[40m [m[31;40m1[m[40m [m[40m [m[31;40m1[m[40m [m[40m [m[31;40m1[m[40m [m+[31;40m0[m[40m[m[40m [m[31;40m1[m[40m[m[40m [m[31;40m2[m[40m [m[40m [m[31;40m3[m[40m [m[40m [m[31;40m4[m[40m [m+[31;40m0[m[40m[m[40m [m[31;40m1[m[40m[m[40m [m[31;40m4[m[40m [m[40m [m[31;40m9[m[40m [m[40m [m[31;40m16[m[40m [m+[31;40m0[m[40m[m[40m [m[31;40m1[m[40m[m[40m [m[31;40m8[m[40m [m[40m [m[31;40m27[m[40m[m[40m [m[31;40m64[m[40m [m+[31;40m0[m[40m[m[40m [m[31;40m1[m[40m[m[40m [m[31;40m16[m[40m[m[40m [m[31;40m81[m[40m[m[40m [m[31;40m256[m[40m[m
+ test_resources/bicolour-background.dat view
@@ -0,0 +1,5 @@+[31;40m1[m[40m[m[40m [m[31;40m1[m[40m[m[40m [m[31;40m1[m[40m [m[40m [m[31;40m1[m[40m [m[40m [m[31;40m1[m[40m [m+[31;100m0[m[100m[m[100m [m[31;100m1[m[100m[m[100m [m[31;100m2[m[100m [m[100m [m[31;100m3[m[100m [m[100m [m[31;100m4[m[100m [m+[31;40m0[m[40m[m[40m [m[31;40m1[m[40m[m[40m [m[31;40m4[m[40m [m[40m [m[31;40m9[m[40m [m[40m [m[31;40m16[m[40m [m+[31;100m0[m[100m[m[100m [m[31;100m1[m[100m[m[100m [m[31;100m8[m[100m [m[100m [m[31;100m27[m[100m[m[100m [m[31;100m64[m[100m [m+[31;40m0[m[40m[m[40m [m[31;40m1[m[40m[m[40m [m[31;40m16[m[40m[m[40m [m[31;40m81[m[40m[m[40m [m[31;40m256[m[40m[m
+ test_resources/custom-column-separator.dat view
@@ -0,0 +1,10 @@+0@1 @2 @3 @4 @5 @6 @7 @8 @9 +1@2 @3 @4 @5 @6 @7 @8 @9 @10+2@3 @4 @5 @6 @7 @8 @9 @10@11+3@4 @5 @6 @7 @8 @9 @10@11@12+4@5 @6 @7 @8 @9 @10@11@12@13+5@6 @7 @8 @9 @10@11@12@13@14+6@7 @8 @9 @10@11@12@13@14@15+7@8 @9 @10@11@12@13@14@15@16+8@9 @10@11@12@13@14@15@16@17+9@10@11@12@13@14@15@16@17@18
+ test_resources/list.dat view
@@ -0,0 +1,4 @@+this+is +a +list
+ test_resources/table-with-rows-of-unequal-length.dat view
@@ -0,0 +1,3 @@+what the +is this -ing +I don't understand one of it
+ test_resources/two-columns.dat view
@@ -0,0 +1,4 @@+this this +is is +a another+list list