From 5f0d519e73baf763c8caeab10d90fa9a55dc71b8 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 16 Mar 2014 14:22:55 -0400 Subject: write to terminal --- Presence/ConsoleWriter.hs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Presence/ConsoleWriter.hs b/Presence/ConsoleWriter.hs index d75dfec0..aca4bf98 100644 --- a/Presence/ConsoleWriter.hs +++ b/Presence/ConsoleWriter.hs @@ -240,12 +240,23 @@ deliverTerminalMessage cw tty utmp msg = do mode <- fmap fileMode (getFileStatus $ Text.unpack tty) let mesgy = mode .&. 0o020 /= 0 -- verify mode g+w if not mesgy then return False else do - -- TODO: deliver to active console - return False -- return True if a message was delivered + text <- do + t <- messageText msg + return $ Text.unpack + $ case stanzaFrom msg of + Just from -> from <> " says...\n" <> t + Nothing -> t + writeFile (Text.unpack tty) text + return True -- return True if a message was delivered writeAllPty :: ConsoleWriter -> Stanza -> IO Bool writeAllPty cw msg = do - return False -- return True if a message was delivered + us <- atomically $ readTVar (csUtmp cw) + let ptys = Map.filterWithKey ispty us + ispty k _ = "pts/" `Text.isPrefixOf` k + bs <- forM (Map.toList ptys) $ \(tty,utmp) -> do + deliverTerminalMessage cw tty utmp msg + return $ or bs resource :: UtmpRecord -> Text resource u = -- cgit v1.2.3