Provides ANSI terminal support for Windows and ANSI terminal software running on a Unix-like operating system.
The ANSI escape codes are described at http://en.wikipedia.org/wiki/ANSI_escape_code and provide a rich range of functionality for terminal control, which includes:
- Colored text output, with control over both foreground and background colors
- Hiding or showing the cursor
- Moving the cursor around
- Clearing parts of the screen
The most frequently used parts of this ANSI command set are exposed with a platform independent interface by this module. Every function exported comes in three flavours:
- Vanilla: has an
IO ()
type and doesn't take aHandle
. This just outputs the ANSI command directly on to the terminal corresponding to stdout. Commands issued like this should work as you expect on both Windows and Unix. - Chocolate: has an
IO ()
type but takes aHandle
. This outputs the ANSI command on the terminal corresponding to the supplied handle. Commands issued like this should also work as your expect on both Windows and Unix. - Strawberry: has a
String
type and just consists of an escape code which can be added to any other bit of text before being output. This version of the API is often convenient to use, but due to fundamental limitations in Windows ANSI terminal support will only work on Unix. On Windows these codes will always be the empty string, so it is possible to use them portably for e.g. coloring console output on the understanding that you will only see colors if you are running on a Unix-like operating system.
- data ANSIColor
- data ANSISGR
- = Reset
- | BoldIntensity
- | FaintIntensity
- | NormalIntensity
- | Italic
- | SingleUnderline
- | DoubleUnderline
- | NoUnderline
- | SlowBlink
- | RapidBlink
- | NoBlink
- | Conceal
- | Reveal
- | SwapForegroundBackground
- | DontSwapForegroundBackground
- | ForegroundNormalIntensity ANSIColor
- | ForegroundHighIntensity ANSIColor
- | BackgroundNormalIntensity ANSIColor
- | BackgroundHighIntensity ANSIColor
- cursorUp :: Int -> IO ()
- cursorDown :: Int -> IO ()
- cursorForward :: Int -> IO ()
- cursorBackward :: Int -> IO ()
- hCursorUp :: Handle -> Int -> IO ()
- hCursorDown :: Handle -> Int -> IO ()
- hCursorForward :: Handle -> Int -> IO ()
- hCursorBackward :: Handle -> Int -> IO ()
- cursorUpCode :: Int -> String
- cursorDownCode :: Int -> String
- cursorForwardCode :: Int -> String
- cursorBackwardCode :: Int -> String
- nextLine :: Int -> IO ()
- previousLine :: Int -> IO ()
- hNextLine :: Handle -> Int -> IO ()
- hPreviousLine :: Handle -> Int -> IO ()
- nextLineCode :: Int -> String
- previousLineCode :: Int -> String
- setColumn :: Int -> IO ()
- hSetColumn :: Handle -> Int -> IO ()
- setColumnCode :: Int -> String
- setPosition :: Int -> Int -> IO ()
- hSetPosition :: Handle -> Int -> Int -> IO ()
- setPositionCode :: Int -> Int -> String
- clearFromCursorToScreenEnd :: IO ()
- clearFromCursorToScreenBeginning :: IO ()
- clearScreen :: IO ()
- hClearFromCursorToScreenEnd :: Handle -> IO ()
- hClearFromCursorToScreenBeginning :: Handle -> IO ()
- hClearScreen :: Handle -> IO ()
- clearFromCursorToScreenEndCode :: String
- clearFromCursorToScreenBeginningCode :: String
- clearScreenCode :: String
- clearFromCursorToLineEnd :: IO ()
- clearFromCursorToLineBeginning :: IO ()
- clearLine :: IO ()
- hClearFromCursorToLineEnd :: Handle -> IO ()
- hClearFromCursorToLineBeginning :: Handle -> IO ()
- hClearLine :: Handle -> IO ()
- clearFromCursorToLineEndCode :: String
- clearFromCursorToLineBeginningCode :: String
- clearLineCode :: String
- scrollPageUp :: Int -> IO ()
- scrollPageDown :: Int -> IO ()
- hScrollPageUp :: Handle -> Int -> IO ()
- hScrollPageDown :: Handle -> Int -> IO ()
- scrollPageUpCode :: Int -> String
- scrollPageDownCode :: Int -> String
- setSGR :: ANSISGR -> IO ()
- hSetSGR :: Handle -> ANSISGR -> IO ()
- setSGRCode :: ANSISGR -> String
- hideCursor :: IO ()
- showCursor :: IO ()
- hHideCursor :: Handle -> IO ()
- hShowCursor :: Handle -> IO ()
- hideCursorCode :: String
- showCursorCode :: String
Basic data types
ANSI colors: come in various intensities, which are controlled by ANSISGR
ANSI Select Graphic Rendition command
Reset | |
BoldIntensity | |
FaintIntensity | Not widely supported: sometimes treated as conceal |
NormalIntensity | |
Italic | Not widely supported: sometimes treated as swapping foreground and background |
SingleUnderline | |
DoubleUnderline | Not widely supported |
NoUnderline | |
SlowBlink | |
RapidBlink | |
NoBlink | |
Conceal | Not widely supported |
Reveal | |
SwapForegroundBackground | |
DontSwapForegroundBackground | |
ForegroundNormalIntensity ANSIColor | |
ForegroundHighIntensity ANSIColor | |
BackgroundNormalIntensity ANSIColor | |
BackgroundHighIntensity ANSIColor |
Cursor movement by character
Cursor movement by line
Directly changing cursor position
Clearing parts of the screen
hClearScreen :: Handle -> IO ()Source
hClearLine :: Handle -> IO ()Source
Scrolling the screen
Scroll the displayed information up or down the terminal: not widely supported
Scroll the displayed information up or down the terminal: not widely supported
Scroll the displayed information up or down the terminal: not widely supported
Select Graphic Rendition mode: colors and other whizzy stuff
Set the Select Graphic Rendition mode
Set the Select Graphic Rendition mode
Set the Select Graphic Rendition mode
Cursor visibilty changes
hideCursor :: IO ()Source
showCursor :: IO ()Source
hHideCursor :: Handle -> IO ()Source
hShowCursor :: Handle -> IO ()Source