diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2017-01-23 16:09:05 +0100 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2017-01-23 16:09:05 +0100 |
commit | 64b6ead0d1e157701f8569743eda496bc71b8351 (patch) | |
tree | f7ae09e9ec950e91cacb1923aa54b96d59c9a8f3 /spec | |
parent | e95dac748371afcad3ffddf5c98e5fcb0a8302b7 (diff) | |
download | thermoprint-64b6ead0d1e157701f8569743eda496bc71b8351.tar thermoprint-64b6ead0d1e157701f8569743eda496bc71b8351.tar.gz thermoprint-64b6ead0d1e157701f8569743eda496bc71b8351.tar.bz2 thermoprint-64b6ead0d1e157701f8569743eda496bc71b8351.tar.xz thermoprint-64b6ead0d1e157701f8569743eda496bc71b8351.zip |
Add support for ESC/POS text decoration
Diffstat (limited to 'spec')
-rw-r--r-- | spec/src/Thermoprint/Printout.hs | 15 | ||||
-rw-r--r-- | spec/thermoprint-spec.cabal | 2 | ||||
-rw-r--r-- | spec/thermoprint-spec.nix | 2 |
3 files changed, 17 insertions, 2 deletions
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 | |||
11 | , Block(..) | 11 | , Block(..) |
12 | , Line( HSpace | 12 | , Line( HSpace |
13 | , JuxtaPos | 13 | , JuxtaPos |
14 | , Markup | ||
14 | ) | 15 | ) |
16 | , MarkupMode(..) | ||
15 | , text, cotext | 17 | , text, cotext |
16 | , prop_text | 18 | , prop_text |
17 | ) where | 19 | ) where |
@@ -48,6 +50,9 @@ import Data.Monoid (Monoid(..), (<>)) | |||
48 | 50 | ||
49 | import Data.List (dropWhile, dropWhileEnd, groupBy, genericLength, genericReplicate) | 51 | import Data.List (dropWhile, dropWhileEnd, groupBy, genericLength, genericReplicate) |
50 | 52 | ||
53 | import Data.Set (Set) | ||
54 | import qualified Data.Set as Set | ||
55 | |||
51 | import Data.Sequence as Seq (fromList, null, singleton) | 56 | import Data.Sequence as Seq (fromList, null, singleton) |
52 | import Data.Sequence (ViewL(..), viewl) | 57 | import Data.Sequence (ViewL(..), viewl) |
53 | 58 | ||
@@ -143,6 +148,7 @@ We don't export all constructors and instead encourage the use of 'text'. | |||
143 | -} | 148 | -} |
144 | data Line = Word Text | 149 | data Line = Word Text |
145 | | HSpace Integer | 150 | | HSpace Integer |
151 | | Markup (Set MarkupMode) Line | ||
146 | | JuxtaPos (Seq Line) | 152 | | JuxtaPos (Seq Line) |
147 | deriving (Generic, NFData, Show, CoArbitrary, FromJSON, ToJSON) | 153 | deriving (Generic, NFData, Show, CoArbitrary, FromJSON, ToJSON) |
148 | 154 | ||
@@ -215,6 +221,7 @@ cotext (Line x) = cotext' x | |||
215 | where | 221 | where |
216 | cotext' (Word x) = x | 222 | cotext' (Word x) = x |
217 | cotext' (HSpace n) = TL.pack . genericReplicate n $ ' ' | 223 | cotext' (HSpace n) = TL.pack . genericReplicate n $ ' ' |
224 | cotext' (Markup _ l) = cotext' l | ||
218 | cotext' (JuxtaPos xs) = mconcat . map cotext' . toList $ xs | 225 | cotext' (JuxtaPos xs) = mconcat . map cotext' . toList $ xs |
219 | 226 | ||
220 | prop_text :: Text -> Bool | 227 | prop_text :: Text -> Bool |
@@ -231,6 +238,14 @@ prop_text x = (cotext . either id Line . text $ x') == x' | |||
231 | | otherwise = c | 238 | | otherwise = c |
232 | keep = [' ', '\n'] :: [Char] | 239 | keep = [' ', '\n'] :: [Char] |
233 | 240 | ||
241 | data MarkupMode = Bold | ||
242 | | Underline | ||
243 | | DoubleHeight | ||
244 | | DoubleWidth | ||
245 | deriving (Generic, NFData, Show, Arbitrary, CoArbitrary, FromJSON, ToJSON | ||
246 | , Eq, Ord, Enum | ||
247 | ) | ||
248 | |||
234 | -- | We don't test 'Raw' 'Chunk's | 249 | -- | We don't test 'Raw' 'Chunk's |
235 | instance Arbitrary Chunk where | 250 | instance Arbitrary Chunk where |
236 | shrink = genericShrink | 251 | 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 @@ | |||
2 | -- documentation, see http://haskell.org/cabal/users-guide/ | 2 | -- documentation, see http://haskell.org/cabal/users-guide/ |
3 | 3 | ||
4 | name: thermoprint-spec | 4 | name: thermoprint-spec |
5 | version: 4.0.0 | 5 | version: 5.0.0 |
6 | synopsis: A specification of the API and the payload datatypes and associated utilities | 6 | synopsis: A specification of the API and the payload datatypes and associated utilities |
7 | -- description: | 7 | -- description: |
8 | homepage: http://dirty-haskell.org/tags/thermoprint.html | 8 | 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 @@ | |||
4 | }: | 4 | }: |
5 | mkDerivation { | 5 | mkDerivation { |
6 | pname = "thermoprint-spec"; | 6 | pname = "thermoprint-spec"; |
7 | version = "4.0.0"; | 7 | version = "5.0.0"; |
8 | src = ./.; | 8 | src = ./.; |
9 | libraryHaskellDepends = [ | 9 | libraryHaskellDepends = [ |
10 | aeson base base64-bytestring bytestring Cabal cabal-test-quickcheck | 10 | aeson base base64-bytestring bytestring Cabal cabal-test-quickcheck |