diff options
| -rw-r--r-- | main/Main.hs | 18 | ||||
| -rw-r--r-- | src/Erebos/Conversation.hs | 11 |
2 files changed, 20 insertions, 9 deletions
diff --git a/main/Main.hs b/main/Main.hs index def3b8c..5496315 100644 --- a/main/Main.hs +++ b/main/Main.hs @@ -444,7 +444,7 @@ interactiveLoop st opts = withTerminal commandCompletion $ \term -> do SelectedConversation conv -> return $ conversationPeer conv _ -> return Nothing when (not tui || maybe False (msgPeer cur `sameIdentity`) mbpid) $ do - line <- printLine term $ formatMessageFT tzone $ makeMessage new msg + line <- printLine term $ formatMessageLine tzone $ makeMessage new msg modifyMVar_ currentLinesVar $ return . (line :) case optDmBotEcho opts of @@ -735,6 +735,18 @@ cmdPutStrLn str = do term <- asks ciTerminal void $ liftIO $ printLine term str +formatMessageLine :: TimeZone -> Message -> FormattedText +formatMessageLine tzone msg = mconcat + [ formatMessageStatus msg + , formatMessageFT tzone msg + ] + +formatMessageStatus :: Message -> FormattedText +formatMessageStatus msg + | messageUnread msg = withStyle (setForegroundColor BrightYellow noStyle) $ plainText " * " + | otherwise = plainText " " + + cmdUnknown :: String -> Command cmdUnknown cmd = cmdPutStrLn $ withStyle (setForegroundColor BrightRed noStyle) $ plainText $ "Unknown command: ‘" <> T.pack cmd <> "’" @@ -835,7 +847,7 @@ cmdSelectContext = do Right conv -> do liftIO $ updatePromptStatus term h (Just conv) tzone <- liftIO $ getCurrentTimeZone - tlines <- liftIO $ mapM (printLine term . formatMessageFT tzone) $ + tlines <- liftIO $ mapM (printLine term . formatMessageLine tzone) $ reverse $ takeWhile messageUnread $ conversationHistory conv var <- asks ciCurrentLinesVar liftIO $ modifyMVar_ var $ \_ -> return (reverse tlines) @@ -860,7 +872,7 @@ cmdHistory = void $ do thread@(_:_) -> do tzone <- liftIO $ getCurrentTimeZone term <- asks ciTerminal - tlines <- liftIO $ mapM (printLine term . formatMessageFT tzone) $ reverse $ take 50 thread + tlines <- liftIO $ mapM (printLine term . formatMessageLine tzone) $ reverse $ take 50 thread var <- asks ciCurrentLinesVar liftIO $ modifyMVar_ var $ \_ -> return (reverse tlines) [] -> do diff --git a/src/Erebos/Conversation.hs b/src/Erebos/Conversation.hs index 1c2b340..0e6690e 100644 --- a/src/Erebos/Conversation.hs +++ b/src/Erebos/Conversation.hs @@ -74,12 +74,11 @@ formatMessage :: TimeZone -> Message -> String formatMessage tzone = T.unpack . renderPlainText . formatMessageFT tzone formatMessageFT :: TimeZone -> Message -> FormattedText -formatMessageFT tzone msg = - (if messageUnread msg then FormattedText (CustomTextColor (Just BrightYellow) Nothing) else id) $ mconcat - [ PlainText $ T.pack $ formatTime defaultTimeLocale "[%H:%M] " $ utcToLocalTime tzone $ zonedTimeToUTC $ messageTime msg - , maybe "<unnamed>" PlainText $ idName $ messageFrom msg - , maybe "" ((": " <>) . PlainText) $ messageText msg - ] +formatMessageFT tzone msg = mconcat + [ PlainText $ T.pack $ formatTime defaultTimeLocale "[%H:%M] " $ utcToLocalTime tzone $ zonedTimeToUTC $ messageTime msg + , maybe "<unnamed>" PlainText $ idName $ messageFrom msg + , maybe "" ((": " <>) . PlainText) $ messageText msg + ] data Conversation |