diff options
-rw-r--r-- | tprint/src/Instances.hs | 6 | ||||
-rw-r--r-- | tprint/src/Main.hs | 27 | ||||
-rw-r--r-- | tprint/src/Options.hs | 4 | ||||
-rw-r--r-- | tprint/tprint.cabal | 2 | ||||
-rw-r--r-- | tprint/tprint.nix | 9 |
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) | |||
8 | import Text.Show.Pretty (Value, PrettyVal(..), dumpStr) | 8 | import Text.Show.Pretty (Value, PrettyVal(..), dumpStr) |
9 | import qualified Text.Show.Pretty as PShow (Value(..)) | 9 | import qualified Text.Show.Pretty as PShow (Value(..)) |
10 | 10 | ||
11 | import Thermoprint.Client (Scheme(..), BaseUrl(..), PrinterId(..), JobId(..), DraftId(..), Range(..)) | 11 | import Thermoprint.Client (Scheme(..), BaseUrl(..), PrinterId(..), JobId(..), DraftId(..), Range(..), PrinterStatus(..), JobStatus(..), PrintingError(..), EncodingException(..)) |
12 | 12 | ||
13 | instance PrettyVal Scheme | 13 | instance PrettyVal Scheme |
14 | instance PrettyVal BaseUrl | 14 | instance PrettyVal BaseUrl |
@@ -23,3 +23,7 @@ instance PrettyVal UTCTime where | |||
23 | instance PrettyVal Text where | 23 | instance PrettyVal Text where |
24 | prettyVal = prettyVal . T.unpack | 24 | prettyVal = prettyVal . T.unpack |
25 | 25 | ||
26 | instance PrettyVal PrinterStatus | ||
27 | instance PrettyVal JobStatus | ||
28 | instance PrettyVal PrintingError | ||
29 | instance 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 | ||
3 | import Data.Map (Map) | 4 | import Data.Map (Map) |
4 | import qualified Data.Map as Map | 5 | import qualified Data.Map as Map |
@@ -6,10 +7,15 @@ import Data.Sequence (Seq) | |||
6 | import qualified Data.Sequence as Seq | 7 | import qualified Data.Sequence as Seq |
7 | import Data.Text (Text) | 8 | import Data.Text (Text) |
8 | import qualified Data.Text as T | 9 | import qualified Data.Text as T |
10 | import qualified Data.ByteString.Lazy.Char8 as Lazy (ByteString) | ||
11 | import qualified Data.ByteString.Lazy.Char8 as LCBS | ||
12 | |||
13 | import Control.Monad | ||
9 | 14 | ||
10 | import Control.Monad | 15 | import Control.Monad |
11 | 16 | ||
12 | import Text.Show.Pretty (dumpStr) | 17 | import Text.Show.Pretty (dumpStr) |
18 | import Data.Aeson.Encode.Pretty (encodePretty) | ||
13 | 19 | ||
14 | import System.IO | 20 | import System.IO |
15 | 21 | ||
@@ -19,9 +25,22 @@ import Options | |||
19 | import Debug.Trace | 25 | import Debug.Trace |
20 | 26 | ||
21 | main :: IO () | 27 | main :: IO () |
22 | main = withArgs (tprint <=< dumpOpts) | 28 | main = 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) | |
26 | tprint :: TPrint -> IO () | 32 | |
27 | tprint = undefined | 33 | withOutput :: TPrint -> (Handle -> IO a) -> IO a |
34 | withOutput TPrint{..} a | ||
35 | | (_, WriteFile f) <- output = withFile f WriteMode a | ||
36 | | otherwise = a stdout | ||
37 | |||
38 | tprint :: TPrint -> Client IO -> Handle -> IO () | ||
39 | tprint 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" | ||
46 | tprint _ _ _ = 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 | ||
82 | supportedInputs, supportedOutputs :: [Format] | 82 | supportedInputs, supportedOutputs :: [Format] |
83 | supportedInputs = [BBCode] | 83 | supportedInputs = [BBCode, JSON] |
84 | supportedOutputs = [Human] | 84 | supportedOutputs = [Human, Internal, JSON] |
85 | 85 | ||
86 | cmdPrinters, cmdJobs, cmdJobCreate, cmdJob, cmdJobStatus, cmdJobDelete, cmdDrafts, cmdDraftCreate, cmdDraftReplace, cmdDraft, cmdDraftDelete, cmdDraftPrint :: ParserInfo Operation | 86 | cmdPrinters, cmdJobs, cmdJobCreate, cmdJob, cmdJobStatus, cmdJobDelete, cmdDrafts, cmdDraftCreate, cmdDraftReplace, cmdDraft, cmdDraftDelete, cmdDraftPrint :: ParserInfo Operation |
87 | cmdPrinters = info cmdPrinters' $ progDesc "List all available printers" | 87 | cmdPrinters = 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 | }: |
4 | mkDerivation { | 5 | mkDerivation { |
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"; |