stylized: Ways to output stylized text on ANSI consoles.

[ library, user-interfaces ] [ Propose Tags ] [ Report a vulnerability ]

Various ways to output stylized text on ANSI consoles. Uses some of the MaxBolingbroke's System.Console.ANSI functionalities.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.2, 0.1.3
Dependencies ansi-terminal (>=0.5 && <0.6), base (>=4.1 && <4.2) [details]
License LicenseRef-GPL
Author Luca Molari
Maintainer luca.pwns@gmail.com
Category User Interfaces
Home page http://patch-tag.com/r/lucid/Stylized
Uploaded by LucaMolari at 2010-01-05T14:26:27Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1663 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for stylized-0.1.3

[back to package description]
{-

.: Sample usage :.
  :------------:

  You can run this README with: `runhaskell README`

-}


-- 0) import stylized module

import System.Console.ANSI.Stylized


-- 1) a data type to 'tag' messages:

data MsgType
  = Info
  | Warning
  | Error
  deriving (Enum)


-- 2) a function from tags to styles:

stylemap :: MsgType -> Style
stylemap Info    = ((Dull, Green), (NormalIntensity, NoUnderline))
stylemap Warning = ((Dull, Yellow), (NormalIntensity, NoUnderline))
stylemap Error   = ((Dull, Red), (NormalIntensity, NoUnderline))


-- 3) a logging function built from 'T' ending functions (i.e. putLnT and putT)

myLogLn msg = putLnT stylemap msg >> resetGR
myLog msg = putT stylemap msg >> resetGR


-- 4) some example messages:

msgs1 = [
  (Info, "Info Message\n"),
  (Warning, "Warning Message\n"),
  (Error, "Error Message") ]

msgs2 = zip (cycle $ enumFrom Info) ["some ", "random ", "messages "]


-- 5) print:

main = do
  myLog   msgs2
  myLogLn msgs2
  myLogLn msgs1


-- 6) you can always use S-ending functions ('curried' or 'uncurried' ones)

  putStrLnS ((Dull, Blue), (NormalIntensity, SingleUnderline)) "blue underlined"
  putLnS
    [ (((Vivid, Yellow), (NormalIntensity, NoUnderline)), "vivid yellow ")
    , (((Vivid, Blue), (NormalIntensity, NoUnderline)), "vivid blue")
    ]


-- 7) Remember to reset (if you want to)!

  resetGR