haskell / haskeline

A Haskell library for line input in command-line programs.
https://hackage.haskell.org/package/haskeline
BSD 3-Clause "New" or "Revised" License
221 stars 75 forks source link

How to get control characters #13

Open fujimura opened 9 years ago

fujimura commented 9 years ago

Hello,

I'd like to do something with \BS, but getInputChar ignores non-printable characters. How can I do it? Should I build a custom function which acts like getInputChar returns non-printable ones?

mxswd commented 9 years ago

I vote it should return all characters and not filter out non-printable characters.

fujimura commented 9 years ago

I vote it should return all characters and not filter out non-printable characters.

+1

hdgarrood commented 9 years ago

Here's another use case for allowing users of this library to respond to control characters: purescript/purescript#934.

I wonder if a better API would be to add a function which can transform InputT actions to specify what should happen when a control character is entered. Something like this, perhaps:

type ControlHandler m = Char -> (String, String) -> InputT m (Maybe String)

handleControlChars :: (MonadException m) =>
  ControlHandler m -> InputT m (Maybe String) -> InputT m (Maybe String)

The arguments to a ControlHandler should be:

@judah if I were to put together a PR for this, would you take it?