diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-08-29 12:15:10 +0200 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-08-29 12:15:10 +0200 |
| commit | 9e45b6638fb32b0ca20514db8a53c545902c91af (patch) | |
| tree | 8923f465b7c6ab7f6a66abc409434282ba739cd1 /src/TextFormat/Types.hs | |
| parent | ce9bb87a06a440ebb200d2caa7c919805712f0b1 (diff) | |
Diffstat (limited to 'src/TextFormat/Types.hs')
| -rw-r--r-- | src/TextFormat/Types.hs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/TextFormat/Types.hs b/src/TextFormat/Types.hs new file mode 100644 index 0000000..40deabd --- /dev/null +++ b/src/TextFormat/Types.hs @@ -0,0 +1,58 @@ +module TextFormat.Types ( + FormattedText(..), + TextStyle(..), + Color(..), +) where + +import Data.String +import Data.Text (Text) + + +data FormattedText + = PlainText Text + | ConcatenatedText [ FormattedText ] + | FormattedText TextStyle FormattedText + | EndWithNewline 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) |