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

Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.IRC.Fun.Color

Contents

Description

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 String 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 Pure or fromString to Strings before styling (e.g. with '#>').

Green text:

Green #> "hello beautiful world"

The same, but without the extension mentioned above:

Green #> Pure "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"

Synopsis

Primary Toolkit

data Color Source

One of the 16 available color codes.

data Decoration Source

A text decoration style.

Constructors

Bold 
Italic 
Underline 
Reverse 

(#>) :: Style s => s -> StyledString -> StyledString infixr 7 Source

Apply a style to a given string.

(<#) :: Style s => StyledString -> s -> StyledString infixl 7 Source

Apply a style to a given string.

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 :: StyledString -> String 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.

data FgBg Source

A color decoration, specifying text foreground and background colors.

Constructors

FgBg (Maybe Color) (Maybe Color) 

Instances

Utilities

data RGB a Source

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

Constructors

RGB a a a 

Instances

Eq a => Eq (RGB a) 
Show a => Show (RGB 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 :: StyledString -> String Source

Remove style from a string, returning just the content.