-- ANSIColor.hs -- Tom Moertel -- CVS $Id: ANSIColor.hs,v 1.2 2002/09/06 04:03:51 thor Exp $ -- | The ANSIColor modules provides rudimentary support for ANSI -- color codes on terminal displays. module ANSIColor ( ANSICode(..), ANSIColor(..), acolorize, acode ) where data ANSICode = ANSI_Reset | ANSI_Bold Bool | ANSI_Underline Bool | ANSI_Inverse Bool | ANSI_Italics Bool | ANSI_Strikethru Bool | ANSI_Foreground ANSIColor | ANSI_Background ANSIColor deriving (Eq, Ord, Read, Show) data ANSIColor = ANSI_Black | ANSI_Red | ANSI_Green | ANSI_Yellow | ANSI_Blue | ANSI_Magenta | ANSI_Cyan | ANSI_White deriving (Eq, Ord, Read, Show, Enum) acolorize :: ANSICode -> String -> String acolorize ansicode s = acode ansicode ++ s ++ acode ANSI_Reset acode :: ANSICode -> String acode ansicode = "\ESC[" ++ codestr ++ "m" where codestr = case ansicode of ANSI_Reset -> "0" -- reset; clears all colors and styles ANSI_Bold True -> "1" -- bold on ANSI_Bold False -> "22" -- 2.50 bold off ANSI_Italics True -> "3" -- italics on ANSI_Italics False -> "23" -- 2.50 italics off ANSI_Underline True -> "4" -- underline on ANSI_Underline False -> "24" -- 2.50 underline off ANSI_Inverse True -> "7" -- 2.50 inverse on; reverses fgnd & bkgnd ANSI_Inverse False -> "27" -- 2.50 inverse off ANSI_Strikethru True -> "9" -- 2.50 strikethrough on ANSI_Strikethru False -> "29" -- 2.50 strikethrough off ANSI_Foreground color -> '3' : colorcode color ANSI_Background color -> '4' : colorcode color colorcode :: ANSIColor -> String colorcode ANSI_Black = "0" colorcode ANSI_Red = "1" colorcode ANSI_Green = "2" colorcode ANSI_Yellow = "3" colorcode ANSI_Blue = "4" colorcode ANSI_Magenta = "5" colorcode ANSI_Cyan = "6" colorcode ANSI_White = "7" -- ================================================================= -- -- Copyright (C) 2002 Thomas Moertel. -- -- This program is free software; you can redistribute it and/or -- modify it under the terms of the GNU General Public License -- as published by the Free Software Foundation; either version 2 -- of the License, or (at your option) any later version. -- -- The text of the GNU GPL may be found in the LICENSE file, -- included with this software, or online at the following URL: -- -- http://www.gnu.org/copyleft/gpl.html -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- Except as provided for under the terms of the GNU GPL, all rights -- are reserved worldwide. -- -- =================================================================