dog-food: distinguish self from contacts (#42)

* dog-food: distinguish self from contacts

* add missing space

* rename tty functions

* return indents

* remove indentation in sent messages

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
Efim Poberezkin 2021-02-15 23:00:19 +04:00
parent 3de4fa7518
commit be17af4321

17
Main.hs
View File

@ -97,7 +97,7 @@ serializeChatResponse name = \case
ChatHelpInfo -> chatHelpInfo
Invitation qInfo -> "ask your contact to enter: /accept " <> showName name <> " " <> serializeSmpQueueInfo qInfo
Connected c -> ttyContact c <> " connected"
ReceivedMessage c t -> ttyContact c <> ": " <> t
ReceivedMessage c t -> ttyFromContact c <> " " <> t
Disconnected c -> "disconnected from " <> ttyContact c <> " - try \"/chat " <> toBs c <> "\""
YesYes -> "you got it!"
ErrorInput t -> "invalid input: " <> t
@ -236,7 +236,7 @@ getChatLn t = do
getWithContact :: Contact -> ByteString -> IO ByteString
getWithContact a s = do
C.cursorBackward 1
B.hPut stdout $ " " <> ttyContact a <> " " <> s
B.hPut stdout $ ttyToContact a <> " " <> s
getRest $ "@" <> toBs a <> " " <> s
getRest :: ByteString -> IO ByteString
getRest s = do
@ -249,10 +249,19 @@ setTTY mode = do
hSetBuffering stdout mode
ttyContact :: Contact -> ByteString
ttyContact (Contact a) = withSGR contactSGR $ "@" <> a
ttyContact (Contact a) = withSGR contactSGR a
ttyFromContact :: Contact -> ByteString
ttyFromContact (Contact a) = withSGR contactSGR $ a <> ">"
ttyToContact :: Contact -> ByteString
ttyToContact (Contact a) = withSGR selfSGR $ "@" <> a
contactSGR :: [C.SGR]
contactSGR = [C.SetColor C.Foreground C.Vivid C.Cyan]
contactSGR = [C.SetColor C.Foreground C.Vivid C.Yellow]
selfSGR :: [C.SGR]
selfSGR = [C.SetColor C.Foreground C.Vivid C.Cyan]
withSGR :: [C.SGR] -> ByteString -> ByteString
withSGR sgr s = B.pack (C.setSGRCode sgr) <> s <> B.pack (C.setSGRCode [C.Reset])