summaryrefslogtreecommitdiff
path: root/src/Erebos/TextFormat/Types.hs
blob: a03bc717c9ab1cb2f8a0e31164e89c61be5f73d1 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Erebos.TextFormat.Types (
    FormattedText(..),
    TextStyle(..),
    Color(..),
) where

import Data.String
import Data.Text (Text)


data FormattedText
    = PlainText Text
    | ConcatenatedText [ FormattedText ]
    | FormattedText TextStyle FormattedText

instance IsString FormattedText where
    fromString = PlainText . fromString

instance Semigroup FormattedText where
    ConcatenatedText xs <> ConcatenatedText ys = ConcatenatedText (xs ++ ys)
    x <> ConcatenatedText ys = ConcatenatedText (x : ys)
    ConcatenatedText xs <> y = ConcatenatedText (xs ++ [ y ])
    x <> y = ConcatenatedText [ x, y ]

instance Monoid FormattedText where
    mempty = ConcatenatedText []
    mconcat [] = ConcatenatedText []
    mconcat [ x ] = x
    mconcat xs = ConcatenatedText $ concatMap flatten xs
      where
        flatten (ConcatenatedText ys) = ys
        flatten y = [ y ]


data TextStyle
    = CustomTextColor (Maybe Color) (Maybe Color)


data Color
    = DefaultColor
    | Black
    | Red
    | Green
    | Yellow
    | Blue
    | Magenta
    | Cyan
    | White
    | BrightBlack
    | BrightRed
    | BrightGreen
    | BrightYellow
    | BrightBlue
    | BrightMagenta
    | BrightCyan
    | BrightWhite
    deriving (Eq)