$ ghciGHCi, version 6.9.20080912: http://www.haskell.org/ghc/ :? for helpLoading package ghc-prim ... linking ... done.Loading package integer ... linking ... done.Loading package base ... linking ... done.Prelude> a^? [RET]<interactive>:1:3: lexical error at character '\DEL'
When I pressed my Backspace key, the ^? showed up. When I pressed Delete, ^[[3~ showed up and ghci apparently thought I'd typed an '\ESC'. Arrow keys didn't work either (also seemed to be mapped to '\ESC' and Ctrl-U seemed to send a '\NAK'. However, when I hit Ctrl-Z to suspend ghci and then brought it back to the foreground, all the keys started working.
everything works fine if I start ghci in a shell in emacs, instead of in an xterm (in the latter, $TERM=xterm
emacs sets $TERM to "dumb", so I tried executing declare -x TERM=dumb and then starting ghci in an xterm, but the keys still didn't work
declaring TERM as vt100 didn't work either.
Ubuntu 7.10 with xmonad (I think 0.3), if that helps.
Trac metadata
Trac field
Value
Version
6.9
Type
Bug
TypeOfFailure
OtherFailure
Priority
normal
Resolution
Unresolved
Component
GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
x86
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
0
Show closed items
No child items are currently assigned. Use child items to break down this issue into smaller parts.
Linked items
0
Link issues together to show that they're related or that one is blocking others.
Learn more.
By the way, xev says my backspace key is sending keycode 22/keysym 0xff08/BackSpace, and the delete key is sending keycode 107/keysym 0xffff/Delete. Obviously all the keys work in ghci 6.8.2 and in other apps.
Do you reproduce the bug by opening up an xterm, and then typing 'ghci'? If so, what happens when you type "stty -a" in the xterm? Alternately, if you start ghci in such a way as to reproduce the bug, what happens when you run the following commands from inside ghci:
Finally: what version of libedit are you building against?
I suspect that some part of your xterm configuration is not set quite right, causing libedit to think that it's not inside a terminal. But it's strange that readline (used in ghc-6.8.2) isn't affected.
If I enter ghci, hit Ctrl-Z, and bring it back in the foreground so the keys start working again, and then type :!stty -a, the output looks exactly the same to me as before entering ghci.
Alternately, if you start ghci in such a way as to reproduce the bug, what happens when you run the following commands from inside ghci:
{{{
System.IO.hIsTerminalDevice System.IO.stdin
True
System.IO.hIsTerminalDevice System.IO.stdout
True
System.Environment.getEnv "TERM"
"xterm"
The values for these are the same both while the bug is exhibiting itself, and after suspending and re-activating ghci.
Finally: what version of libedit are you building against?
Do you reproduce the bug by opening up an xterm, and then typing 'ghci'? If so, what happens when you type "stty -a" in the xterm?
Yes. "stty -a" says: (...)
If I enter ghci, hit Ctrl-Z, and bring it back in the foreground so the keys start working again, and then type :!stty -a, the output looks exactly the same to me as before entering ghci.
Just to clarify: what happens when you type :!stty -a from inside ghci immediately after entering ghci?
I've never had problems with key mappings on this computer that I can recall, except for now with the HEAD.
I suspect this is a problem with libedit, since HEAD replaced readline with it it between 6.8 and 6.10. Do you know of any other programs on your machine that use libedit and whether they have the same issue? Otherwise, would it be possible for you to compile the following C program (with gcc -ledit) and check its behavior inside the xterm?
Just to clarify: what happens when you type :!stty -a from inside ghci immediately after entering ghci?
Still the same output as what I pasted.
I suspect this is a problem with libedit, since HEAD replaced readline with it it between 6.8 and 6.10. Do you know of any other programs on your machine that use libedit and whether they have the same issue? Otherwise, would it be possible for you to compile the following C program (with gcc -ledit) and check its behavior inside the xterm?
Done (I had to install libedit-dev first, but I don't think that had any other effects); your test program works fine (backspace, delete, Ctrl-U) work, when it's run in an xterm, but still the same problem with ghci.
Hmm, if you had to install libedit-dev to build that program then maybe ghc's editline bindings weren't built when you built ghc. Can you please check whether ghc's editline package is installed, for example by:
trying to run :browse System.Console.Editline.Readline inside ghci
double-checking whether the up/down arrow keys page through the ghci history
If it's not installed, you can probably fix this problem by building ghc again.
Hmm, if you had to install libedit-dev to build that program then maybe ghc's editline bindings weren't built when you built ghc. Can you please check whether ghc's editline package is installed, for example by:
trying to run :browse System.Console.Editline.Readline inside ghci
double-checking whether the up/down arrow keys page through the ghci history
If it's not installed, you can probably fix this problem by building ghc again.
Indeed, the browse command you suggested says there's no such module, and the arrow keys don't work (even after I suspend ghci and bring it back to the foreground as I described before). So I think your explanation is probably right. I won't have a chance to build ghc again for a little bit, but I think it should really be documented that you need to install the libedit-dev package (or whatever the equivalent is for distros other than Ubuntu/Debian), because my install of Ubuntu didn't come with it by default and I would expect that either this would work out of the box, or configure would tell me that I lacked a needed dependency.
Hmm, if you had to install libedit-dev to build that program then maybe ghc's editline bindings weren't built when you built ghc. Can you please check whether ghc's editline package is installed, for example by:
trying to run :browse System.Console.Editline.Readline inside ghci
double-checking whether the up/down arrow keys page through the ghci history
If it's not installed, you can probably fix this problem by building ghc again.
It's also missing in my case, additionally it seems that readline is the only one of the darcs packages missing at the source distributions (6.10,6.11) - might this problem be nonexistent if building from darcs? What's the reason to omit readline?
Hmm, if you had to install libedit-dev to build that program then maybe ghc's editline bindings weren't built when you built ghc. Can you please check whether ghc's editline package is installed, for example by:
trying to run :browse System.Console.Editline.Readline inside ghci
double-checking whether the up/down arrow keys page through the ghci history
If it's not installed, you can probably fix this problem by building ghc again.
It's also missing in my case, additionally it seems that readline is the only one of the darcs GHC boot packages missing at the source distributions (6.10,6.11) - might this problem be nonexistent if building from darcs? What's the reason to omit readline?
In 6.10 ghci uses the editline (libedit) package instead of readline, so only the former is distributed by default. The readline package can still be downloaded from hackage.haskell.org if needed.
In order to get the rich line-editing interface you need to have the libedit library installed before building ghc; see Building/Prerequisites for more information.
In 6.10 ghci uses the editline (libedit) package instead of readline, so only the former is distributed by default. The readline package can still be downloaded from hackage.haskell.org if needed.
In order to get the rich line-editing interface you need to have the libedit library installed before building ghc; see Building/Prerequisites for more information.
:-) Meanwhile, I am using HEAD in darcs (6.11.20081009) and added the libedit-dev package to (x)ubuntu. It seems to work - thank you very much!
ctrl-<left arrow> does not work. #2741 (closed) lists a hacky solution for delete. Is there a solution for the rest of they key bindings? ghci-haskeline makes no visible difference in the behavior.
$ ghci
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> should move one word back;5D
$ uname -a
Linux XXXXXXX 2.6.23.17-88.fc7 #1 (closed) SMP Thu May 15 00:02:29 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
ctrl-<left arrow> does not work. #2741 (closed) lists a hacky solution for delete. Is there a solution for the rest of the usual key bindings? ghci-haskeline makes no visible difference in the wonky behavior.
$ ghciGHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for helpLoading package ghc-prim ... linking ... done.Loading package integer ... linking ... done.Loading package base ... linking ... done.Prelude> should move one word back;5D
where the key sequence might need to be replaced depending on your terminal.
The delete key doesn't work
I agree that the delete behavior in editline is problematic; there's no really satisfying fix short of improving or replacing that library. But <delete> *should* work in ghci-haskeline. If it doesn't, can you please do the following:
Type ghc -e getLine, press delete and then return to see the control sequence for the delete key.
Type infocmp and paste the line with the kdch1 entry.
Sorry, I am using GHC-6.12.3, GHC-7.0.4, GHC-7.2.1 and in all of these versions I cannot delete or move cursor left and right in a line fetched by "getLine" in GHCi.
The above comments tell a lot of details, but what is the final fix? Is it intended behaviour that I cannot alter characters I entered to "getLine"?
One fix to the problem you've described is to set stdin to LineBuffering, using System.IO.hSetBuffering. On some platforms that will enable the delete key, but probably not the arrow keys.
If you want full interactive behavior for line input, you will need to use a package such as haskeline or readline.
One fix to the problem you've described is to set stdin to LineBuffering, using System.IO.hSetBuffering. On some platforms that will enable the delete key, but probably not the arrow keys.
I tried that on Suse Linux with GHC-6.12.3 and Ubuntu Linux with GHC-7.2.1. It enables delete key but not the arrow keys when I respond to a getLine. But with that mode I cannot see any longer what I enter to the GHCi prompt! I tried hSetEcho stdin True, but this didn't help. :-(
If you want full interactive behavior for line input, you will need to use a package such as haskeline or readline.
How can I find out, whether my GHC was built with haskeline, editline or readline? I use the GHC one from the Linux Tarball.
The ghci command prompt (e.g., Prelude>). This is used to specify commands which ghci should run. This always (as of ghc-6.10.4, IIRC) uses haskeline and should always enable the use of arrow keys.
The getLine action. This is a specific action which ghci may run as part of a larger function or program. It never uses haskeline, readline, etc.
This ticket was about #1 (closed), not #2 (closed), so most of the above comments don't apply to your issue.
Here's an example of using the haskeline package from within ghci. (Assuming you've already installed it with, for example, cabal install haskeline):
Prelude> :m +System.Console.HaskelinePrelude System.Console.Haskeline> runInputT defaultSettings (getInputLine "prompt>")prompt>This is an input line.Just "This is an input line."