Difference between revisions of "GHCi in colour"
(Added section on how to color the prompt only, updated GuiHaskell link) |
(Added missed references tag) |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 3: | Line 3: | ||
== Prompt only == |
== Prompt only == |
||
− | The prompt can be colored by altering GHCi's |
+ | The prompt can be colored by altering GHCi's <code>prompt</code> setting including [https://en.wikipedia.org/wiki/ANSI_escape_code#Colors ANSI terminal color codes]. For example |
− | :set prompt "\ESC[34m%s > \ESC[m" |
+ | :set prompt "\ESC[34m\STX%s > \ESC[m\STX" |
will give the prompt blue color: |
will give the prompt blue color: |
||
Line 11: | Line 11: | ||
[[Image:Colored_ghci_prompt.png]] |
[[Image:Colored_ghci_prompt.png]] |
||
− | As usual, adding this to ghci.conf will auto-execute the command when running GHCi, making the prompt colored by default. |
+ | As usual, adding this to <code>ghci.conf</code> will auto-execute the command when running GHCi, making the prompt colored by default. |
− | |||
+ | Remember to use <code>\STX</code> to end an escape sequence. Without this control character, the prompt length will be [http://trac.haskell.org/haskeline/wiki/ControlSequencesInPrompt computer incorrectly] and your prompt will look wrong when editing long commands. |
||
== Full highlighting == |
== Full highlighting == |
||
Line 35: | Line 35: | ||
==== Using sed and ghci.conf ==== |
==== Using sed and ghci.conf ==== |
||
− | You can use sed to color the non-prompt output, and color the prompt with ghci.conf. This works better than piping into HsColour for me. See [http://martijn.van.steenbergen.nl/journal/2010/02/27/colors-in-ghci |
+ | You can use sed to color the non-prompt output, and color the prompt with ghci.conf. This works better than piping into HsColour for me. See [https://web.archive.org/web/20160202232256/http://martijn.van.steenbergen.nl:80/journal/2010/02/27/colors-in-ghci this] blog post for details. |
+ | |||
⚫ | This allows you to colorize everything you can catch with a regexp. Note that when coloring GHCi prompt using ghci.conf one should, in ultimate escapity, escape the escape codes with \001..\002, otherwise readline will mess up when editing long lines. For a working example of how this can be done refer to [[:File:Ghci 256color.tar.gz|this example]]. Output: |
||
+ | |||
+ | [[Image:GHCi 256color.jpg]] |
||
⚫ | This allows you to colorize everything you can catch with a regexp. Note that when coloring GHCi prompt using ghci.conf one should, in ultimate escapity, escape the escape codes with \001..\002, otherwise readline will mess up when editing long lines. For a working example of how this can be done refer to [[: |
||
This approach doesn't work well if you try to output an infinite sequence and then hit CTRL+C, ideas on how to fix that are welcome. |
This approach doesn't work well if you try to output an infinite sequence and then hit CTRL+C, ideas on how to fix that are welcome. |
||
Line 53: | Line 56: | ||
There are small delays however, when lexing certain tokens, and the |
There are small delays however, when lexing certain tokens, and the |
||
interaction with readline isn't ideal. |
interaction with readline isn't ideal. |
||
+ | |||
+ | See http://www.reddit.com/r/haskell/comments/144biy/pretty_output_in_ghci_howto_in_comments/ |
||
==== GuiHaskell ==== |
==== GuiHaskell ==== |
||
− | Neil Mitchell has a prototype [ |
+ | [https://ndmitchell.com/ Neil Mitchell] has a prototype [https://github.com/ndmitchell/guihaskell GuiHaskell] wrapper, based on GTK<ref>''Maintainers note:'' Does this contain a reasonable GHCi wrapper we could steal?</ref>. |
+ | |||
+ | |||
Line 62: | Line 69: | ||
[[Category:Tools]] |
[[Category:Tools]] |
||
+ | |||
+ | <references /> |
Latest revision as of 18:53, 22 January 2019
This page documents efforts to colourise GHCi output.
Prompt only
The prompt can be colored by altering GHCi's prompt
setting including ANSI terminal color codes. For example
:set prompt "\ESC[34m\STX%s > \ESC[m\STX"
will give the prompt blue color:
As usual, adding this to ghci.conf
will auto-execute the command when running GHCi, making the prompt colored by default.
Remember to use \STX
to end an escape sequence. Without this control character, the prompt length will be computer incorrectly and your prompt will look wrong when editing long commands.
Full highlighting
Example
Or a type error:
Output like this would be the result of running, for example:
ghci --colour
and would appear in the console/xterm as ansi terminal coloured output.
Implementation
Using sed and ghci.conf
You can use sed to color the non-prompt output, and color the prompt with ghci.conf. This works better than piping into HsColour for me. See this blog post for details.
This allows you to colorize everything you can catch with a regexp. Note that when coloring GHCi prompt using ghci.conf one should, in ultimate escapity, escape the escape codes with \001..\002, otherwise readline will mess up when editing long lines. For a working example of how this can be done refer to this example. Output:
This approach doesn't work well if you try to output an infinite sequence and then hit CTRL+C, ideas on how to fix that are welcome.
Using HsColour
An existing tool, HsColour, could be modified to operate interactively. In fact, HsColour is already interactive, and with a small patch added on 2006-12-14 to control ouput buffering better, this works relatively nicely:
ghci 2>&1 | HsColour -tty
There are small delays however, when lexing certain tokens, and the interaction with readline isn't ideal.
See http://www.reddit.com/r/haskell/comments/144biy/pretty_output_in_ghci_howto_in_comments/
GuiHaskell
Neil Mitchell has a prototype GuiHaskell wrapper, based on GTK[1].
If you have an idea of how to do this nicely, add your proposal here.
- ↑ Maintainers note: Does this contain a reasonable GHCi wrapper we could steal?