pretty-display (empty) → 0.1.0
raw patch · 6 files changed
+189/−0 lines, 6 filesdep +ansi-wl-pprintdep +basedep +pretty-displaysetup-changed
Dependencies added: ansi-wl-pprint, base, pretty-display, pretty-show, text
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- example/Basic.hs +31/−0
- pretty-display.cabal +45/−0
- src/Text/Display.hs +79/−0
- test/Spec.hs +2/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Justin Sermeno (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Author name here nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ example/Basic.hs view
@@ -0,0 +1,31 @@+module Main where++import Numeric++import Text.Display+import Text.PrettyPrint.ANSI.Leijen as PP++data MyRecord = MyRecord+ { numerators :: [Double]+ , denominator :: Double+ } deriving (Show)++record :: MyRecord+record = MyRecord+ { numerators = [0, 5..100]+ , denominator = 1326+ }++instance {-# OVERLAPPING #-} Display MyRecord where+ display a = mkDisplayTextStr+ $ show+ $ toCol "MyRecord (percentage): " <> toCol (displayPerc a)+ where+ displayPerc a = showFFloat (Just 2) (toPerc a) "%"+ toPerc a = sum (numerators a) / denominator a * 100+ toCol a = (PP.dullgreen . PP.fill 25 . PP.text) a++main :: IO ()+main = do+ dPrint record+ pPrint record
+ pretty-display.cabal view
@@ -0,0 +1,45 @@+name: pretty-display+version: 0.1.0+synopsis: Initial project template from stack+description: Please see README.md+homepage: https://github.com/githubuser/pretty-display#readme+license: BSD3+license-file: LICENSE+author: Author name here+maintainer: example@example.com+copyright: 2016 Author name here+category: Web+build-type: Simple+-- extra-source-files:+cabal-version: >=1.10++library+ hs-source-dirs: src+ exposed-modules: Text.Display+ build-depends: base >= 4.7 && < 5+ , text+ , pretty-show+ default-language: Haskell2010++executable pretty-display-example+ hs-source-dirs: example+ main-is: Basic.hs+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends: base+ , pretty-display+ , pretty-show+ , ansi-wl-pprint+ default-language: Haskell2010++test-suite pretty-display-test+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Spec.hs+ build-depends: base+ , pretty-display+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/githubuser/pretty-display
+ src/Text/Display.hs view
@@ -0,0 +1,79 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE UndecidableInstances #-}+module Text.Display+ ( mkDisplayText+ , unDisplayText+ , mkDt+ , unDt+ , mkDisplayTextStr+ , unDisplayTextStr+ , mkDtStr+ , unDtStr+ , dPrint++ -- * Re-exports+ , ppShow+ , pPrint++ -- * Types+ , Display(..)+ , DisplayText+ )+ where++import Data.Text (Text)+import qualified Data.Text as Text+import qualified Data.Text.IO as TextIO++import Text.Show.Pretty as Pretty++newtype DisplayText = DisplayText { _fromDisplayText :: Text } deriving (Eq)++instance Show DisplayText where+ show displayText = Text.unpack (unDisplayText displayText)++class Display a where+ display :: a -> DisplayText++instance {-# Overlappable #-} (Show a) => Display a where+ display a = (DisplayText . Text.pack . Pretty.ppShow) a++-- | Wrap 'Text' into a 'DisplayText'.+mkDisplayText :: Text -> DisplayText+mkDisplayText a = DisplayText a++-- | Alias for 'mkDt'+mkDt :: Text -> DisplayText+mkDt = mkDisplayText++-- | Unwrap 'DisplayText' to a 'Text'.+unDisplayText :: DisplayText -> Text+unDisplayText a = _fromDisplayText a++-- | Alias for 'unDisplayText'+unDt :: DisplayText -> Text+unDt = unDisplayText++-- | Wrap 'String' into a 'DisplayText'.+mkDisplayTextStr :: String -> DisplayText+mkDisplayTextStr a = mkDisplayText (Text.pack a)++-- | Alias for 'mkDisplayTextStr'+mkDtStr :: String -> DisplayText+mkDtStr = mkDisplayTextStr++-- | Unwrap 'DisplayText' to a 'String'.+unDisplayTextStr :: DisplayText -> String+unDisplayTextStr a = Text.unpack (unDisplayText a)++-- | Alias for 'unDisplayTextStr'+unDtStr :: DisplayText -> String+unDtStr = unDisplayTextStr++-- | Convert 'Display' instance into 'Text'.+dShow :: Display a => a -> Text+dShow a = unDisplayText (display a)++-- | Print 'Display' instance.+dPrint :: Display a => a -> IO ()+dPrint a = TextIO.putStrLn (dShow a)
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"