irc-fun-color- Add color and style decorations to IRC messages.

Safe HaskellNone




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:

  1. Construct the string using combinators
  2. 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) color
  • Decoration : Choose a decoration style, e.g. bold or underline
  • fg : Choose a foreground color, you can use the Color itself directly
  • bg : Choose background color
  • fgBg : 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 Texts 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"


Primary Toolkit

data Color Source

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

Create plain text using formatting. This is simply a shortcut that is equivalent to using format to get a strict Text and applying plain to that.

fg :: Color -> FgBg Source

Create a foreground color style with a given color.

bg :: Color -> FgBg Source

Create a background color style with a given color.

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

class Style s where Source

A class for types which add style formatting to a string. This is what makes '()' work.


style :: s -> StyledText -> StyledText Source

data StyledText Source

A string tagged with style attributes.

data FgBg Source

A color decoration, specifying text foreground and background colors.


data RGB a Source

A color specified by its red, green and blue components.


RGB a a a 


Eq a => Eq (RGB a) Source 
Show a => Show (RGB a) Source 

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.