haskeline icon indicating copy to clipboard operation
haskeline copied to clipboard

How to get control characters

Open fujimura opened this issue 10 years ago • 3 comments

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?

fujimura avatar Oct 11 '14 08:10 fujimura

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

mxswd avatar Oct 13 '14 08:10 mxswd

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

+1

fujimura avatar Oct 13 '14 16:10 fujimura

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:

  • the control character that was pressed - so, for example, pressing ^C should give 'c'
  • what's on the line, in the form of a tuple, like with a CompletionFunc.

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

hdgarrood avatar Mar 16 '15 19:03 hdgarrood