Haskell ANSI Terminal Package For Windows, OS X and Linux
ANSI terminal support for Haskell, which allows:
- Cursor movement
- Screen and line clearing
- Color output
- Showing or hiding the cursor
- Changing the console title (though this is not strictly part of ANSI, it is widely supported in Unix)
It is compatible with Windows (via an emulation layer) and those Unixes with ANSI terminals.
If you like this, you may be interested in ansi-wl-pprint, which provides a pretty-printer that can construct strings containing ANSI colorisation.
Not all of the ANSI escape codes are provided by this module, but most (if not all) of the popular and well supported ones are. For a full list, have a look at the current version of the API. Each supported escape code or family of codes has a corresponding function that comes in three variants:
- A straight
IOvariant that doesn't take a
Handleand just applies the ANSI escape code to the terminal attached to stdout
IOvariant similar to above, but which takes a
Handleto which the ANSI escape should be applied
Stringvariant that returns a literal string that should be included to get the effect of the code. This is the only one of the three API variants that only works on Unix-like operating systems: on Windows these strings will always be blank!
A full example is available, but for a taste of how the library works try the following code:
import System.Console.ANSI main = do setCursorPosition 5 0 setTitle "ANSI Terminal Short Example" setSGR [ SetConsoleIntensity BoldIntensity , SetColor Foreground Vivid Red ] putStr "Hello" setSGR [ SetConsoleIntensity NormalIntensity , SetColor Foreground Vivid White , SetColor Background Dull Blue ] putStrLn "World!"
Haddock documentation is available at Hackage.
The library is originally written by Max Bolingbroke
Roman Cheplyaka is the primary maintainer.
Oliver Charles is the backup maintainer. Please get in touch with him if the primary maintainer cannot be reached.
- Make the fields of
- Make compatible with GHC 8.2.2
- Improve the error message on Windows when not ANSI-capable or ConHost
- Recognise Appveyor build environment as ANSI-enabled
getReportedCursorPosition: don't let the cursor reporting code be echo'd
- Allow saving, restoring, and querying the current cursor position
- Fix a couple of issues with the Reset emulation on Windows
Add 24-bit RGB color support
Fix Windows + ghc 7.8 compatibility
- Add ANSI support for Windows
- Add compatibility with Win32-220.127.116.11 and above
Add an example to the haddocks
Fix a GHC 7.10 warning
Restore compatibility with GHC 7.4 and older
- Drop support for
base < 4
Fix to build with GHC 7.8 on Windows
BoldIntensityno longer changes background color on Windows
setSGR was not equivalent to
setSGR [Reset]on Windows, even though it should be according to the documentation. This is now fixed.