diff options
author | joe <joe@jerkface.net> | 2018-06-21 01:26:58 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-21 02:56:33 -0400 |
commit | 8cdc2de72ebe8945ce4b9f7fe8890970c34135a1 (patch) | |
tree | 99d8cbbaa46f089716f101058d0442b28f762bd8 /Presence/ConsoleWriter.hs | |
parent | 458c7a99e07300cde99826f825c3d0d6a7eab298 (diff) |
Avoid awkward "flip (maybe ...)" pattern.
Diffstat (limited to 'Presence/ConsoleWriter.hs')
-rw-r--r-- | Presence/ConsoleWriter.hs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/Presence/ConsoleWriter.hs b/Presence/ConsoleWriter.hs index b80e477a..6b611e68 100644 --- a/Presence/ConsoleWriter.hs +++ b/Presence/ConsoleWriter.hs | |||
@@ -38,7 +38,7 @@ import UTmp ( users2, utmp_file, UtmpRecord(..), UT_Type(..) ) | |||
38 | import FGConsole ( forkTTYMonitor ) | 38 | import FGConsole ( forkTTYMonitor ) |
39 | import XMPPServer ( Stanza, makePresenceStanza, JabberShow(..), stanzaType | 39 | import XMPPServer ( Stanza, makePresenceStanza, JabberShow(..), stanzaType |
40 | , LangSpecificMessage(..), msgLangMap, cloneStanza, stanzaFrom ) | 40 | , LangSpecificMessage(..), msgLangMap, cloneStanza, stanzaFrom ) |
41 | import ControlMaybe ( handleIO_ ) | 41 | import ControlMaybe |
42 | import ClientState | 42 | import ClientState |
43 | 43 | ||
44 | data ConsoleWriter = ConsoleWriter | 44 | data ConsoleWriter = ConsoleWriter |
@@ -95,9 +95,8 @@ onLogin cs start = \e -> do | |||
95 | let getActive = do | 95 | let getActive = do |
96 | tty <- readTVar $ csActiveTTY cs | 96 | tty <- readTVar $ csActiveTTY cs |
97 | utmp <- readTVar $ csUtmp cs | 97 | utmp <- readTVar $ csUtmp cs |
98 | flip (maybe $ return (tty,Nothing)) | 98 | fromMaybe (return (tty,Nothing)) |
99 | (Map.lookup ("tty"<>tshow tty) utmp) | 99 | $ Map.lookup ("tty"<>tshow tty) utmp <&> \tuvar -> do |
100 | $ \tuvar -> do | ||
101 | tu <- readTVar tuvar | 100 | tu <- readTVar tuvar |
102 | return (tty,tu) | 101 | return (tty,tu) |
103 | 102 | ||
@@ -201,13 +200,14 @@ messageText msg = do | |||
201 | pref <- getPreferedLang | 200 | pref <- getPreferedLang |
202 | let m = msgLangMap (stanzaType msg) | 201 | let m = msgLangMap (stanzaType msg) |
203 | key = lookupLang [pref] (map fst m) | 202 | key = lookupLang [pref] (map fst m) |
204 | choice = do | 203 | mchoice = do |
205 | k <- key | 204 | k <- key |
206 | lookup k m | 205 | lookup k m |
207 | flip (maybe $ return "") choice $ \choice -> do | 206 | return $ fromMaybe "" $ do |
208 | let subj = fmap ("Subject: " <>) $ msgSubject choice | 207 | choice <- mchoice |
209 | ts = catMaybes [subj, msgBody choice] | 208 | let subj = fmap ("Subject: " <>) $ msgSubject choice |
210 | return $ Text.intercalate "\n\n" ts | 209 | ts = catMaybes [subj, msgBody choice] |
210 | return $ Text.intercalate "\n\n" ts | ||
211 | 211 | ||
212 | readEnvFile :: String -> FilePath -> IO (Maybe String) | 212 | readEnvFile :: String -> FilePath -> IO (Maybe String) |
213 | readEnvFile var file = fmap parse $ readFile file | 213 | readEnvFile var file = fmap parse $ readFile file |
@@ -238,7 +238,7 @@ writeActiveTTY cw msg = do | |||
238 | $ Map.lookup ("tty"<>tshow num) utmp | 238 | $ Map.lookup ("tty"<>tshow num) utmp |
239 | return ( "/dev/tty" <> tshow num | 239 | return ( "/dev/tty" <> tshow num |
240 | , mbu ) | 240 | , mbu ) |
241 | flip (maybe $ return False) mbu $ \utmp -> do | 241 | fromMaybe (return False) $ mbu <&> \utmp -> do |
242 | display <- fmap (fmap Text.pack) | 242 | display <- fmap (fmap Text.pack) |
243 | $ readEnvFile "DISPLAY" ("/proc/" ++ show (utmpPid utmp) ++ "/environ") | 243 | $ readEnvFile "DISPLAY" ("/proc/" ++ show (utmpPid utmp) ++ "/environ") |
244 | case fmap (==utmpHost utmp) display of | 244 | case fmap (==utmpHost utmp) display of |
@@ -325,7 +325,7 @@ newCon log cw activeTTY utmp = do | |||
325 | ((tty,tu),u) <- atomically $ | 325 | ((tty,tu),u) <- atomically $ |
326 | liftM2 (,) activeTTY | 326 | liftM2 (,) activeTTY |
327 | (readTVar utmp) | 327 | (readTVar utmp) |
328 | flip (maybe $ return ()) u $ \u -> do | 328 | forM_ u $ \u -> do |
329 | jid <- ujid u | 329 | jid <- ujid u |
330 | log $ status (resource u) tty tu <> " " <> jid <> " pid=" <> tshow (utmpPid u) | 330 | log $ status (resource u) tty tu <> " " <> jid <> " pid=" <> tshow (utmpPid u) |
331 | <> (if istty (resource u) | 331 | <> (if istty (resource u) |