aboutsummaryrefslogtreecommitdiff
path: root/server/src/Thermoprint/Server/Printer/Generic.hs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/Thermoprint/Server/Printer/Generic.hs')
-rw-r--r--server/src/Thermoprint/Server/Printer/Generic.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/server/src/Thermoprint/Server/Printer/Generic.hs b/server/src/Thermoprint/Server/Printer/Generic.hs
index 2c88b55..2945dd0 100644
--- a/server/src/Thermoprint/Server/Printer/Generic.hs
+++ b/server/src/Thermoprint/Server/Printer/Generic.hs
@@ -52,6 +52,8 @@ import Data.Monoid
52 52
53import Data.Int (Int64) 53import Data.Int (Int64)
54 54
55import Control.Concurrent (threadDelay)
56
55import Prelude hiding (mapM_, sequence_, lines) 57import Prelude hiding (mapM_, sequence_, lines)
56 58
57genericPrint :: FilePath -> PrinterMethod 59genericPrint :: FilePath -> PrinterMethod
@@ -65,10 +67,17 @@ genericPrint' path = flip catches handlers . withFile path . print
65 , Handler $ return . Just . EncError 67 , Handler $ return . Just . EncError
66 , Handler $ return . Just 68 , Handler $ return . Just
67 ] 69 ]
68 print printout handle = $(logDebug) (T.pack $ show printout') >> liftIO (LBS.hPutStr handle printout' >> return Nothing) 70 print printout handle = $(logDebug) (T.pack $ show printout') >> liftIO (slowPut handle printout' >> return Nothing)
69 where 71 where
70 printout' = runPut $ initialize >> render printout >> finalize 72 printout' = runPut $ initialize >> render printout >> finalize
71 73
74slowPut :: Handle -> Lazy.ByteString -> IO ()
75slowPut h = slowPut' . LBS.split (LBS.last newl)
76 where
77 slowPut' [] = return ()
78 slowPut' [t] = LBS.hPutStr h t
79 slowPut' (x:xs) = slowPut' [x] >> LBS.hPutStr h (LBS.singleton $ LBS.last newl) >> threadDelay (50 * 10^3) >> slowPut' xs
80
72encode' :: ByteSink m => String -> m () 81encode' :: ByteSink m => String -> m ()
73encode' = encode CP437 82encode' = encode CP437
74 83