generic-pretty-instances (empty) → 0.1.0.0
raw patch · 11 files changed
+452/−0 lines, 11 filesdep +GenericPrettydep +basedep +base16-bytestringsetup-changed
Dependencies added: GenericPretty, base, base16-bytestring, bytestring, case-insensitive, hspec, persistent, pretty, pretty-simple, proto-lens, proto-lens-runtime, secp256k1-haskell, text, time, universum, vector
Files
- ChangeLog.md +0/−0
- LICENSE +30/−0
- README.md +1/−0
- Setup.hs +2/−0
- generic-pretty-instances.cabal +108/−0
- src/Text/PrettyPrint/GenericPretty/Import.hs +8/−0
- src/Text/PrettyPrint/GenericPretty/Instance.hs +167/−0
- src/Text/PrettyPrint/GenericPretty/Type.hs +30/−0
- src/Text/PrettyPrint/GenericPretty/Util.hs +87/−0
- test/GenericPrettyInstancesSpec.hs +17/−0
- test/Spec.hs +2/−0
+ ChangeLog.md view
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Yolo (c) 2022++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 Yolo 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,1 @@+# generic-pretty-instances
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ generic-pretty-instances.cabal view
@@ -0,0 +1,108 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.34.7.+--+-- see: https://github.com/sol/hpack++name: generic-pretty-instances+version: 0.1.0.0+synopsis: GenericPretty canonical instances+description: You can find documentation at <https://hackage.haskell.org/package/generic-pretty-instances>+category: Text, Generics, Pretty Printer+homepage: https://github.com/coingaming/src+bug-reports: https://github.com/coingaming/src/issues+author: 21it <21it@tuta.io>, Mikhail Prushinskiy <mprushinsky@gmail.com>, Artem Markov <drownbes@gmail.com>+maintainer: 21it <21it@tuta.io>, Mikhail Prushinskiy <mprushinsky@gmail.com>, Artem Markov <drownbes@gmail.com>+copyright: 2022 Yolo <hello@coingaming.io>+license: BSD3+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md+ ChangeLog.md++source-repository head+ type: git+ location: https://github.com/coingaming/src++library+ exposed-modules:+ Text.PrettyPrint.GenericPretty.Import+ Text.PrettyPrint.GenericPretty.Instance+ Text.PrettyPrint.GenericPretty.Type+ Text.PrettyPrint.GenericPretty.Util+ other-modules:+ Paths_generic_pretty_instances+ hs-source-dirs:+ src+ default-extensions:+ NoImplicitPrelude+ OverloadedStrings+ ScopedTypeVariables+ StrictData+ DeriveGeneric+ DerivingStrategies+ LambdaCase+ ghc-options: -Weverything -Wno-missing-exported-signatures -Wno-missing-import-lists -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-missing-local-signatures+ build-depends:+ GenericPretty+ , base >=4.7 && <5+ , base16-bytestring+ , bytestring+ , case-insensitive+ , persistent+ , pretty+ , pretty-simple+ , proto-lens+ , proto-lens-runtime+ , secp256k1-haskell ==0.6.*+ , text+ , time+ , universum+ , vector+ if impl(ghc >= 8.10.7)+ ghc-options: -Wno-unused-packages -Wno-prepositive-qualified-module -Wno-missing-safe-haskell-mode+ default-language: Haskell2010++test-suite generic-pretty-instances-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Text.PrettyPrint.GenericPretty.Import+ Text.PrettyPrint.GenericPretty.Instance+ Text.PrettyPrint.GenericPretty.Type+ Text.PrettyPrint.GenericPretty.Util+ GenericPrettyInstancesSpec+ Paths_generic_pretty_instances+ hs-source-dirs:+ src+ test+ default-extensions:+ NoImplicitPrelude+ OverloadedStrings+ ScopedTypeVariables+ StrictData+ DeriveGeneric+ DerivingStrategies+ LambdaCase+ ghc-options: -Weverything -Wno-missing-exported-signatures -Wno-missing-import-lists -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-missing-local-signatures -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ GenericPretty+ , base >=4.7 && <5+ , base16-bytestring+ , bytestring+ , case-insensitive+ , hspec+ , persistent+ , pretty+ , pretty-simple+ , proto-lens+ , proto-lens-runtime+ , secp256k1-haskell ==0.6.*+ , text+ , time+ , universum+ , vector+ if impl(ghc >= 8.10.7)+ ghc-options: -Wno-unused-packages -Wno-prepositive-qualified-module -Wno-missing-safe-haskell-mode+ default-language: Haskell2010
+ src/Text/PrettyPrint/GenericPretty/Import.hs view
@@ -0,0 +1,8 @@+module Text.PrettyPrint.GenericPretty.Import+ ( module X,+ )+where++import Text.PrettyPrint.GenericPretty.Instance as X ()+import Text.PrettyPrint.GenericPretty.Type as X+import Text.PrettyPrint.GenericPretty.Util as X
+ src/Text/PrettyPrint/GenericPretty/Instance.hs view
@@ -0,0 +1,167 @@+{-# LANGUAGE StandaloneDeriving #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Text.PrettyPrint.GenericPretty.Instance+ (+ )+where++import qualified Control.Exception as Exception+import qualified Crypto.Secp256k1 as Secp256k1+import Data.ByteString.Base16 as B16 (encode)+import qualified Data.CaseInsensitive as CI+import qualified Data.Fixed as Fixed+import qualified Data.ProtoLens.Runtime.Data.ProtoLens.Encoding.Wire as Wire+import qualified Data.Text as T+import qualified Data.Text.Lazy as TL+import qualified Data.Time.Calendar as Calendar+import Data.Time.Clock (UTCTime)+import qualified Data.Time.Clock as Clock+import qualified Data.Time.LocalTime as LocalTime+import qualified Data.Vector.Unboxed as Unboxed+import qualified Database.Persist as Psql+import qualified GHC.Conc.Sync as GHC+import Text.PrettyPrint.GenericPretty+import Universum++--+-- Trivial+--++deriving stock instance Generic Wire.Tag++instance Out Wire.Tag++deriving stock instance Generic Wire.WireValue++instance Out Wire.WireValue++deriving stock instance Generic Wire.TaggedValue++instance Out Wire.TaggedValue++deriving stock instance Generic Exception.BlockedIndefinitelyOnMVar++instance Out Exception.BlockedIndefinitelyOnMVar++deriving stock instance Generic Calendar.Day++instance Out Calendar.Day++deriving stock instance Generic LocalTime.TimeOfDay++instance Out LocalTime.TimeOfDay++deriving stock instance Generic UTCTime++instance Out UTCTime++deriving stock instance Generic (Fixed.Fixed a)++instance Out (Fixed.Fixed a)++deriving stock instance Generic Psql.PersistValue++instance Out Psql.PersistValue++deriving stock instance Generic Psql.LiteralType++instance Out Psql.LiteralType++instance+ ( Generic a,+ Generic (Psql.Key a),+ Out a,+ Out (Psql.Key a)+ ) =>+ Out (Psql.Entity a)++instance Out Secp256k1.PubKey++instance Out Secp256k1.Sig++instance (Out a) => Out (CI.CI a) where+ docPrec x = docPrec x . CI.original+ doc = doc . CI.original++--+-- Show+--++instance Out GHC.ThreadId where+ docPrec = const Universum.show+ doc = Universum.show++instance Out Clock.DiffTime where+ docPrec = const Universum.show+ doc = Universum.show++--+-- Composite+--++instance Out Word32 where+ docPrec n = docPrec n . fromIntegral @Word32 @Integer+ doc = doc . fromIntegral @Word32 @Integer++instance Out Word64 where+ docPrec n = docPrec n . fromIntegral @Word64 @Integer+ doc = doc . fromIntegral @Word64 @Integer++instance Out Int32 where+ docPrec n = docPrec n . fromIntegral @Int32 @Integer+ doc = doc . fromIntegral @Int32 @Integer++instance Out Int64 where+ docPrec n = docPrec n . fromIntegral @Int64 @Integer+ doc = doc . fromIntegral @Int64 @Integer++instance Out Text where+ docPrec n = docPrec n . T.unpack+ doc = doc . T.unpack++instance Out TL.Text where+ docPrec n = docPrec n . TL.unpack+ doc = doc . TL.unpack++instance Out ByteString where+ docPrec n = docPrec n . newBsDoc+ doc = doc . newBsDoc++instance (Out a) => Out (Vector a) where+ docPrec n = docPrec n . toList+ doc = doc . toList++instance+ (Out a, Unboxed.Unbox a) =>+ Out (Unboxed.Vector a)+ where+ docPrec n = docPrec n . Unboxed.toList+ doc = doc . Unboxed.toList++instance (Out a, Out b) => Out (Map a b) where+ docPrec n = docPrec n . toList+ doc = doc . toList++--+-- Misc+--++data ByteStringDoc+ = ByteStringUtf8 Text+ | ByteStringHex Text+ | ByteStringRaw Text+ deriving stock (Generic)++instance Out ByteStringDoc++newBsDoc :: ByteString -> ByteStringDoc+newBsDoc bs =+ case decodeUtf8' bs of+ Right txt -> ByteStringUtf8 txt+ Left {} ->+ case decodeUtf8' $ B16.encode bs of+ Right txt -> ByteStringHex txt+ Left {} -> ByteStringRaw $ Universum.show bs
+ src/Text/PrettyPrint/GenericPretty/Type.hs view
@@ -0,0 +1,30 @@+module Text.PrettyPrint.GenericPretty.Type+ ( PrettyLog (..),+ SecretVision (..),+ )+where++import Text.PrettyPrint.GenericPretty (Out (..))+import Universum++data PrettyLog a+ = PrettyLog a+ | SecretLog SecretVision a+ deriving stock (Eq, Ord)++data SecretVision+ = SecretVisible+ | SecretHidden+ deriving stock (Eq, Ord, Show, Read, Generic)++instance Out SecretVision++instance (Out a) => Out (PrettyLog a) where+ docPrec n = \case+ PrettyLog x -> docPrec n x+ SecretLog SecretVisible x -> docPrec n x+ SecretLog SecretHidden _ -> "SECRET"+ doc = \case+ PrettyLog x -> doc x+ SecretLog SecretVisible x -> doc x+ SecretLog SecretHidden _ -> "SECRET"
+ src/Text/PrettyPrint/GenericPretty/Util.hs view
@@ -0,0 +1,87 @@+module Text.PrettyPrint.GenericPretty.Util+ ( inspect,+ inspectStr,+ inspectGen,+ inspectPlain,+ inspectStrPlain,+ inspectGenPlain,+ inspectStyle,+ inspectStyleStr,+ inspectStyleGen,+ )+where++import qualified Data.Text as T+import qualified Data.Text.Lazy as TL+import qualified Text.Pretty.Simple as PrettySimple+import qualified Text.PrettyPrint as Pretty+import Text.PrettyPrint.GenericPretty (Out)+import qualified Text.PrettyPrint.GenericPretty as GenericPretty+import Universum hiding (show)++inspect :: (Out a) => a -> T.Text+inspect =+ inspectStyle simpleStyle++inspectStr :: (Out a) => a -> String+inspectStr =+ inspectStyleStr simpleStyle++inspectGen :: (Out a, IsString b) => a -> b+inspectGen =+ inspectStyleGen simpleStyle++inspectPlain :: (Out a) => a -> T.Text+inspectPlain =+ inspectStyle plainStyle++inspectStrPlain :: (Out a) => a -> String+inspectStrPlain =+ inspectStyleStr plainStyle++inspectGenPlain :: (Out a, IsString b) => a -> b+inspectGenPlain =+ inspectStyleGen plainStyle++inspectStyle ::+ (Out a) =>+ PrettySimple.OutputOptions ->+ a ->+ T.Text+inspectStyle style =+ TL.toStrict+ . PrettySimple.pStringOpt style+ . GenericPretty.prettyStyle+ Pretty.style+ { Pretty.mode = Pretty.OneLineMode+ }++inspectStyleStr ::+ (Out a) =>+ PrettySimple.OutputOptions ->+ a ->+ String+inspectStyleStr style =+ T.unpack . inspectStyle style++inspectStyleGen ::+ ( Out a,+ IsString b+ ) =>+ PrettySimple.OutputOptions ->+ a ->+ b+inspectStyleGen style =+ fromString . inspectStyleStr style++simpleStyle :: PrettySimple.OutputOptions+simpleStyle =+ PrettySimple.defaultOutputOptionsDarkBg++plainStyle :: PrettySimple.OutputOptions+plainStyle =+ PrettySimple.defaultOutputOptionsNoColor+ { PrettySimple.outputOptionsPageWidth = 100000,+ PrettySimple.outputOptionsCompact = True,+ PrettySimple.outputOptionsCompactParens = True+ }
+ test/GenericPrettyInstancesSpec.hs view
@@ -0,0 +1,17 @@+module GenericPrettyInstancesSpec (spec) where++import Test.Hspec+import Text.PrettyPrint.GenericPretty.Util+ ( inspect,+ inspectPlain,+ )+import Universum hiding (show)++spec :: Spec+spec = do+ it "Bool" $+ inspect True+ `shouldBe` "True"+ it "List" $+ inspectPlain ([1 .. 5] :: [Int])+ `shouldBe` "[ 1, 2, 3, 4, 5 ]"
+ test/Spec.hs view
@@ -0,0 +1,2 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}+{-# OPTIONS_GHC -Wno-missing-export-lists #-}