20

I want to have a lambda (λ) symbol as my prompt in GHCi (7.8) on Windows 7, so I set up my .ghci file as

:set +m
:set prompt  "λ: "
:set prompt2 " | "

And I set my console font to Lucida Console since it's supposed to support Unicode, but when I load up GHCi, it looks like this instead

no lambda!

How can I get Windows to recognize the λ symbol properly?

bheklilr
  • 53,530
  • 6
  • 107
  • 163

3 Answers3

35

Using > chcp.com 65001 worked with GHCi but opening other text files with Vim after setting that encoding returned garbled text.

Add the following to your %USERPROFILE%\.ghci. Instead of changing the encoding, you can use the Unicode escaped lambda \x03BB:

:set prompt  "\x03BB: "

If %USERPROFILE%\.ghci does not exist, create it first before making the change.

Ed The ''Pro''
  • 875
  • 10
  • 22
Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169
  • @vikingsteve: does it work to change the prompt text to anything else? maybe the config is not being picked up, by default it should be located in %USERPROFILE% and named .ghci – Răzvan Flavius Panda Apr 17 '15 at 19:22
  • I can set the prompt to any other sort of normal characters, it's just the lambda symbol that isn't working :( – vikingsteve Apr 17 '15 at 19:25
  • 2
    @vikingsteve: what does the ghci prompt look like when you use `:set prompt "\x03BB: "` ? It might be the font being used by the console, if it is not true type it displays a question mark instead. With Lucida Console or Consolas it diplays correctly though. – Răzvan Flavius Panda Apr 17 '15 at 20:59
  • 1
    This answer worked for me, but I had to make a `ghci.conf` in `AppData\Roaming\ghc`. For some reason, GHCi wasn't loading the configuration file when I had it in my home directory. – Ed The ''Pro'' Jan 29 '21 at 20:37
17

This is actually quite a simple fix, just run the following command before starting GHCi:

> chcp.com 65001

This sets Window's encoding to the 65001 code page, which lets the λ get displayed properly:

enter image description here

This will also let a lot of other Unicode characters be displayed properly in cmd.exe and other Windows shells (such as Cygwin bash), but Windows' Unicode support is still not perfect, and some fonts don't support many of the characters. Luckily, λ happens to be a supported character so we can all have the classic GHCi prompt.

bheklilr
  • 53,530
  • 6
  • 107
  • 163
  • 1
    [Ah, memories.](http://stackoverflow.com/questions/23643897/modified-break-in-haskell/23643959#comment36312443_23643959) Still cannot make it work in WinGHCi, though. (Not to mention the command line breaks on the `Ø` in my user directory name.) – Ørjan Johansen Aug 18 '14 at 23:17
  • Oh that command line break was just because I didn't change the font. – Ørjan Johansen Aug 18 '14 at 23:19
  • 1
    Anyway to set this by default? – Steve3p0 Mar 07 '19 at 18:18
  • 1
    @Steve3p0 A solution is given [here](https://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8). – IPodFan Jul 24 '20 at 11:01
3

Using Răzvan Flavius Panda's answer, I decided to make a configuration file that had three flags for setting the prompt. The reason for this is prompt-cont is for GHCi versions >= 8.2.0, whereas prompt2 is for older GHCi versions.

I had a look at a short tutorial about configuring GHCi to try and find out where to put the configuration file. The site says that GHCi reads configuration files in the following order:

  1. ./.ghci (Local configuration file.)

  2. Depending on your OS:

    • *nix: $HOME/.ghc/ghci.conf
    • Windows: C:\Users\<name>\AppData\Roaming\ghc\ghci.conf
  3. $HOME/.ghci (Possibly *nix only; didn't work for me.)

I chose the second option.

C:\Users\Edwin\AppData\Roaming\ghc\ghci.conf:

:set prompt "\x03BB> "
:set prompt2 "\x03BB| "
:set prompt-cont "\x03BB| "

Explanation:

  • \x03BB stands for λ.
  • prompt is the main prompt. So it'll be "λ> ".
  • prompt2 is for a secondary prompt (I haven't seen it yet). So it'll be "λ| ".
  • prompt-cont is the same as prompt2, and is a replacement for prompt2 in GHCi 8.2.0.
Ed The ''Pro''
  • 875
  • 10
  • 22