summaryrefslogtreecommitdiff
path: root/src/Erebos/TextFormat.hs
blob: 20973d91f3db8161774213e05431b425c28b7df9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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