Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module allows you to add color and style to IRC text messages. Decoding style-encoded messages isn't implemented currently.
Building styled strings is done in two steps:
- Construct the string using combinators
- Encode it into the IRC message styling format
The result you get is a style-encoded Text
which you can send as an IRC
message (e.g. using PRIVMSG).
The combinators are:
- '#>',
<#
: Apply a style to a styled string <>
: Styles strings are monoids, use<>
to concatenate them
The tools for choosing styles for application are:
Color
: Choose a (foreground) colorDecoration
: Choose a decoration style, e.g. bold or underlinefg
: Choose a foreground color, you can use theColor
itself directlybg
: Choose background colorfgBg
: Choose both colors
Once you build the styled string, use encode
to obtain an encoded String
for use in IRC.
Here are some examples. I assume here the OverloadedStrings
extension is
enabled. If you prefer not to use it, you'll need to directly apply plain
to Text
s before styling (e.g. with '#>').
Green text:
Green #> "hello beautiful world"
The same, but without the extension mentioned above:
Green #> plain "hello beautiful world"
Bold text:
Bold #> "hello beautiful world"
Green text with some underlined text in the middle:
Green #> ("hello " <> Underline #> "beautiful" <> " world")
Red text on gray background:
Red `fgBg` Gray #> "hello beautiful world"
Text with a red underlined part in the middle, and the whole string with blue background:
("hello " <> Red #> Underline #> "beaufitul" <> " world") <# bg Blue
Three letters. The first is lime-on-black and bold. The second is black-on-line. The third is again lime-on-black, and italicized:
Lime `fgBg` Black #> (Bold #> "A" <> Reverse #> "B" <> Italic #> "C")
Bold, underlined purple-on-white text:
Bold #> Underline #> Purple `fgBg` White #> "hello beautiful world"
- data Color
- data Decoration
- (#>) :: Style s => s -> StyledText -> StyledText
- (<#) :: Style s => StyledText -> s -> StyledText
- plain :: Text -> StyledText
- fmt :: Format StyledText a -> a
- fg :: Color -> FgBg
- bg :: Color -> FgBg
- fgBg :: Color -> Color -> FgBg
- encode :: StyledText -> Text
- class Style s where
- style :: s -> StyledText -> StyledText
- data StyledText
- data FgBg
- data RGB a = RGB a a a
- toIrcRGB :: Num a => Color -> RGB a
- toTangoRGB :: Num a => Color -> RGB a
- strip :: StyledText -> Text
Primary Toolkit
One of the 16 available color codes.
data Decoration Source
A text decoration style.
(#>) :: Style s => s -> StyledText -> StyledText infixr 7 Source
Apply a style to a given string.
(<#) :: Style s => StyledText -> s -> StyledText infixl 7 Source
Apply a style to a given string.
plain :: Text -> StyledText Source
Create a plain-text styled text.
fmt :: Format StyledText a -> a Source
fgBg :: Color -> Color -> FgBg Source
Create a color style with a given foreground and background colors.
encode :: StyledText -> Text Source
Convert a styled string value into an IRC style-coded text message.
Underlying Types
style :: s -> StyledText -> StyledText Source
data StyledText Source
A string tagged with style attributes.
A color decoration, specifying text foreground and background colors.
Utilities
A color specified by its red, green and blue components.
RGB a a a |
toIrcRGB :: Num a => Color -> RGB a Source
Return the default RGB values of IRC colors. Client often allow the user to change the values, but these are the defaults.
toTangoRGB :: Num a => Color -> RGB a Source
Return RGB values for color codes, using the Tango color scheme. It is a rough mapping between IRC color names and the 16 terminal colors.
strip :: StyledText -> Text Source
Remove style from a string, returning just the content.