tabl 0.1.0.0 → 1.0.1
raw patch · 6 files changed
+130/−4 lines, 6 filesdep +randomdep +splitdep +tabldep ~basenew-component:exe:tabl-example-constantsnew-component:exe:tabl-example-multiplynew-component:exe:tabl-example-tictactoenew-component:exe:tabl-example-users
Dependencies added: random, split, tabl, unix
Dependency ranges changed: base
Files
- examples/Constants.hs +17/−0
- examples/Multiply.hs +28/−0
- examples/TicTacToe.hs +22/−0
- examples/Users.hs +22/−0
- src/Text/Tabl/Ascii.hs +4/−3
- tabl.cabal +37/−1
+ examples/Constants.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE OverloadedStrings #-}++import Text.Tabl++import qualified Data.Text.IO as T++-- | Table containing few physics constants.+main :: IO ()+main = T.putStrLn $ tabl EnvAscii hdecor vdecor aligns cells + where+ hdecor = DecorUnion [DecorOuter, DecorOnly [1]]+ vdecor = DecorAll+ aligns = [AlignLeft, AlignLeft, AlignRight]+ cells = [ ["Name", "SI Unit", "Value"]+ , ["Speed of light", "m/s", "299792458"]+ , ["Atmosphere", "Pa", "101325"]+ , ["Absolute zero", "C", "-273.15"] ]
+ examples/Multiply.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE OverloadedStrings #-}++import System.Environment+import Text.Tabl++import qualified Data.Text as T+import qualified Data.Text.IO as T++-- | Create the multiplication table.+numbers :: Int -- ^ table side size+ -> [[T.Text]] -- ^ multiplication table+numbers n = header : zipWith (:) digits content+ where+ header = " " : digits+ digits = map (T.pack . show) [1..n]+ content = map (map (T.pack . show)) mults+ mults = map (flip map [1..n] . (*)) [1..n]++-- | Table containing basic integer products.+main :: IO ()+main = do+ [n] <- getArgs+ let cells = numbers (read n)+ T.putStrLn $ tabl EnvAscii hdecor vdecor aligns cells+ where+ hdecor = DecorOnly [1]+ vdecor = DecorOnly [1]+ aligns = repeat AlignRight
+ examples/TicTacToe.hs view
@@ -0,0 +1,22 @@+{-# LANGUAGE OverloadedStrings #-}++import Control.Monad+import Data.List.Split+import Data.Word+import Safe+import System.Random+import Text.Tabl++import qualified Data.Text.IO as T++-- | Table containing the play grid of tic-tac-toe.+main :: IO ()+main = do+ xs <- replicateM 9 randomIO :: IO [Word8]+ let cells = chunksOf 3 $ map (mark . (`mod` 3)) xs+ T.putStrLn $ tabl EnvAscii hdecor vdecor aligns cells+ where+ mark x = lookupJust x [(0, " "), (1, "X"), (2, "O")]+ hdecor = DecorAll+ vdecor = DecorAll+ aligns = []
+ examples/Users.hs view
@@ -0,0 +1,22 @@+import System.Posix.User+import Text.Tabl++import qualified Data.Text as T+import qualified Data.Text.IO as T++-- | Create a table row for one user entry.+createRow :: UserEntry -- ^ user+ -> [T.Text] -- ^ table row+createRow ue = map T.pack [show $ userID ue, userName ue, userGecos ue]++-- | Table containing all system users and their respective basic+-- information.+main :: IO ()+main = do+ users <- getAllUserEntries+ let cells = map createRow users+ T.putStrLn $ tabl EnvAscii hdecor vdecor aligns cells+ where+ hdecor = DecorNone+ vdecor = DecorNone+ aligns = [AlignRight]
src/Text/Tabl/Ascii.hs view
@@ -88,7 +88,8 @@ -> [Alignment] -- ^ column alignments -> [[T.Text]] -- ^ table cell data -> T.Text -- ^ table-ascii hpres vpres aligns cells = T.intercalate "\n" drows+ascii hpres vpres aligns cells = T.intercalate "\n" decorated where- drows = applyDecoration hpres vpres acells- acells = alignCells cells (columnWidths cells) aligns+ decorated = applyDecoration hpres vpres aligned+ aligned = alignCells escaped (columnWidths escaped) aligns+ escaped = map (map (T.replace "\n" "\\n" . T.replace "\t" "\\t")) cells
tabl.cabal view
@@ -1,5 +1,5 @@ name: tabl-version: 0.1.0.0+version: 1.0.1 synopsis: Table layout description: Text.Tabl arranges multiple Text instances into a table layout while providing means of alignment@@ -25,6 +25,42 @@ , Text.Tabl.Util build-depends: base >= 4.7 && < 5 , safe+ , text+ default-language: Haskell2010++executable tabl-example-users+ hs-source-dirs: examples+ main-is: Users.hs+ build-depends: base+ , unix+ , tabl+ , text+ default-language: Haskell2010++executable tabl-example-multiply+ hs-source-dirs: examples+ main-is: Multiply.hs+ build-depends: base+ , tabl+ , text+ default-language: Haskell2010++executable tabl-example-tictactoe+ hs-source-dirs: examples+ main-is: TicTacToe.hs+ build-depends: base+ , random+ , safe+ , split+ , tabl+ , text+ default-language: Haskell2010++executable tabl-example-constants+ hs-source-dirs: examples+ main-is: Constants.hs+ build-depends: base+ , tabl , text default-language: Haskell2010