bheklilr
bheklilr

Reputation: 54078

How can I set my GHCi prompt to a lambda character on Windows?

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?

Upvotes: 23

Views: 10864

Answers (3)

Răzvan Flavius Panda
Răzvan Flavius Panda

Reputation: 22126

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.

Upvotes: 40

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.

Upvotes: 5

bheklilr
bheklilr

Reputation: 54078

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.

Upvotes: 18

Related Questions