Safe Haskell | None |
---|
The innards of Rainbow. Ordinarily you should not need this module; instead, just import Rainbow, which re-exports the most useful names from this module.
- data Term
- termFromEnv :: IO Term
- smartTermFromEnv :: Handle -> IO Term
- type Background8 = Last Color8
- type Background256 = Last Color256
- type Foreground8 = Last Color8
- type Foreground256 = Last Color256
- data Enum8
- enum8toWord8 :: Enum8 -> Word8
- newtype Color8 = Color8 {}
- color8toTerminfo :: Color8 -> Maybe Color
- newtype Color256 = Color256 {
- unColor256 :: Maybe Word8
- color256toTerminfo :: Color256 -> Maybe Color
- to256 :: Color8 -> Color256
- data StyleCommon = StyleCommon {}
- data Style8 = Style8 {}
- data Style256 = Style256 {}
- data TextSpec = TextSpec {}
- data Chunk = Chunk {}
- fromText :: Text -> Chunk
- fromLazyText :: Text -> Chunk
- defaultColors :: Terminal -> TermOutput
- commonAttrs :: Terminal -> StyleCommon -> TermOutput
- getTermCodes :: Terminal -> TextSpec -> TermOutput
- hPrintChunk :: Handle -> Terminal -> Chunk -> IO ()
- hPutChunks :: Handle -> Term -> [Chunk] -> IO ()
- putChunks :: Term -> [Chunk] -> IO ()
- hPutChunk :: Handle -> Chunk -> IO ()
- putChunk :: Chunk -> IO ()
- hPutChunkLn :: Handle -> Chunk -> IO ()
- putChunkLn :: Chunk -> IO ()
- bold8 :: Chunk
- bold8off :: Chunk
- underline8 :: Chunk
- underline8off :: Chunk
- flash8 :: Chunk
- flash8off :: Chunk
- inverse8 :: Chunk
- inverse8off :: Chunk
- underline256 :: Chunk
- underline256off :: Chunk
- bold256 :: Chunk
- bold256off :: Chunk
- inverse256 :: Chunk
- inverse256off :: Chunk
- flash256 :: Chunk
- flash256off :: Chunk
- bold :: Chunk
- boldOff :: Chunk
- inverse :: Chunk
- inverseOff :: Chunk
- flash :: Chunk
- flashOff :: Chunk
- underline :: Chunk
- underlineOff :: Chunk
Documentation
Which terminal definition to use.
Dumb | Using this terminal should always succeed. This suppresses all colors. Uesful if output is not going to a TTY, or if you just do not like colors. |
TermName String | Use the terminal with this given name. You might get this from the TERM environment variable, or set it explicitly. A runtime error will result if the terminfo database does not have a definition for this terminal. If this terminal supports 256 colors, then 256 colors are used. If this terminal supports less than 256 colors, but at least 8 colors, then 8 colors are used. Otherwise, no colors are used. |
Gets the terminal definition from the environment. If the
environment does not have a TERM veriable, use Dumb
.
Gets the terminal definition from the environment and a handle.
If the handle is not a terminal, Dumb
is returned. Otherwise,
the terminal is obtained from the environment.
Changed in version 0.12.0.0 - the type of this function was different in previous versions.
type Background8 = Last Color8Source
type Background256 = Last Color256Source
type Foreground8 = Last Color8Source
type Foreground256 = Last Color256Source
A simple enumeration for eight values.
enum8toWord8 :: Enum8 -> Word8Source
Color for an 8-color terminal. Does not affect 256-color terminals.
Color for an 256-color terminal. Does not affect 8-color terminals.
Color256 | |
|
to256 :: Color8 -> Color256Source
Any color for an 8-color terminal can also be used in a 256-color terminal.
data StyleCommon Source
Style elements that apply in both 8 and 256 color terminals. However, the elements are described separately for 8 and 256 color terminals, so that the text appearance can change depending on how many colors a terminal has.
Describes text appearance (foreground and background colors, as well as other attributes such as bold) for an 8 color terminal.
Describes text appearance (foreground and background colors, as well as other attributes such as bold) for a 256 color terminal.
The TextSpec bundles together the styles for the 8 and 256 color terminals, so that the text can be portrayed on any terminal.
A chunk is some textual data coupled with a description of what color the text is, attributes like whether it is bold or underlined, etc. The chunk knows what foreground and background colors and what attributes to use for both an 8 color terminal and a 256 color terminal.
The text is held as a list of strict Text
.
fromLazyText :: Text -> ChunkSource
commonAttrs :: Terminal -> StyleCommon -> TermOutputSource
getTermCodes :: Terminal -> TextSpec -> TermOutputSource
Gets the right set of terminal codes to apply the desired highlighting, bold, underlining, etc. Be sure to apply the attributes first (bold, underlining, etc) and then the colors. Setting the colors first and then the attributes seems to reset the colors, giving blank output.
hPutChunks :: Handle -> Term -> [Chunk] -> IO ()Source
Sends a list of chunks to the given handle for printing. Sets up
the terminal (this only needs to be done once.) Lazily processes
the list of Chunk. See putChunks
for notes on how many colors
are used.
putChunks :: Term -> [Chunk] -> IO ()Source
Sends a list of chunks to standard output for printing. Sets up the terminal (this only needs to be done once.) Lazily processes the list of Chunk.
Which colors are used depends upon the Term
. If it is Dumb
,
then no colors are used on output. If the Term
is specified with
TermName
, the UNIX terminfo library is used to determine how many
colors the terminal supports. If it supports at least 256 colors,
then 256 colors are used. If it supports at least 8 colors but less
than 256 colors, then 256 colors are used. Otherwise, no colors are
used. A runtime error will occur if the TermName
is not found in
the system terminal database.
hPutChunkLn :: Handle -> Chunk -> IO ()Source
Print one chunk at a time, to a handle, append a newline
putChunkLn :: Chunk -> IO ()Source
Print one chunk at a time, to standard output, append a newline
Bold. What actually happens when you use Bold is going to depend
on your terminal. For example, xterm allows you actually use a bold
font for bold, if you have one. Otherwise, it might simulate bold
by using overstriking. Another possibility is that your terminal
might use a different color to indicate bold. For more details (at
least for xterm), look at xterm (1) and search for boldColors
.
If your terminal uses a different color for bold, this allows an 8-color terminal to really have 16 colors.