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

support non-controlling terminals #156

Open goertzenator opened 3 years ago

goertzenator commented 3 years ago

This patch adds useTermHandles to support terminals other than the controlling terminal. For example, opening and serving a serial port might look like...

main :: IO ()
main = do
  behavior <- useTermHandles (Just "vt100")
    <$> openFile "/dev/ttyUSB0" ReadMode
    <*> openFile "/dev/ttyUSB0" WriteMode
  runInputTBehavior behavior defaultSettings loop
    where
      loop :: InputT IO ()
      loop = do ...

This also has applications for pseudo terminals as per issue #147.

Testing:

goertzenator commented 3 years ago

Some comments on a Windows implementation:

This PR does not implement useTermHandles for Windows. I tried briefly to port the changes into the Windows backend, but more rework is required there than I was comfortable with so I abandoned the effort. I think it would be useful to do that at some point; being able to support serial ports and the new ConPTY under Windows would be a good thing.

I would urge that this PR be merged despite the lack of Windows support. It would be useful to me and likely others. What I do seek though is the input of a Windows expert to determine if the new API useTermHandles is going to be suitable for Windows. That at least should be made portable so that a Window implementation can later be merged.

NorfairKing commented 3 years ago

+1 Just subscribing.