I am looking for a Haskell module that would allow me to easily send some escape sequences that generate coloured output (as ls --color does on a linux console or on rxvt). -- -- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ -- -- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/252 --
for simple quick-and-dirty stuff see my attatched ANSI.hs file which encodes a few basic ansi sequences including color changing ones and cursor control. If you want to do it the right (and more complicated) way however I suggest you find an haskell binding for the 'curses' library, one comes with QForeign in the examples directory based on hsc2hs, it should be portable to what comes with ghc 5 easilly now that QForeign and ghc's functionality are merging... (BTW, can the excellent QForeign examples, Curses, Db, Bzip, zlib and libgr be included in hslibs?) below is a simple module which exports some ANSI control codes which should work on any terminal (DOS ANSI, vt102, xterm, rxvt, linux console, etc...) to use just concat the strings with whatever you wish to output, attrFG and attrBG control the foreground and background colors respectivly, what numbers map to which colors is an excersize left to the reader. John {- ---- begin ANSI.hs ---- -} module ANSI( move, clrToEOL, clrFromBOL, clrLine, clrToEOS, clrFrombos, clrScreen, attrClear, attrBold, attrUnderline, attrBlink, attrReverse, cursorOn, cursorOff, attrFG, attrBG, ) where import Prelude((++), show, Int, String) move :: Int -> Int -> String move x y = "\27[" ++ (show y) ++ ";" ++ (show x) ++ ";H" clrToEOL = "\27[K" clrFromBOL = "\27[1K" clrLine = "\27[2K" clrToEOS = "\27[J" clrFrombos = "\27[1J" clrScreen = "\27[2J" attrClear = "\27[0m" attrBold = "\27[1m" attrUnderline = "\27[4m" attrBlink = "\27[5m" attrReverse = "\27[7m" cursorOn = "\27[?25h" cursorOff = "\27[?25l" attrFG :: Int -> String attrFG c = "\27[3" ++ (show c) ++ "m" attrBG :: Int -> String attrBG c = "\27[4" ++ (show c) ++ "m" {- ---- end ANSI.hs ---- -} On Mon, Sep 10, 2001 at 10:51:48AM +0200, Johannes Waldmann wrote:
I am looking for a Haskell module that would allow me to easily send some escape sequences that generate coloured output (as ls --color does on a linux console or on rxvt). -- -- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ -- -- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/252 --
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- --------------------------------------------------------------------------- John Meacham - California Institute of Technology, Alum. - john@repetae.net ---------------------------------------------------------------------------
On Monday 10 September 2001 08:51, Johannes Waldmann wrote: | I am looking for a Haskell module that would allow me | to easily send some escape sequences that generate coloured output | (as ls --color does on a linux console or on rxvt). The attached modules can be used to print colored text on a console using a nicer syntax. I hope this help. ----------------------------------------------------------- Hermann Oliveira Rodrigues - hermann@dcc.ufmg.br Graduated in Computer Science at Universidade Federal de Minas Gerais - Brazil -----------------------------------------------------------
participants (3)
-
Hermann O. Rodrigues -
Johannes Waldmann -
John Meacham