Copyright | Daniel Mendler (c) 2017 |
---|---|
License | MIT (see the file LICENSE) |
Maintainer | mail@daniel-mendler.de |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
This library provides styled text output using ANSI escape sequences. The main feature is that the library keeps track of a stack of the active styles using a state monad. This makes it easy to use this library for a pretty printer with nested annotations, e.g., wl-pprint-console.
Warning: Windows support is currently not implemented, but is planned (by using ansi-terminal or the ffi).
Example:
basicExample :: IO () basicExample = do term <- getTerm printColoredS term $ Style Under $ Style Bold "Basic Example\n" printColoredS term $ Style Bold "Bold" printColoredS term $ Style Italic $ Bg Red "Italic Red" printColoredS term $ Style Under "Under" putChar '\n'
For many more examples, see the example.hs file.
- data Style
- data Color
- data Term
- data Colored a
- hGetTerm :: Handle -> IO Term
- getTerm :: IO Term
- hPrintColored :: (Handle -> a -> IO ()) -> Handle -> Term -> Colored a -> IO ()
- printColored :: (a -> IO ()) -> Term -> Colored a -> IO ()
- hPrintColoredIO :: Handle -> Term -> Colored (IO ()) -> IO ()
- printColoredIO :: Term -> Colored (IO ()) -> IO ()
- hPrintColoredS :: Handle -> Term -> Colored String -> IO ()
- printColoredS :: Term -> Colored String -> IO ()
- showColored :: Monoid o => (a -> o) -> (SGRCode -> o) -> Term -> Colored a -> o
- showColoredA :: (Applicative f, Monoid o) => (a -> f o) -> (SGRCode -> f o) -> Term -> Colored a -> f o
- showColoredS :: Term -> Colored String -> ShowS
Documentation
Rendering style
Named colors, 256 and RGB colors for more capable terminals.
DefaultColor | Default terminal color (terminal specific) |
Black | |
Red | |
Green | |
Yellow | |
Blue | |
Magenta | |
Cyan | |
White | |
DullBlack | |
DullRed | |
DullGreen | |
DullYellow | |
DullBlue | |
DullMagenta | |
DullCyan | |
DullWhite | |
Color256 !Word8 | Color from 256 color scheme. Color is automatically reduced to 8 colors for less capable terminals. |
RGB !Word8 !Word8 !Word8 | True color. Color is automatically reduced to 256 or 8 colors for less capable terminals. |
Terminal type. For less capable terminals the color depth is automatically reduced.
Nil | |
Value a | |
Style !Style (Colored a) | |
Unstyle !Style (Colored a) | |
Fg !Color (Colored a) | |
Bg !Color (Colored a) | |
Pair (Colored a) (Colored a) |
Monad Colored Source # | |
Functor Colored Source # | |
Applicative Colored Source # | |
Foldable Colored Source # | |
Traversable Colored Source # | |
Generic1 Colored Source # | |
IsList (Colored a) Source # | |
Eq a => Eq (Colored a) Source # | |
Ord a => Ord (Colored a) Source # | |
Read a => Read (Colored a) Source # | |
Show a => Show (Colored a) Source # | |
IsString a => IsString (Colored a) Source # | |
Generic (Colored a) Source # | |
Semigroup (Colored a) Source # | |
Monoid (Colored a) Source # | |
type Rep1 Colored Source # | |
type Rep (Colored a) Source # | |
type Item (Colored a) Source # | |
hGetTerm :: Handle -> IO Term Source #
The action (hGetTerm handle)
determines the terminal type of the file handle
.
The terminal type is determined by checking if the file handle points to a device
and by looking at the $TERM
environment variable.
showColoredA :: (Applicative f, Monoid o) => (a -> f o) -> (SGRCode -> f o) -> Term -> Colored a -> f o Source #