diff options
Diffstat (limited to 'src/Erebos')
| -rw-r--r-- | src/Erebos/TextFormat.hs | 13 | ||||
| -rw-r--r-- | src/Erebos/TextFormat/Ansi.hs | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/Erebos/TextFormat.hs b/src/Erebos/TextFormat.hs index 0bfad75..20973d9 100644 --- a/src/Erebos/TextFormat.hs +++ b/src/Erebos/TextFormat.hs @@ -1,16 +1,29 @@ module Erebos.TextFormat ( FormattedText, + plainText, renderPlainText, + formattedTextLength, ) where import Data.Text (Text) +import Data.Text qualified as T import Erebos.TextFormat.Types +plainText :: Text -> FormattedText +plainText = PlainText + + renderPlainText :: FormattedText -> Text renderPlainText = \case PlainText text -> text ConcatenatedText ftexts -> mconcat $ map renderPlainText ftexts FormattedText _ ftext -> renderPlainText ftext + +formattedTextLength :: FormattedText -> Int +formattedTextLength = \case + PlainText text -> T.length text + ConcatenatedText ftexts -> sum $ map formattedTextLength ftexts + FormattedText _ ftext -> formattedTextLength ftext diff --git a/src/Erebos/TextFormat/Ansi.hs b/src/Erebos/TextFormat/Ansi.hs index 504e098..c0ff978 100644 --- a/src/Erebos/TextFormat/Ansi.hs +++ b/src/Erebos/TextFormat/Ansi.hs @@ -9,6 +9,7 @@ module Erebos.TextFormat.Ansi ( import Control.Applicative +import Data.String import Data.Text (Text) import Data.Text qualified as T @@ -16,6 +17,8 @@ import Erebos.TextFormat.Types newtype AnsiText = AnsiText { fromAnsiText :: Text } + deriving (Eq, Ord, Semigroup, Monoid, IsString) + renderAnsiText :: FormattedText -> AnsiText renderAnsiText = AnsiText . go ( Nothing, Nothing ) |