summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-02-04 21:05:30 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2026-02-04 21:05:30 +0100
commitf3f03c0111729633e4026ce398ac60725e1bc1ba (patch)
treee4b71a74f4206eb76e54466dc18892976e09f6be
parent449df6e7eb7961fabde978bebd804fd35e298367 (diff)
Show number of conversations with unread messages in CLI prompt
Changelog: Show the number of conversations with unread messages in CLI prompt
-rw-r--r--main/Main.hs21
-rw-r--r--src/Erebos/TextFormat.hs19
2 files changed, 40 insertions, 0 deletions
diff --git a/main/Main.hs b/main/Main.hs
index 5fca2d9..0ab474d 100644
--- a/main/Main.hs
+++ b/main/Main.hs
@@ -418,6 +418,9 @@ interactiveLoop st opts = withTerminal commandCompletion $ \term -> do
Left err -> extPrintLn $ "Failed to send dm echo: " <> err
_ -> return ()
+ updatePromptStatus term erebosHead
+ updatePromptStatus term erebosHead
+
peers <- liftIO $ newMVar []
contextOptions <- liftIO $ newMVar ( Nothing, [] )
chatroomSetVar <- liftIO $ newEmptyMVar
@@ -605,6 +608,24 @@ getSelectedOrManualContext = do
str | all isDigit str -> getContextByIndex id (read str)
_ -> throwOtherError "invalid index"
+updatePromptStatus :: Terminal -> Head LocalState -> IO ()
+updatePromptStatus term h = do
+ conversations <- mapMaybe checkNew <$> flip runReaderT h lookupConversations
+ setPromptStatus term $ withStyle (setForegroundColor BrightYellow noStyle) $ formatStatus (length conversations) <> " "
+ where
+ checkNew conv
+ | (msg : _) <- conversationHistory conv
+ , messageUnread msg
+ = Just ( conv, msg )
+ checkNew _ = Nothing
+
+ formatStatus 0 = withStyle (setForegroundColor BrightBlack noStyle) "--"
+ formatStatus 1 = withStyle (setForegroundColor BrightYellow noStyle) " *"
+ formatStatus n
+ | n < 10 = withStyle (setForegroundColor BrightYellow noStyle) $ plainText $ T.pack (show n) <> "*"
+ | otherwise = withStyle (setForegroundColor BrightYellow noStyle) $ plainText $ "X*"
+
+
commands :: [(String, Command)]
commands =
[ ( "history", cmdHistory )
diff --git a/src/Erebos/TextFormat.hs b/src/Erebos/TextFormat.hs
index 20973d9..88fe0c2 100644
--- a/src/Erebos/TextFormat.hs
+++ b/src/Erebos/TextFormat.hs
@@ -2,6 +2,12 @@ module Erebos.TextFormat (
FormattedText,
plainText,
+ TextStyle,
+ withStyle, noStyle,
+
+ Color(..),
+ setForegroundColor, setBackgroundColor,
+
renderPlainText,
formattedTextLength,
) where
@@ -16,6 +22,19 @@ plainText :: Text -> FormattedText
plainText = PlainText
+withStyle :: TextStyle -> FormattedText -> FormattedText
+withStyle = FormattedText
+
+noStyle :: TextStyle
+noStyle = CustomTextColor Nothing Nothing
+
+setForegroundColor :: Color -> TextStyle -> TextStyle
+setForegroundColor color (CustomTextColor _ bg) = CustomTextColor (Just color) bg
+
+setBackgroundColor :: Color -> TextStyle -> TextStyle
+setBackgroundColor color (CustomTextColor fg _) = CustomTextColor fg (Just color)
+
+
renderPlainText :: FormattedText -> Text
renderPlainText = \case
PlainText text -> text