This module provides various utilities and short-cuts.
- set_colour :: Colour -> IO ()
- set_colours_default :: IO ()
- putStrLnC :: Colour -> String -> IO ()
- putPairLn :: (Colour, String) -> (Colour, String) -> IO ()
- highlight :: ((Colour, Colour), (Colour, Colour), (Colour, Colour)) -> Int -> String -> IO ()
- highlightLN :: ((Colour, Colour), (Colour, Colour), (Colour, Colour)) -> Int -> String -> IO ()
- default_exception_handler :: Exception e => e -> IO x
- with_default_exception_handler :: IO x -> IO x
Set terminal [foreground] colour and then
putStrLn a string.
Write a pair of text strings on a single line, with different [foreground] text colours.
Print a single line of text, with a given character highlighted in colour. Useful for, say, highlighting the location of a syntax error in an expression.
The tuple consists of three colour pairs. Each pair is a foreground/background pair. The first pair applies to the next before the nominated position, the second pair applies to the nominated position itself, and the third pair applies to any text after the nominated position.
The nominated position is given by the
with 0 being the very first character of the string.
Note that if the position is off the end of the
string, a blank space will be added to the end of the
string and that will be highlighted.
Note that no newline is written. If you want one, you must output it yourself.
A version of
highlight that outputs a newline after
the final character of text.
Handling exceptions and errors
A default top-level exception handler, for exceptions that fail to be caught before reaching the top level.
In a properly designed application, exceptions should be anticipated, caught and handled in the correct place. (E.g., if you try to open a file, you should anticipate the possibility of an I/O exception and catch/process this appropriately.) Thus an exception reaching the top-level of the program would indicate a programming bug, and the generated error message reflects this. On a crash, the text
An internal program malfunction has occurred. Please report this as a bug to the program developers.
will be emitted on
stderr, coloured bright yellow on a
bright red background. The exception is then re-thrown
(presumably halting the program).