packages feed

xformat 0.1 → 0.1.1

raw patch · 3 files changed

+28/−16 lines, 3 files

Files

src/Text/XFormat/Read.hs view
@@ -74,6 +74,7 @@  -------------------------------------------------------------------------------- +import Control.Applicative ((<$>)) import Text.ParserCombinators.ReadP import Data.Char (isSpace) @@ -289,7 +290,7 @@ data ChoiceF a = Choice [a]  instance (Format d a) => Format (ChoiceF d) a where-  readpf (Choice ds) = choice (fmap readpf ds)+  readpf (Choice ds) = choice (readpf <$> ds)  -- | Parse one of two formats in a fully symmetric choice. @@ -297,7 +298,7 @@  instance (Format d1 a1, Format d2 a2) => Format (EitherF d1 d2) (Either a1 a2) where   readpf (Either d1 d2) =-    (readpf d1 >>= return . Left) +++ (readpf d2 >>= return . Right)+    (Left <$> readpf d1) +++ (Right <$> readpf d2)  -- | Parse one of two formats, trying the left one first. @@ -305,7 +306,7 @@  instance (Format d1 a1, Format d2 a2) => Format (EitherLF d1 d2) (Either a1 a2) where   readpf (EitherL d1 d2) =-    (readpf d1 >>= return . Left) <++ (readpf d2 >>= return . Right)+    (Left <$> readpf d1) <++ (Right <$> readpf d2)  -------------------------------------------------------------------------------- 
src/Text/XFormat/Show.hs view
@@ -64,6 +64,7 @@    WrapF(..),   AlignF(..),+  AlignChopF(..),   Dir(..),    -- ** Other Format Descriptors@@ -273,7 +274,7 @@  data NumF a = Num -instance (Num a) => Format (NumF a) (Arr a) where+instance (Num a, Show a) => Format (NumF a) (Arr a) where   showsf' Num = Arr shows  --------------------------------------------------------------------------------@@ -327,21 +328,31 @@  data AlignF a = Align Dir Int a --- | Direction (left or right) used for 'AlignF'.+-- | Same as 'AlignF' but chop off the output if it extends past the column+-- width. +data AlignChopF a = AlignChop Dir Int a++-- | Direction (left or right) used for 'AlignF' and 'AlignChopF'.+ data Dir = L | R -align :: Dir -> Int -> ShowS -> ShowS-align dir wid f =+align :: Bool -> Dir -> Int -> ShowS -> ShowS+align doChop dir wid input =   case dir of-    L -> f . g-    R -> g . f+    L -> chop (take wid)         . input . addSpaces+    R -> chop (drop (len - wid)) . addSpaces . input   where-    len = length (f "")-    g = if len < wid then showString (replicate (wid - len) ' ') else id+    len = length (input "")+    spaces = replicate (wid - len) ' '+    chop act = if doChop && len > wid then act else id+    addSpaces = if len < wid then showString spaces else id  instance (Format d f) => Format (AlignF d) f where-  showsf' (Align dir wid d) = fmap (align dir wid) (showsf' d)+  showsf' (Align dir wid d) = fmap (align False dir wid) (showsf' d)++instance (Format d f) => Format (AlignChopF d) f where+  showsf' (AlignChop dir wid d) = fmap (align True dir wid) (showsf' d)  -------------------------------------------------------------------------------- 
xformat.cabal view
@@ -1,10 +1,10 @@ name:                   xformat-version:                0.1+version:                0.1.1 synopsis:    Extensible, type-safe formatting with scanf- and printf-like functions -homepage:               http://github.com/spl/xformat/tree/master+homepage:               http://github.com/spl/xformat description:    /Warning:/ This version of the package is very experimental and the interface@@ -33,12 +33,12 @@ copyright:              (c) 2009 Sean Leather license:                BSD3 license-file:           LICENSE-author:                 Sean Leather,+author:                 Sean Leather maintainer:             leather@cs.uu.nl stability:              experimental build-type:             Custom cabal-version:          >= 1.2.1-tested-with:            GHC == 6.8.3, GHC == 6.10.1+tested-with:            GHC == 6.8.3, GHC == 6.10.1, GHC == 7.4.1  --------------------------------------------------------------------------------