aboutsummaryrefslogtreecommitdiff
path: root/tprint
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-03-01 10:58:08 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2016-03-01 10:58:08 +0100
commit5fea1efa7b276134750920f4d8da317422a21d83 (patch)
treee59496875fb131280ed4e9f976e488d7c9824ec9 /tprint
parent8d811536eb1b45e2be3eb6be1e2f1a3feef04336 (diff)
downloadthermoprint-5fea1efa7b276134750920f4d8da317422a21d83.tar
thermoprint-5fea1efa7b276134750920f4d8da317422a21d83.tar.gz
thermoprint-5fea1efa7b276134750920f4d8da317422a21d83.tar.bz2
thermoprint-5fea1efa7b276134750920f4d8da317422a21d83.tar.xz
thermoprint-5fea1efa7b276134750920f4d8da317422a21d83.zip
jobCreate
Diffstat (limited to 'tprint')
-rw-r--r--tprint/src/Main.hs20
-rw-r--r--tprint/tprint.cabal2
-rw-r--r--tprint/tprint.nix8
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
21import Control.Monad 21import Control.Monad
22import Control.Monad.Catch 22import Control.Monad.Catch
23import Control.DeepSeq
24import Control.Concurrent (threadDelay)
23 25
24import Text.Show.Pretty (dumpStr) 26import Text.Show.Pretty (dumpStr)
25import Data.Aeson.Encode.Pretty (encodePretty) 27import Data.Aeson.Encode.Pretty (encodePretty)
28import Data.Aeson (eitherDecode')
26 29
27import System.IO 30import 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
95tprint 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
93tprint _ _ _ = undefined 113tprint _ _ _ = 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}:
5mkDerivation { 5mkDerivation {
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 ];