ansi-terminal-0.3.0: Simple ANSI terminal support, with Windows compatibility

System.Console.ANSI

Contents

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

Basic data types

data ANSIColor Source

ANSI colors: come in various intensities, which are controlled by ANSISGR

Constructors

Black 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
White 

data ANSISGR Source

ANSI Select Graphic Rendition command

Constructors

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

cursorUpSource

Arguments

:: Int

Number of lines or characters to move

-> IO () 

cursorDownSource

Arguments

:: Int

Number of lines or characters to move

-> IO () 

cursorForwardSource

Arguments

:: Int

Number of lines or characters to move

-> IO () 

cursorBackwardSource

Arguments

:: Int

Number of lines or characters to move

-> IO () 

hCursorUpSource

Arguments

:: Handle 
-> Int

Number of lines or characters to move

-> IO () 

hCursorDownSource

Arguments

:: Handle 
-> Int

Number of lines or characters to move

-> IO () 

hCursorForwardSource

Arguments

:: Handle 
-> Int

Number of lines or characters to move

-> IO () 

hCursorBackwardSource

Arguments

:: Handle 
-> Int

Number of lines or characters to move

-> IO () 

cursorUpCodeSource

Arguments

:: Int

Number of lines or characters to move

-> String 

cursorDownCodeSource

Arguments

:: Int

Number of lines or characters to move

-> String 

cursorForwardCodeSource

Arguments

:: Int

Number of lines or characters to move

-> String 

cursorBackwardCodeSource

Arguments

:: Int

Number of lines or characters to move

-> String 

Cursor movement by line

nextLineSource

Arguments

:: Int

Number of lines to move

-> IO () 

previousLineSource

Arguments

:: Int

Number of lines to move

-> IO () 

hNextLineSource

Arguments

:: Handle 
-> Int

Number of lines to move

-> IO () 

hPreviousLineSource

Arguments

:: Handle 
-> Int

Number of lines to move

-> IO () 

nextLineCodeSource

Arguments

:: Int

Number of lines to move

-> String 

previousLineCodeSource

Arguments

:: Int

Number of lines to move

-> String 

Directly changing cursor position

setColumnSource

Arguments

:: Int

0-based column to move to

-> IO () 

hSetColumnSource

Arguments

:: Handle 
-> Int

0-based column to move to

-> IO () 

setColumnCodeSource

Arguments

:: Int

0-based column to move to

-> String 

setPositionSource

Arguments

:: Int

0-based row to move to

-> Int

0-based column to move to

-> IO () 

hSetPositionSource

Arguments

:: Handle 
-> Int

0-based row to move to

-> Int

0-based column to move to

-> IO () 

setPositionCodeSource

Arguments

:: Int

0-based row to move to

-> Int

0-based column to move to

-> String 

Clearing parts of the screen

Scrolling the screen

scrollPageUpSource

Arguments

:: Int

Number of lines to scroll by

-> IO () 

scrollPageDownSource

Arguments

:: Int

Number of lines to scroll by

-> IO () 

Scroll the displayed information up or down the terminal: not widely supported

hScrollPageUpSource

Arguments

:: Handle 
-> Int

Number of lines to scroll by

-> IO () 

hScrollPageDownSource

Arguments

:: Handle 
-> Int

Number of lines to scroll by

-> IO () 

Scroll the displayed information up or down the terminal: not widely supported

scrollPageUpCodeSource

Arguments

:: Int

Number of lines to scroll by

-> String 

scrollPageDownCodeSource

Arguments

:: Int

Number 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

Arguments

:: ANSISGR

Mode: this is applied to the current console SGR mode

-> IO () 

Set the Select Graphic Rendition mode

hSetSGRSource

Arguments

:: Handle 
-> ANSISGR

Mode: this is applied to the current console SGR mode

-> IO () 

Set the Select Graphic Rendition mode

setSGRCodeSource

Arguments

:: ANSISGR

Mode: this is applied to the current console SGR mode

-> String 

Set the Select Graphic Rendition mode

Cursor visibilty changes