diff options
-rw-r--r-- | tprint/src/Main.hs | 20 | ||||
-rw-r--r-- | tprint/tprint.cabal | 2 | ||||
-rw-r--r-- | tprint/tprint.nix | 8 |
3 files changed, 26 insertions, 4 deletions
diff --git a/tprint/src/Main.hs b/tprint/src/Main.hs index 6df335a..708fa4c 100644 --- a/tprint/src/Main.hs +++ b/tprint/src/Main.hs | |||
@@ -20,9 +20,12 @@ import Data.Either | |||
20 | 20 | ||
21 | import Control.Monad | 21 | import Control.Monad |
22 | import Control.Monad.Catch | 22 | import Control.Monad.Catch |
23 | import Control.DeepSeq | ||
24 | import Control.Concurrent (threadDelay) | ||
23 | 25 | ||
24 | import Text.Show.Pretty (dumpStr) | 26 | import Text.Show.Pretty (dumpStr) |
25 | import Data.Aeson.Encode.Pretty (encodePretty) | 27 | import Data.Aeson.Encode.Pretty (encodePretty) |
28 | import Data.Aeson (eitherDecode') | ||
26 | 29 | ||
27 | import System.IO | 30 | import System.IO |
28 | 31 | ||
@@ -89,5 +92,22 @@ tprint TPrint{ operation = Job{..}, ..} Client{..} out = job jobId >>= format | |||
89 | | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty p | 92 | | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty p |
90 | | otherwise <- output = T.hPutStrLn out =<< either throwM return (cobbcode p) | 93 | | otherwise <- output = T.hPutStrLn out =<< either throwM return (cobbcode p) |
91 | 94 | ||
95 | tprint TPrint{ operation = JobCreate{..}, ..} Client{..} out = withInput input $ \inH -> do | ||
96 | let | ||
97 | p' | ||
98 | | (BBCode, _) <- input = either throwM return . bbcode =<< T.hGetContents inH | ||
99 | | otherwise = either (throwM . userError) return . eitherDecode' =<< LCBS.hGetContents inH | ||
100 | blockLoop =<< jobCreate printer . force =<< p' | ||
101 | where | ||
102 | blockLoop jId | ||
103 | | block = do | ||
104 | threadDelay (10^6) | ||
105 | status <- jobStatus jId | ||
106 | case status of | ||
107 | Done -> return () | ||
108 | Failed err -> throwM err | ||
109 | _ -> blockLoop jId | ||
110 | | otherwise = return () | ||
111 | |||
92 | 112 | ||
93 | tprint _ _ _ = undefined | 113 | tprint _ _ _ = undefined |
diff --git a/tprint/tprint.cabal b/tprint/tprint.cabal index 03d6352..d6fc422 100644 --- a/tprint/tprint.cabal +++ b/tprint/tprint.cabal | |||
@@ -31,8 +31,10 @@ executable tprint | |||
31 | , pretty-show >=1.6.9 && <2 | 31 | , pretty-show >=1.6.9 && <2 |
32 | , text >=1.2.2 && <2 | 32 | , text >=1.2.2 && <2 |
33 | , aeson-pretty >=0.7.2 && <1 | 33 | , aeson-pretty >=0.7.2 && <1 |
34 | , aeson >=0.9.0 && <1 | ||
34 | , bytestring >=0.10.6 && <1 | 35 | , bytestring >=0.10.6 && <1 |
35 | , exceptions >=0.8.2 && <1 | 36 | , exceptions >=0.8.2 && <1 |
37 | , deepseq >=1.4.1 && <2 | ||
36 | hs-source-dirs: src | 38 | hs-source-dirs: src |
37 | default-language: Haskell2010 | 39 | default-language: Haskell2010 |
38 | ghc-options: -Wall \ No newline at end of file | 40 | ghc-options: -Wall \ No newline at end of file |
diff --git a/tprint/tprint.nix b/tprint/tprint.nix index ace6210..3a23af2 100644 --- a/tprint/tprint.nix +++ b/tprint/tprint.nix | |||
@@ -1,6 +1,6 @@ | |||
1 | { mkDerivation, aeson-pretty, base, bytestring, containers | 1 | { mkDerivation, aeson, aeson-pretty, base, bytestring, containers |
2 | , exceptions, optparse-applicative, pretty-show, stdenv, text | 2 | , deepseq, exceptions, optparse-applicative, pretty-show, stdenv |
3 | , thermoprint-bbcode, thermoprint-client, time | 3 | , text, thermoprint-bbcode, thermoprint-client, time |
4 | }: | 4 | }: |
5 | mkDerivation { | 5 | mkDerivation { |
6 | pname = "tprint"; | 6 | pname = "tprint"; |
@@ -9,7 +9,7 @@ mkDerivation { | |||
9 | isLibrary = false; | 9 | isLibrary = false; |
10 | isExecutable = true; | 10 | isExecutable = true; |
11 | executableHaskellDepends = [ | 11 | executableHaskellDepends = [ |
12 | aeson-pretty base bytestring containers exceptions | 12 | aeson aeson-pretty base bytestring containers deepseq exceptions |
13 | optparse-applicative pretty-show text thermoprint-bbcode | 13 | optparse-applicative pretty-show text thermoprint-bbcode |
14 | thermoprint-client time | 14 | thermoprint-client time |
15 | ]; | 15 | ]; |