ansi-terminal-0.5.5: Simple ANSI terminal support, with Windows compatibilitySource codeContentsIndex
System.Console.ANSI
Contents
Basic data types
Cursor movement by character
Cursor movement by line
Directly changing cursor position
Clearing parts of the screen
Scrolling the screen
Select Graphic Rendition mode: colors and other whizzy stuff
Cursor visibilty changes
Changing the title
Description

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 a Handle. 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 a Handle. 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.
Synopsis
data Color
= Black
| Red
| Green
| Yellow
| Blue
| Magenta
| Cyan
| White
data ColorIntensity
= Dull
| Vivid
data ConsoleLayer
= Foreground
| Background
data BlinkSpeed
= SlowBlink
| RapidBlink
| NoBlink
data Underlining
= SingleUnderline
| DoubleUnderline
| NoUnderline
data ConsoleIntensity
= BoldIntensity
| FaintIntensity
| NormalIntensity
data SGR
= Reset
| SetConsoleIntensity ConsoleIntensity
| SetItalicized Bool
| SetUnderlining Underlining
| SetBlinkSpeed BlinkSpeed
| SetVisible Bool
| SetSwapForegroundBackground Bool
| SetColor ConsoleLayer ColorIntensity Color
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
cursorUpLine :: Int -> IO ()
cursorDownLine :: Int -> IO ()
hCursorUpLine :: Handle -> Int -> IO ()
hCursorDownLine :: Handle -> Int -> IO ()
cursorUpLineCode :: Int -> String
cursorDownLineCode :: Int -> String
setCursorColumn :: Int -> IO ()
hSetCursorColumn :: Handle -> Int -> IO ()
setCursorColumnCode :: Int -> String
setCursorPosition :: Int -> Int -> IO ()
hSetCursorPosition :: Handle -> Int -> Int -> IO ()
setCursorPositionCode :: 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 :: [SGR] -> IO ()
hSetSGR :: Handle -> [SGR] -> IO ()
setSGRCode :: [SGR] -> String
hideCursor :: IO ()
showCursor :: IO ()
hHideCursor :: Handle -> IO ()
hShowCursor :: Handle -> IO ()
hideCursorCode :: String
showCursorCode :: String
setTitle :: String -> IO ()
hSetTitle :: Handle -> String -> IO ()
setTitleCode :: String -> String
Basic data types
data Color Source
ANSI colors: come in various intensities, which are controlled by ColorIntensity
Constructors
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
show/hide Instances
data ColorIntensity Source
ANSI colors come in two intensities
Constructors
Dull
Vivid
show/hide Instances
data ConsoleLayer Source
ANSI colors can be set on two different layers
Constructors
Foreground
Background
show/hide Instances
data BlinkSpeed Source
ANSI blink speeds: values other than NoBlink are not widely supported
Constructors
SlowBlinkLess than 150 blinks per minute
RapidBlinkMore than 150 blinks per minute
NoBlink
data Underlining Source
ANSI text underlining
Constructors
SingleUnderline
DoubleUnderlineNot widely supported
NoUnderline
data ConsoleIntensity Source
ANSI general console intensity: usually treated as setting the font style (e.g. BoldIntensity causes text to be bold)
Constructors
BoldIntensity
FaintIntensityNot widely supported: sometimes treated as concealing text
NormalIntensity
data SGR Source
ANSI Select Graphic Rendition command
Constructors
Reset
SetConsoleIntensity ConsoleIntensity
SetItalicized BoolNot widely supported: sometimes treated as swapping foreground and background
SetUnderlining Underlining
SetBlinkSpeed BlinkSpeed
SetVisible BoolNot widely supported
SetSwapForegroundBackground Bool
SetColor ConsoleLayer ColorIntensity Color
Cursor movement by character
cursorUpSource
:: IntNumber of lines or characters to move
-> IO ()
cursorDownSource
:: IntNumber of lines or characters to move
-> IO ()
cursorForwardSource
:: IntNumber of lines or characters to move
-> IO ()
cursorBackwardSource
:: IntNumber of lines or characters to move
-> IO ()
hCursorUpSource
:: Handle
-> IntNumber of lines or characters to move
-> IO ()
hCursorDownSource
:: Handle
-> IntNumber of lines or characters to move
-> IO ()
Thanks to Brandon S. Allbery and Curt Sampson for pointing me in the right direction on xterm title setting on haskell-cafe. The 0 signifies that both the title and icon text should be set: i.e. the text for the window in the Start bar (or similar) as well as that in the actual window title. This is chosen for consistent behaviour between Unixes and Windows.
hCursorForwardSource
:: Handle
-> IntNumber of lines or characters to move
-> IO ()
hCursorBackwardSource
:: Handle
-> IntNumber of lines or characters to move
-> IO ()
cursorUpCodeSource
:: IntNumber of lines or characters to move
-> String
cursorDownCodeSource
:: IntNumber of lines or characters to move
-> String
cursorForwardCodeSource
:: IntNumber of lines or characters to move
-> String
cursorBackwardCodeSource
:: IntNumber of lines or characters to move
-> String
Cursor movement by line
cursorUpLineSource
:: IntNumber of lines to move
-> IO ()
cursorDownLineSource
:: IntNumber of lines to move
-> IO ()
hCursorUpLineSource
:: Handle
-> IntNumber of lines to move
-> IO ()
hCursorDownLineSource
:: Handle
-> IntNumber of lines to move
-> IO ()
cursorUpLineCodeSource
:: IntNumber of lines to move
-> String
cursorDownLineCodeSource
:: IntNumber of lines to move
-> String
Directly changing cursor position
setCursorColumnSource
:: Int0-based column to move to
-> IO ()
hSetCursorColumnSource
:: Handle
-> Int0-based column to move to
-> IO ()
setCursorColumnCodeSource
:: Int0-based column to move to
-> String
setCursorPositionSource
:: Int0-based row to move to
-> Int0-based column to move to
-> IO ()
hSetCursorPositionSource
:: Handle
-> Int0-based row to move to
-> Int0-based column to move to
-> IO ()
setCursorPositionCodeSource
:: Int0-based row to move to
-> Int0-based column to move to
-> String
Clearing parts of the screen
clearFromCursorToScreenEnd :: IO ()Source
clearFromCursorToScreenBeginning :: IO ()Source
clearScreen :: IO ()Source
hClearFromCursorToScreenEnd :: Handle -> IO ()Source
hClearFromCursorToScreenBeginning :: Handle -> IO ()Source
hClearScreen :: Handle -> IO ()Source
clearFromCursorToScreenEndCode :: StringSource
clearFromCursorToScreenBeginningCode :: StringSource
clearScreenCode :: StringSource
clearFromCursorToLineEnd :: IO ()Source
clearFromCursorToLineBeginning :: IO ()Source
clearLine :: IO ()Source
hClearFromCursorToLineEnd :: Handle -> IO ()Source
hClearFromCursorToLineBeginning :: Handle -> IO ()Source
hClearLine :: Handle -> IO ()Source
clearFromCursorToLineEndCode :: StringSource
clearFromCursorToLineBeginningCode :: StringSource
clearLineCode :: StringSource
Scrolling the screen
scrollPageUpSource
:: IntNumber of lines to scroll by
-> IO ()
scrollPageDownSource
:: IntNumber of lines to scroll by
-> IO ()
Scroll the displayed information up or down the terminal: not widely supported
hScrollPageUpSource
:: Handle
-> IntNumber of lines to scroll by
-> IO ()
hScrollPageDownSource
:: Handle
-> IntNumber of lines to scroll by
-> IO ()
Scroll the displayed information up or down the terminal: not widely supported
scrollPageUpCodeSource
:: IntNumber of lines to scroll by
-> String
scrollPageDownCodeSource
:: IntNumber of lines to scroll by
-> String
Scroll the displayed information up or down the terminal: not widely supported
Select Graphic Rendition mode: colors and other whizzy stuff
setSGRSource
:: [SGR]Commands: these will typically be applied on top of the current console SGR mode. An empty list of commands is equivalent to the list [Reset]. Commands are applied left to right.
-> IO ()
Set the Select Graphic Rendition mode
hSetSGRSource
:: Handle
-> [SGR]Commands: these will typically be applied on top of the current console SGR mode. An empty list of commands is equivalent to the list [Reset]. Commands are applied left to right.
-> IO ()
Set the Select Graphic Rendition mode
setSGRCodeSource
:: [SGR]Commands: these will typically be applied on top of the current console SGR mode. An empty list of commands is equivalent to the list [Reset]. Commands are applied left to right.
-> String
Set the Select Graphic Rendition mode
Cursor visibilty changes
hideCursor :: IO ()Source
showCursor :: IO ()Source
hHideCursor :: Handle -> IO ()Source
hShowCursor :: Handle -> IO ()Source
hideCursorCode :: StringSource
showCursorCode :: StringSource
Changing the title
setTitleSource
:: StringNew title
-> IO ()
Set the terminal window title
hSetTitleSource
:: Handle
-> StringNew title
-> IO ()
Set the terminal window title
setTitleCodeSource
:: StringNew title
-> String
Set the terminal window title
Produced by Haddock version 2.6.1