mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
terminal: command to show the most recent chats (#1756)
* terminal: command to show the list of the last active chats * indent for chats without messages, help * update command in the test
This commit is contained in:
committed by
GitHub
parent
af414d7f6e
commit
774af334fd
@@ -1,5 +1,6 @@
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Simplex.Chat.Styled
|
||||
( StyledString (..),
|
||||
@@ -9,6 +10,7 @@ module Simplex.Chat.Styled
|
||||
unStyle,
|
||||
sLength,
|
||||
sShow,
|
||||
sTake,
|
||||
)
|
||||
where
|
||||
|
||||
@@ -25,7 +27,7 @@ data StyledString = Styled [SGR] String | StyledString :<>: StyledString
|
||||
|
||||
instance Semigroup StyledString where (<>) = (:<>:)
|
||||
|
||||
instance Monoid StyledString where mempty = plain ""
|
||||
instance Monoid StyledString where mempty = ""
|
||||
|
||||
instance IsString StyledString where fromString = plain
|
||||
|
||||
@@ -34,7 +36,7 @@ styleMarkdown (s1 :|: s2) = styleMarkdown s1 <> styleMarkdown s2
|
||||
styleMarkdown (Markdown f s) = styleFormat f s
|
||||
|
||||
styleMarkdownList :: MarkdownList -> StyledString
|
||||
styleMarkdownList [] = plain ""
|
||||
styleMarkdownList [] = ""
|
||||
styleMarkdownList [FormattedText f s] = styleFormat f s
|
||||
styleMarkdownList (FormattedText f s : ts) = styleFormat f s <> styleMarkdownList ts
|
||||
|
||||
@@ -82,3 +84,15 @@ unStyle (s1 :<>: s2) = unStyle s1 <> unStyle s2
|
||||
sLength :: StyledString -> Int
|
||||
sLength (Styled _ s) = length s
|
||||
sLength (s1 :<>: s2) = sLength s1 + sLength s2
|
||||
|
||||
sTake :: Int -> StyledString -> StyledString
|
||||
sTake n = go Nothing 0
|
||||
where
|
||||
go res len = \case
|
||||
Styled f s ->
|
||||
let s' = Styled f $ take (n - len) s
|
||||
in maybe id (<>) res s'
|
||||
s1 :<>: s2 ->
|
||||
let s1' = go res len s1
|
||||
len' = sLength s1'
|
||||
in if len' >= n then s1' else go (Just s1') len' s2
|
||||
|
||||
Reference in New Issue
Block a user