From 64b6ead0d1e157701f8569743eda496bc71b8351 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 23 Jan 2017 16:09:05 +0100 Subject: Add support for ESC/POS text decoration --- spec/src/Thermoprint/Printout.hs | 15 +++++++++++++++ spec/thermoprint-spec.cabal | 2 +- spec/thermoprint-spec.nix | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/src/Thermoprint/Printout.hs b/spec/src/Thermoprint/Printout.hs index 8c33e07..752ccb5 100644 --- a/spec/src/Thermoprint/Printout.hs +++ b/spec/src/Thermoprint/Printout.hs @@ -11,7 +11,9 @@ module Thermoprint.Printout , Block(..) , Line( HSpace , JuxtaPos + , Markup ) + , MarkupMode(..) , text, cotext , prop_text ) where @@ -48,6 +50,9 @@ import Data.Monoid (Monoid(..), (<>)) import Data.List (dropWhile, dropWhileEnd, groupBy, genericLength, genericReplicate) +import Data.Set (Set) +import qualified Data.Set as Set + import Data.Sequence as Seq (fromList, null, singleton) import Data.Sequence (ViewL(..), viewl) @@ -143,6 +148,7 @@ We don't export all constructors and instead encourage the use of 'text'. -} data Line = Word Text | HSpace Integer + | Markup (Set MarkupMode) Line | JuxtaPos (Seq Line) deriving (Generic, NFData, Show, CoArbitrary, FromJSON, ToJSON) @@ -215,6 +221,7 @@ cotext (Line x) = cotext' x where cotext' (Word x) = x cotext' (HSpace n) = TL.pack . genericReplicate n $ ' ' + cotext' (Markup _ l) = cotext' l cotext' (JuxtaPos xs) = mconcat . map cotext' . toList $ xs prop_text :: Text -> Bool @@ -231,6 +238,14 @@ prop_text x = (cotext . either id Line . text $ x') == x' | otherwise = c keep = [' ', '\n'] :: [Char] +data MarkupMode = Bold + | Underline + | DoubleHeight + | DoubleWidth + deriving (Generic, NFData, Show, Arbitrary, CoArbitrary, FromJSON, ToJSON + , Eq, Ord, Enum + ) + -- | We don't test 'Raw' 'Chunk's instance Arbitrary Chunk where shrink = genericShrink diff --git a/spec/thermoprint-spec.cabal b/spec/thermoprint-spec.cabal index 28680fb..d4ecda6 100644 --- a/spec/thermoprint-spec.cabal +++ b/spec/thermoprint-spec.cabal @@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: thermoprint-spec -version: 4.0.0 +version: 5.0.0 synopsis: A specification of the API and the payload datatypes and associated utilities -- description: homepage: http://dirty-haskell.org/tags/thermoprint.html diff --git a/spec/thermoprint-spec.nix b/spec/thermoprint-spec.nix index 3480782..1a1611c 100644 --- a/spec/thermoprint-spec.nix +++ b/spec/thermoprint-spec.nix @@ -4,7 +4,7 @@ }: mkDerivation { pname = "thermoprint-spec"; - version = "4.0.0"; + version = "5.0.0"; src = ./.; libraryHaskellDepends = [ aeson base base64-bytestring bytestring Cabal cabal-test-quickcheck -- cgit v1.2.3