diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-03-01 10:11:47 +0100 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-03-01 10:11:47 +0100 |
| commit | 0ae7acc6217b1a06c8a1628c7a6dc2487ab55736 (patch) | |
| tree | 152aaadce2404819a1e96975d9f4a2f3d5d2fe15 | |
| parent | c2153f196c64593a252bc0fbbc3d503628fe896f (diff) | |
| download | thermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.tar thermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.tar.gz thermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.tar.bz2 thermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.tar.xz thermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.zip | |
jobs
| -rw-r--r-- | tprint/src/Main.hs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tprint/src/Main.hs b/tprint/src/Main.hs index a937181..dcdeb4f 100644 --- a/tprint/src/Main.hs +++ b/tprint/src/Main.hs | |||
| @@ -9,8 +9,11 @@ import Data.Text (Text) | |||
| 9 | import qualified Data.Text as T | 9 | import qualified Data.Text as T |
| 10 | import qualified Data.ByteString.Lazy.Char8 as Lazy (ByteString) | 10 | import qualified Data.ByteString.Lazy.Char8 as Lazy (ByteString) |
| 11 | import qualified Data.ByteString.Lazy.Char8 as LCBS | 11 | import qualified Data.ByteString.Lazy.Char8 as LCBS |
| 12 | import Data.Time | ||
| 12 | 13 | ||
| 13 | import Control.Monad | 14 | import Data.Foldable |
| 15 | import Data.List | ||
| 16 | import Data.Monoid | ||
| 14 | 17 | ||
| 15 | import Control.Monad | 18 | import Control.Monad |
| 16 | 19 | ||
| @@ -36,6 +39,7 @@ withOutput TPrint{..} a | |||
| 36 | | otherwise = a stdout | 39 | | otherwise = a stdout |
| 37 | 40 | ||
| 38 | tprint :: TPrint -> Client IO -> Handle -> IO () | 41 | tprint :: TPrint -> Client IO -> Handle -> IO () |
| 42 | |||
| 39 | tprint TPrint{ operation = Printers, ..} Client{..} out = printers >>= format | 43 | tprint TPrint{ operation = Printers, ..} Client{..} out = printers >>= format |
| 40 | where format ps | 44 | where format ps |
| 41 | | (Human, _) <- output = mapM_ (\(PrinterId n, st) -> hPutStrLn out $ show n ++ "\t" ++ humanStatus st) $ Map.toAscList ps | 45 | | (Human, _) <- output = mapM_ (\(PrinterId n, st) -> hPutStrLn out $ show n ++ "\t" ++ humanStatus st) $ Map.toAscList ps |
| @@ -43,4 +47,24 @@ tprint TPrint{ operation = Printers, ..} Client{..} out = printers >>= format | |||
| 43 | | otherwise = hPutStrLn out . dumpStr $ Map.toAscList ps | 47 | | otherwise = hPutStrLn out . dumpStr $ Map.toAscList ps |
| 44 | humanStatus (Busy (JobId n)) = "busy printing job #" ++ show n | 48 | humanStatus (Busy (JobId n)) = "busy printing job #" ++ show n |
| 45 | humanStatus (Available) = "available" | 49 | humanStatus (Available) = "available" |
| 50 | |||
| 51 | tprint TPrint{ operation = Jobs{..}, ..} Client{..} out = jobs printer jobRange timeRange >>= format | ||
| 52 | where format js | ||
| 53 | | (Human, _) <- output = mapM_ (\((JobId n), created, status) -> hPutStrLn out $ show n ++ "\t" ++ formatTime defaultTimeLocale "%Y-%m-%d %H:%M:%S %Z" created ++ "\t" ++ humanStatus status printer) . sortBy jSort $ toList js | ||
| 54 | | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty js | ||
| 55 | | otherwise = hPutStrLn out . dumpStr $ toList js | ||
| 56 | jSort (id, time, status) (id', time', status') = queueSort status status' <> compare time' time <> compare id id' | ||
| 57 | where | ||
| 58 | compare' :: Ord a => a -> a -> Ordering | ||
| 59 | compare' | ||
| 60 | | (Queued _) <- status = compare | ||
| 61 | | otherwise = flip compare | ||
| 62 | humanStatus (Queued (PrinterId n)) Nothing = "queued at printer #" ++ show n | ||
| 63 | humanStatus (Queued _) _ = "queued" | ||
| 64 | humanStatus (Printing (PrinterId n)) Nothing = "printing on printer #" ++ show n | ||
| 65 | humanStatus (Printing _) _ = "printing" | ||
| 66 | humanStatus (Done) _ = "finished successfully" | ||
| 67 | humanStatus (Failed err) _ = "failed: " ++ show err | ||
| 68 | |||
| 69 | |||
| 46 | tprint _ _ _ = undefined | 70 | tprint _ _ _ = undefined |
