summaryrefslogtreecommitdiff
path: root/src/Erebos/TextFormat.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Erebos/TextFormat.hs')
-rw-r--r--src/Erebos/TextFormat.hs13
1 files changed, 13 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