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.hs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/Erebos/TextFormat.hs b/src/Erebos/TextFormat.hs
new file mode 100644
index 0000000..20973d9
--- /dev/null
+++ b/src/Erebos/TextFormat.hs
@@ -0,0 +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