packages feed

enum-text-rio (empty) → 1.0.0.0

raw patch · 7 files changed

+258/−0 lines, 7 filesdep +basedep +bytestringdep +enum-textsetup-changed

Dependencies added: base, bytestring, enum-text, enum-text-rio, fmt, rio, text

Files

+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Changelog for enum-text-rio++  * 1.0.0.0 first release++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Chris Dornan (c) 2019++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 Chris Dornan 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.
+ README.md view
@@ -0,0 +1,8 @@+# enum-text-rio++Making `fmt` available with `rio`.++See the [Haddocks](http://hackage.haskell.org/package/enum-text-rio)+and the+[example program](https://github.com/cdornan/enum-text-rio/blob/master/app/demo-enum-text-rio.hs)+for details.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ app/demo-enum-text-rio.hs view
@@ -0,0 +1,53 @@+{-# LANGUAGE DeriveAnyClass    #-}+{-# LANGUAGE DerivingVia       #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE OverloadedStrings #-}+++import           RIO+import           Text.Enum.RIO.Fmt+++data Foo = FOO_bar | FOO_bar_baz+  deriving (Bounded,Enum,EnumText,Eq,Ord,Show)+  deriving (Buildable,Display,TextParsable) via UsingEnumText  Foo+++main :: IO ()+main = run $ test [minBound..maxBound]++test :: [Foo] -> RIO Env ()+test []         = return ()+test (foo:foos) = do+    logInfo $ fmt $ "hello "+|foo|+""+    test foos++--+-- RIO setup+--++data Env =+  Env+    { _env_lf :: LogFunc+    }++instance HasLogFunc Env where+  logFuncL = lens+    _env_lf+    (\x y -> x { _env_lf = y })++run :: RIO Env a -> IO a+run bdy = rio_log_func $ \lf -> runRIO (Env lf) bdy++rio_log_func :: (LogFunc -> IO a) -> IO a+rio_log_func cb = do+    lo <- opts <$> logOptionsHandle stdout is_logging+    withLogFunc lo cb+  where+    opts =+      setLogVerboseFormat   True+      . setLogUseTime       True+      . setLogUseLoc        False+      . setLogMinLevel      LevelDebug++    is_logging = True
+ enum-text-rio.cabal view
@@ -0,0 +1,62 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.1.+--+-- see: https://github.com/sol/hpack+--+-- hash: ed3ec7d9ef5873879b0d4f5cc7e129361ec3a063458d81eba59afa804e0d8298++name:           enum-text-rio+version:        1.0.0.0+synopsis:       Making fmt available with rio+description:    Please see the README on GitHub at <https://github.com/cdornan/enum-text-rio#readme>+category:       Control+homepage:       https://github.com/cdornan/enum-text-rio#readme+bug-reports:    https://github.com/cdornan/enum-text-rio/issues+author:         Chris Dornan+maintainer:     chris@chrisdornan.com+copyright:      2019 Chris Dornan+license:        BSD3+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++source-repository head+  type: git+  location: https://github.com/cdornan/enum-text-rio++library+  exposed-modules:+      Text.Enum.RIO.Fmt+  other-modules:+      Paths_enum_text_rio+  hs-source-dirs:+      src+  ghc-options: -Wall -Wcompat+  build-depends:+      base >=4.10 && <10+    , bytestring >=0.10+    , enum-text >=0.5.1.0+    , fmt >=0.6+    , rio >=0.1.0.0+    , text >=1.2.2.2+  default-language: Haskell2010++executable demo-enum-text-rio+  main-is: demo-enum-text-rio.hs+  other-modules:+      Paths_enum_text_rio+  hs-source-dirs:+      app+  ghc-options: -Wall -Wcompat -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      base >=4.10 && <10+    , bytestring >=0.10+    , enum-text >=0.5.1.0+    , enum-text-rio+    , fmt >=0.6+    , rio >=0.1.0.0+    , text >=1.2.2.2+  default-language: Haskell2010
+ src/Text/Enum/RIO/Fmt.hs view
@@ -0,0 +1,98 @@+{-# LANGUAGE NoImplicitPrelude    #-}+{-# LANGUAGE OverloadedStrings    #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Text.Enum.RIO.Fmt+  (+  -- * Overview+  -- $overview++  -- * EnumText, Display Types+  -- $example++  -- * TBuilder+    TBuilder+  -- * UsingBuildable and UsingDisplay+  , UsingBuildable(..)+  , UsingDisplay(..)+  -- * Text.Enum.Text+  , module Text.Enum.Text+  -- * Fmt+  , module Fmt+  ) where++import           Fmt                      hiding (Builder)+import           Fmt.Internal.Core+import qualified Data.ByteString.Lazy     as LBS+import           Data.ByteString.Builder+import qualified Data.Text.Lazy.Builder   as T+import           RIO+import           Text.Enum.Text+++{- $overview+If you want to use @fmt@ with @rio@, preparing 'Utf8Builder' log messages with+`fmt` and so forth then you can just import this module along side @RIO@.++See the demo program for a working example.+-}+++-- | RIO export @Builder@ as the @ByteString@ builder so we have to hide it and+-- provide this in its stead.+type TBuilder = T.Builder++{- $example+To place an 'EnumText' type in 'Display' (with the 'Buildable' and+'TextParsable' instance reqiored by 'EnumText') you can do something like this:++@+{\-\# LANGUAGE DeriveAnyClass    #-\}+{\-\# LANGUAGE DerivingVia       #-\}+{\-\# LANGUAGE NoImplicitPrelude #-\}++import           RIO+import           Text.Enum.RIO.Fmt++data Foo = FOO_bar | FOO_bar_baz+  deriving (Bounded,Enum,EnumText,Eq,Ord,Show)+  deriving (Buildable,Display,TextParsable) via UsingEnumText  Foo+@+-}++-- | @derive@ @via@ this type if you have a `Buildable` and want to derive a+-- corresponding 'Display' instance+newtype UsingBuildable a = UsingBuildable { _UsingBuildable :: a }++-- | @derive@ @via@ this type if you have a `Display` type and want to derive a+-- corresponding 'Buildable' instance+newtype UsingDisplay   a = UsingDisplay   { _UsingDisplay   :: a }++instance Buildable a => Display (UsingBuildable a) where+  display (UsingBuildable x) =+    Utf8Builder+      $ byteString+      $ encodeUtf8+      $ fmt+      $ build x++instance Display a => Buildable (UsingDisplay a) where+  build (UsingDisplay x) =+    build+      $ decodeUtf8With lenientDecode+      $ LBS.toStrict+      $ toLazyByteString+      $ getUtf8Builder+      $ display x++instance EnumText a => Display (UsingEnumText a) where+  display (UsingEnumText x) =+    Utf8Builder+      $ byteString+      $ encodeUtf8+      $ fmt+      $ buildEnumText x++-- | With this instance we can use `fmt` to generate `Utf8Builder` strings+instance FromBuilder Utf8Builder where+  fromBuilder = Utf8Builder . byteString . fromBuilder