Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting items in stdin with haskell

Tags:

io

input

haskell

I have a bit of code in my haskell program like so:

evaluate :: String -> IO ()
evaluate = ...

repl = forever $ do
  putStr "> " >> hFlush stdout
  getLine >>= evaluate

Problem is, when I press the delete key (backspace on windows), instead of deleting a character from the buffer, I get a ^? character instead. What's the canonical way of getting delete to delete a character when reading from stdin? Similarly, I'd like to be able to get the arrow keys to move a cursor around, etc.

like image 265
limp_chimp Avatar asked Feb 22 '14 22:02

limp_chimp


1 Answers

Compile the program and then run the compiled executable. This will give the correct behavior for the Delete key. For some reason interpreting the program screws up the use of Delete.

To compile the program, just invoke ghc like this:

$ ghc -O2 myProgram.hs

This will generate a myProgram executable that you can run from the command line:

$ ./myProgram

That will then give the correct behavior for Delete.

like image 62
Gabriella Gonzalez Avatar answered Oct 14 '22 13:10

Gabriella Gonzalez