diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-16 20:35:29 +0000 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-02-16 20:35:29 +0000 |
commit | e9c92d233ba470d060f1ee0276120bc746b806ac (patch) | |
tree | 89aac68a6fbb912562c3979f7d278268695dad79 /server | |
parent | 8e8394452565dbd338427c6304c324d5fb51b908 (diff) | |
download | thermoprint-e9c92d233ba470d060f1ee0276120bc746b806ac.tar thermoprint-e9c92d233ba470d060f1ee0276120bc746b806ac.tar.gz thermoprint-e9c92d233ba470d060f1ee0276120bc746b806ac.tar.bz2 thermoprint-e9c92d233ba470d060f1ee0276120bc746b806ac.tar.xz thermoprint-e9c92d233ba470d060f1ee0276120bc746b806ac.zip |
rate limiting output to generic printer
Diffstat (limited to 'server')
-rw-r--r-- | server/src/Thermoprint/Server/Printer/Generic.hs | 11 |
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 | ||
53 | import Data.Int (Int64) | 53 | import Data.Int (Int64) |
54 | 54 | ||
55 | import Control.Concurrent (threadDelay) | ||
56 | |||
55 | import Prelude hiding (mapM_, sequence_, lines) | 57 | import Prelude hiding (mapM_, sequence_, lines) |
56 | 58 | ||
57 | genericPrint :: FilePath -> PrinterMethod | 59 | genericPrint :: 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 | ||
74 | slowPut :: Handle -> Lazy.ByteString -> IO () | ||
75 | slowPut 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 | |||
72 | encode' :: ByteSink m => String -> m () | 81 | encode' :: ByteSink m => String -> m () |
73 | encode' = encode CP437 | 82 | encode' = encode CP437 |
74 | 83 | ||