aboutsummaryrefslogtreecommitdiff
path: root/tprint
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-03-01 09:57:25 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2016-03-01 09:57:25 +0100
commitc2153f196c64593a252bc0fbbc3d503628fe896f (patch)
treee2218871dc70a304cd37f26c895d524f0cc6456f /tprint
parentaeceaafdab661f6e0d63ef9695396bc7dfb8619d (diff)
downloadthermoprint-c2153f196c64593a252bc0fbbc3d503628fe896f.tar
thermoprint-c2153f196c64593a252bc0fbbc3d503628fe896f.tar.gz
thermoprint-c2153f196c64593a252bc0fbbc3d503628fe896f.tar.bz2
thermoprint-c2153f196c64593a252bc0fbbc3d503628fe896f.tar.xz
thermoprint-c2153f196c64593a252bc0fbbc3d503628fe896f.zip
printers
Diffstat (limited to 'tprint')
-rw-r--r--tprint/src/Instances.hs6
-rw-r--r--tprint/src/Main.hs27
-rw-r--r--tprint/src/Options.hs4
-rw-r--r--tprint/tprint.cabal2
-rw-r--r--tprint/tprint.nix9
5 files changed, 37 insertions, 11 deletions
diff --git a/tprint/src/Instances.hs b/tprint/src/Instances.hs
index cffb8b0..7814bbc 100644
--- a/tprint/src/Instances.hs
+++ b/tprint/src/Instances.hs
@@ -8,7 +8,7 @@ import Data.Time (UTCTime, formatTime, defaultTimeLocale)
8import Text.Show.Pretty (Value, PrettyVal(..), dumpStr) 8import Text.Show.Pretty (Value, PrettyVal(..), dumpStr)
9import qualified Text.Show.Pretty as PShow (Value(..)) 9import qualified Text.Show.Pretty as PShow (Value(..))
10 10
11import Thermoprint.Client (Scheme(..), BaseUrl(..), PrinterId(..), JobId(..), DraftId(..), Range(..)) 11import Thermoprint.Client (Scheme(..), BaseUrl(..), PrinterId(..), JobId(..), DraftId(..), Range(..), PrinterStatus(..), JobStatus(..), PrintingError(..), EncodingException(..))
12 12
13instance PrettyVal Scheme 13instance PrettyVal Scheme
14instance PrettyVal BaseUrl 14instance PrettyVal BaseUrl
@@ -23,3 +23,7 @@ instance PrettyVal UTCTime where
23instance PrettyVal Text where 23instance PrettyVal Text where
24 prettyVal = prettyVal . T.unpack 24 prettyVal = prettyVal . T.unpack
25 25
26instance PrettyVal PrinterStatus
27instance PrettyVal JobStatus
28instance PrettyVal PrintingError
29instance PrettyVal EncodingException
diff --git a/tprint/src/Main.hs b/tprint/src/Main.hs
index cd6e68b..a937181 100644
--- a/tprint/src/Main.hs
+++ b/tprint/src/Main.hs
@@ -1,4 +1,5 @@
1{-# LANGUAGE RecordWildCards #-} 1{-# LANGUAGE RecordWildCards #-}
2{-# LANGUAGE ViewPatterns #-}
2 3
3import Data.Map (Map) 4import Data.Map (Map)
4import qualified Data.Map as Map 5import qualified Data.Map as Map
@@ -6,10 +7,15 @@ import Data.Sequence (Seq)
6import qualified Data.Sequence as Seq 7import qualified Data.Sequence as Seq
7import Data.Text (Text) 8import Data.Text (Text)
8import qualified Data.Text as T 9import qualified Data.Text as T
10import qualified Data.ByteString.Lazy.Char8 as Lazy (ByteString)
11import qualified Data.ByteString.Lazy.Char8 as LCBS
12
13import Control.Monad
9 14
10import Control.Monad 15import Control.Monad
11 16
12import Text.Show.Pretty (dumpStr) 17import Text.Show.Pretty (dumpStr)
18import Data.Aeson.Encode.Pretty (encodePretty)
13 19
14import System.IO 20import System.IO
15 21
@@ -19,9 +25,22 @@ import Options
19import Debug.Trace 25import Debug.Trace
20 26
21main :: IO () 27main :: IO ()
22main = withArgs (tprint <=< dumpOpts) 28main = withArgs (main' <=< dumpOpts)
23 where 29 where
24 dumpOpts c@(TPrint{..}) = c <$ when (dumpOptions) (hPutStrLn stderr $ dumpStr c) 30 dumpOpts c@(TPrint{..}) = c <$ when (dumpOptions) (hPutStrLn stderr $ dumpStr c)
25 31 main' config@(TPrint{..}) = withOutput config $ tprint config (mkClient' baseUrl)
26tprint :: TPrint -> IO () 32
27tprint = undefined 33withOutput :: TPrint -> (Handle -> IO a) -> IO a
34withOutput TPrint{..} a
35 | (_, WriteFile f) <- output = withFile f WriteMode a
36 | otherwise = a stdout
37
38tprint :: TPrint -> Client IO -> Handle -> IO ()
39tprint TPrint{ operation = Printers, ..} Client{..} out = printers >>= format
40 where format ps
41 | (Human, _) <- output = mapM_ (\(PrinterId n, st) -> hPutStrLn out $ show n ++ "\t" ++ humanStatus st) $ Map.toAscList ps
42 | (JSON , _) <- output = LCBS.hPutStrLn out $ encodePretty ps
43 | otherwise = hPutStrLn out . dumpStr $ Map.toAscList ps
44 humanStatus (Busy (JobId n)) = "busy printing job #" ++ show n
45 humanStatus (Available) = "available"
46tprint _ _ _ = undefined
diff --git a/tprint/src/Options.hs b/tprint/src/Options.hs
index 4b61d1c..30350cb 100644
--- a/tprint/src/Options.hs
+++ b/tprint/src/Options.hs
@@ -80,8 +80,8 @@ data Sink = Stdout | WriteFile FilePath
80 deriving (Show, Generic, PrettyVal) 80 deriving (Show, Generic, PrettyVal)
81 81
82supportedInputs, supportedOutputs :: [Format] 82supportedInputs, supportedOutputs :: [Format]
83supportedInputs = [BBCode] 83supportedInputs = [BBCode, JSON]
84supportedOutputs = [Human] 84supportedOutputs = [Human, Internal, JSON]
85 85
86cmdPrinters, cmdJobs, cmdJobCreate, cmdJob, cmdJobStatus, cmdJobDelete, cmdDrafts, cmdDraftCreate, cmdDraftReplace, cmdDraft, cmdDraftDelete, cmdDraftPrint :: ParserInfo Operation 86cmdPrinters, cmdJobs, cmdJobCreate, cmdJob, cmdJobStatus, cmdJobDelete, cmdDrafts, cmdDraftCreate, cmdDraftReplace, cmdDraft, cmdDraftDelete, cmdDraftPrint :: ParserInfo Operation
87cmdPrinters = info cmdPrinters' $ progDesc "List all available printers" 87cmdPrinters = info cmdPrinters' $ progDesc "List all available printers"
diff --git a/tprint/tprint.cabal b/tprint/tprint.cabal
index aeb61c9..9531665 100644
--- a/tprint/tprint.cabal
+++ b/tprint/tprint.cabal
@@ -30,6 +30,8 @@ executable tprint
30 , time >=1.5.0 && <2 30 , time >=1.5.0 && <2
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
34 , bytestring >=0.10.6 && <1
33 hs-source-dirs: src 35 hs-source-dirs: src
34 default-language: Haskell2010 36 default-language: Haskell2010
35 ghc-options: -Wall \ No newline at end of file 37 ghc-options: -Wall \ No newline at end of file
diff --git a/tprint/tprint.nix b/tprint/tprint.nix
index 9954b02..e28204d 100644
--- a/tprint/tprint.nix
+++ b/tprint/tprint.nix
@@ -1,5 +1,6 @@
1{ mkDerivation, base, containers, optparse-applicative, pretty-show 1{ mkDerivation, aeson-pretty, base, bytestring, containers
2, stdenv, thermoprint-bbcode, thermoprint-client, time 2, optparse-applicative, pretty-show, stdenv, text
3, thermoprint-bbcode, thermoprint-client, time
3}: 4}:
4mkDerivation { 5mkDerivation {
5 pname = "tprint"; 6 pname = "tprint";
@@ -8,8 +9,8 @@ mkDerivation {
8 isLibrary = false; 9 isLibrary = false;
9 isExecutable = true; 10 isExecutable = true;
10 executableHaskellDepends = [ 11 executableHaskellDepends = [
11 base containers optparse-applicative pretty-show thermoprint-bbcode 12 aeson-pretty base bytestring containers optparse-applicative
12 thermoprint-client time 13 pretty-show text thermoprint-bbcode thermoprint-client time
13 ]; 14 ];
14 homepage = "http://dirty-haskell.org/tags/thermoprint.html"; 15 homepage = "http://dirty-haskell.org/tags/thermoprint.html";
15 description = "A CLI for thermoprint-client"; 16 description = "A CLI for thermoprint-client";