aboutsummaryrefslogtreecommitdiff
path: root/spec/src/Thermoprint/Printout.hs
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2017-01-23 16:09:05 +0100
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2017-01-23 16:09:05 +0100
commit64b6ead0d1e157701f8569743eda496bc71b8351 (patch)
treef7ae09e9ec950e91cacb1923aa54b96d59c9a8f3 /spec/src/Thermoprint/Printout.hs
parente95dac748371afcad3ffddf5c98e5fcb0a8302b7 (diff)
downloadthermoprint-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/src/Thermoprint/Printout.hs')
-rw-r--r--spec/src/Thermoprint/Printout.hs15
1 files changed, 15 insertions, 0 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
49import Data.List (dropWhile, dropWhileEnd, groupBy, genericLength, genericReplicate) 51import Data.List (dropWhile, dropWhileEnd, groupBy, genericLength, genericReplicate)
50 52
53import Data.Set (Set)
54import qualified Data.Set as Set
55
51import Data.Sequence as Seq (fromList, null, singleton) 56import Data.Sequence as Seq (fromList, null, singleton)
52import Data.Sequence (ViewL(..), viewl) 57import 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-}
144data Line = Word Text 149data 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
220prop_text :: Text -> Bool 227prop_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
241data 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
235instance Arbitrary Chunk where 250instance Arbitrary Chunk where
236 shrink = genericShrink 251 shrink = genericShrink