diff --git a/app/Api/Types.hs b/app/Api/Types.hs index 1be76e9..d2c2e43 100644 --- a/app/Api/Types.hs +++ b/app/Api/Types.hs @@ -33,6 +33,14 @@ data Section = Section { id :: Integer instance NFData Section instance FromJSON Section +instance PrintColor Section where + printColor Section{id = thread_id, thread_group_name, description} = do + withSgr [SetUnderlining SingleUnderline] do + putTextO thread_group_name + withSgr [SetColor Foreground Dull White] do + putTextLnO $ " #" <> show thread_id + putTextLnO description + data GetTopics = GetTopics instance ToForm GetTopics where toForm GetTopics = Form $ M.fromList [("type", ["threads"]), ("key", ["anon"])] @@ -44,6 +52,16 @@ data TopicInfo = TopicInfo { id, group_id, nbr_ansfers :: Integer instance NFData TopicInfo instance FromJSON TopicInfo +instance PrintColor TopicInfo where + printColor TopicInfo{id = topic_id, thrname, last_activity_date, last_activity_user} = do + withSgr [SetUnderlining SingleUnderline] do + putTextO thrname + putTextO ": " + withSgr [SetPaletteColor Foreground (textColor last_activity_user)] do + putTextO $ "@" <> last_activity_user + withSgr [SetColor Foreground Dull White] do + putTextLnO $ " at " <> last_activity_date <> " #" <> show topic_id + data GetTopic = GetTopic { topic_id :: Integer } instance ToForm GetTopic where toForm GetTopic {topic_id} = Form $ M.fromList [ ("type", ["topic"]) diff --git a/app/Main.hs b/app/Main.hs index 18d338d..558104d 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -3,13 +3,14 @@ module Main (main) where import Relude hiding (Proxy) import Api qualified as Api +import Api.Types (last_activity_date) import Cli import Network.HTTP.Client import Polysemy (Member, Members, Sem) import Polysemy.Embed (Embed) import Polysemy.Error (Error, errorToIOFinal) import Polysemy.Output (Output) -import Polysemy.Output.IO (runOutputToStdout) +import Polysemy.Output.IO (putTextLnO, runOutputToStdout) import Polysemy.Sgr (Sgr, SgrRegion, ignoreSgrFull, runSgrFull, withSgr) import Polysemy.Final (Final, embedToFinal, runFinal) import Color.Print @@ -40,13 +41,16 @@ sgrFullInterpreter noAnsi = if noAnsi then ignoreSgrFull else runSgrFull program :: Members [Error ClientError, ServantClient, Output Text, Sgr, SgrRegion] r => Choice -> Sem r () -program GetSections = error "GetSections is not yet implemented" -program GetTopics = error "GetTopics is not yet implemented" -program GetTopic{topic_id} = showTopic topic_id - -showTopic :: Members [ServantClient, Error ClientError, Output Text, Sgr, SgrRegion] r - => Integer -> Sem r () -showTopic topic_id = do +program GetSections = do + sections <- Api.getSections + withSgr [SetColor Foreground Vivid White] do + sequenceA_ $ intersperse (putTextLnO "") (printColor <$> sections) +program GetTopics = do + topics <- Api.getTopics + withSgr [SetColor Foreground Vivid White] do + sequenceA_ $ intersperse (putTextLnO "") + (fmap printColor . reverse $ sortBy (comparing (.last_activity_date)) topics) +program GetTopic{topic_id} = do topic <- Api.getTopic topic_id withSgr [SetColor Foreground Vivid White] do printColor topic