aboutsummaryrefslogtreecommitdiff
path: root/tprint
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-03-01 11:25:04 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2016-03-01 11:25:04 +0100
commit4e434b328a0f6ddb0dc4ee333aa3135c1b271bf9 (patch)
tree48daaaf62658085ca1d32c84a1a61ecc8df20216 /tprint
parent83a51ef7d5b8b788a86b521d3ef421ebe068c197 (diff)
downloadthermoprint-4e434b328a0f6ddb0dc4ee333aa3135c1b271bf9.tar
thermoprint-4e434b328a0f6ddb0dc4ee333aa3135c1b271bf9.tar.gz
thermoprint-4e434b328a0f6ddb0dc4ee333aa3135c1b271bf9.tar.bz2
thermoprint-4e434b328a0f6ddb0dc4ee333aa3135c1b271bf9.tar.xz
thermoprint-4e434b328a0f6ddb0dc4ee333aa3135c1b271bf9.zip
minor code cleanup
Diffstat (limited to 'tprint')
-rw-r--r--tprint/src/Main.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/tprint/src/Main.hs b/tprint/src/Main.hs
index 5734e68..bc5ee2f 100644
--- a/tprint/src/Main.hs
+++ b/tprint/src/Main.hs
@@ -90,31 +90,31 @@ tprint TPrint{ operation = Printers, ..} Client{..} out = printers >>= format
90tprint TPrint{ operation = Jobs{..}, ..} Client{..} out = jobs printer jobRange timeRange >>= format 90tprint TPrint{ operation = Jobs{..}, ..} Client{..} out = jobs printer jobRange timeRange >>= format
91 where format js 91 where format js
92 | (Human, _) <- output = mapM_ (\((JobId n), created, status) -> hPutStrLn out $ show n ++ "\t" ++ formatTime defaultTimeLocale "%Y-%m-%d %H:%M:%S %Z" created ++ "\t" ++ humanJobStatus status printer) . sortBy jSort $ toList js 92 | (Human, _) <- output = mapM_ (\((JobId n), created, status) -> hPutStrLn out $ show n ++ "\t" ++ formatTime defaultTimeLocale "%Y-%m-%d %H:%M:%S %Z" created ++ "\t" ++ humanJobStatus status printer) . sortBy jSort $ toList js
93 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty js 93 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty js
94 | otherwise = hPutStrLn out . dumpStr $ toList js 94 | otherwise = hPutStrLn out . dumpStr $ toList js
95 jSort (id, time, status) (id', time', status') = queueSort status status' <> compare time' time <> compare id id' 95 jSort (id, time, status) (id', time', status') = queueSort status status' <> compare time' time <> compare id id'
96 96
97tprint TPrint{ operation = Drafts, ..} Client{..} out = drafts >>= format 97tprint TPrint{ operation = Drafts, ..} Client{..} out = drafts >>= format
98 where format ds 98 where format ds
99 | (Human, _) <- output = mapM_ (\(DraftId n, fromMaybe "" . fmap T.unpack -> t) -> hPutStrLn out $ show n ++ "\t" ++ t) $ Map.toAscList ds 99 | (Human, _) <- output = mapM_ (\(DraftId n, fromMaybe "" . fmap T.unpack -> t) -> hPutStrLn out $ show n ++ "\t" ++ t) $ Map.toAscList ds
100 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty ds 100 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty ds
101 | otherwise = hPutStrLn out . dumpStr $ Map.toAscList ds 101 | otherwise = hPutStrLn out . dumpStr $ Map.toAscList ds
102 102
103tprint TPrint{ operation = JobStatus{..}, ..} Client{..} out = jobStatus jobId >>= format 103tprint TPrint{ operation = JobStatus{..}, ..} Client{..} out = jobStatus jobId >>= format
104 where format s 104 where format s
105 | (Human, _) <- output = hPutStrLn out $ humanJobStatus s Nothing 105 | (Human, _) <- output = hPutStrLn out $ humanJobStatus s Nothing
106 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty s 106 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty s
107 | otherwise = hPutStrLn out $ dumpStr s 107 | otherwise = hPutStrLn out $ dumpStr s
108 108
109tprint TPrint{ operation = Job{..}, ..} Client{..} out = job jobId >>= format 109tprint TPrint{ operation = Job{..}, ..} Client{..} out = job jobId >>= format
110 where format p 110 where format p
111 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty p 111 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty p
112 | otherwise = T.hPutStrLn out =<< either throwM return (cobbcode p) 112 | otherwise = T.hPutStrLn out =<< either throwM return (cobbcode p)
113 113
114tprint TPrint{ operation = Draft{..}, ..} Client{..} out = draft draftId >>= format 114tprint TPrint{ operation = Draft{..}, ..} Client{..} out = draft draftId >>= format
115 where format d@(fromMaybe "" . fmap T.unpack -> t, p) 115 where format d@(fromMaybe "" . fmap T.unpack -> t, p)
116 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty d 116 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty d
117 | otherwise = do 117 | otherwise = do
118 hPutStrLn out t 118 hPutStrLn out t
119 hPutStrLn out "" 119 hPutStrLn out ""
120 T.hPutStrLn out =<< either throwM return (cobbcode p) 120 T.hPutStrLn out =<< either throwM return (cobbcode p)