Safe Haskell | Safe-Infered |
---|
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 Color
- data ColorIntensity
- data ConsoleLayer
- = Foreground
- | Background
- data BlinkSpeed
- = SlowBlink
- | RapidBlink
- | NoBlink
- data Underlining
- data ConsoleIntensity
- data SGR
- cursorUp, cursorBackward, cursorForward, cursorDown :: Int -> IO ()
- hCursorUp, hCursorBackward, hCursorForward, hCursorDown :: Handle -> Int -> IO ()
- cursorUpCode, cursorBackwardCode, cursorForwardCode, cursorDownCode :: Int -> String
- cursorDownLine, cursorUpLine :: Int -> IO ()
- hCursorDownLine, hCursorUpLine :: Handle -> Int -> IO ()
- cursorDownLineCode, cursorUpLineCode :: 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, clearScreen, clearFromCursorToScreenBeginning :: IO ()
- hClearFromCursorToScreenEnd, hClearScreen, hClearFromCursorToScreenBeginning :: Handle -> IO ()
- clearFromCursorToScreenEndCode, clearScreenCode, clearFromCursorToScreenBeginningCode :: String
- clearFromCursorToLineEnd, clearLine, clearFromCursorToLineBeginning :: IO ()
- hClearFromCursorToLineEnd, hClearLine, hClearFromCursorToLineBeginning :: Handle -> IO ()
- clearFromCursorToLineEndCode, clearLineCode, clearFromCursorToLineBeginningCode :: String
- scrollPageUp, scrollPageDown :: Int -> IO ()
- hScrollPageUp, hScrollPageDown :: Handle -> Int -> IO ()
- scrollPageUpCode, scrollPageDownCode :: Int -> String
- setSGR :: [SGR] -> IO ()
- hSetSGR :: Handle -> [SGR] -> IO ()
- setSGRCode :: [SGR] -> String
- hideCursor, showCursor :: IO ()
- hHideCursor, hShowCursor :: Handle -> IO ()
- hideCursorCode, showCursorCode :: String
- setTitle :: String -> IO ()
- hSetTitle :: Handle -> String -> IO ()
- setTitleCode :: String -> String
Basic data types
ANSI colors: come in various intensities, which are controlled by ColorIntensity
data ColorIntensity Source
ANSI colors come in two intensities
data ConsoleLayer Source
ANSI colors can be set on two different layers
data BlinkSpeed Source
ANSI blink speeds: values other than NoBlink
are not widely supported
SlowBlink | Less than 150 blinks per minute |
RapidBlink | More than 150 blinks per minute |
NoBlink |
data Underlining Source
ANSI text underlining
SingleUnderline | |
DoubleUnderline | Not 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)
BoldIntensity | |
FaintIntensity | Not widely supported: sometimes treated as concealing text |
NormalIntensity |
ANSI Select Graphic Rendition command
Reset | |
SetConsoleIntensity ConsoleIntensity | |
SetItalicized Bool | Not widely supported: sometimes treated as swapping foreground and background |
SetUnderlining Underlining | |
SetBlinkSpeed BlinkSpeed | |
SetVisible Bool | Not widely supported |
SetSwapForegroundBackground Bool | |
SetColor ConsoleLayer ColorIntensity Color |
Cursor movement by character
Cursor movement by line
Directly changing cursor position
Clearing parts of the screen
hClearFromCursorToScreenEnd, hClearScreen, hClearFromCursorToScreenBeginning :: Handle -> IO ()Source
clearFromCursorToScreenEndCode, clearScreenCode, clearFromCursorToScreenBeginningCode :: StringSource
Scrolling the screen
scrollPageUp,scrollPageDownSource
Scroll the displayed information up or down the terminal: not widely supported
hScrollPageUp,hScrollPageDownSource
Scroll the displayed information up or down the terminal: not widely supported
scrollPageUpCode,scrollPageDownCodeSource
Scroll the displayed information up or down the terminal: not widely supported
Select Graphic Rendition mode: colors and other whizzy stuff
:: [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 |
-> IO () |
Set the Select Graphic Rendition mode
:: 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 |
-> IO () |
Set the Select Graphic Rendition mode
:: [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 |
-> String |
Set the Select Graphic Rendition mode
Cursor visibilty changes
hHideCursor, hShowCursor :: Handle -> IO ()Source
Changing the title
Set the terminal window title
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.