fpco / ide-backend

ide-backend drives the GHC API to build, query, and run your code
120 stars 17 forks source link

Use a psuedo terminal when running user code #235

Closed snoyberg closed 9 years ago

snoyberg commented 10 years ago

The goal would be to fix the line buffering behavior to match runghc or running a compiled executable. This isn't a strict requirement, but would be a nice enhancement. @dcoutts Let's discuss feasibility on Tuesday.

edsko commented 10 years ago

http://hackage.haskell.org/package/unix-2.7.0.1/docs/System-Posix-Terminal.html

edsko commented 10 years ago

In definition of stdout etc, calls mkHandle, calls getCharBuffer, which does:

getCharBuffer :: IODevice dev => dev -> BufferState
              -> IO (IORef CharBuffer, BufferMode)
getCharBuffer dev state = do
  buffer <- newCharBuffer dEFAULT_CHAR_BUFFER_SIZE state
  ioref  <- newIORef buffer
  is_tty <- IODevice.isTerminal dev

  let buffer_mode 
         | is_tty    = LineBuffering 
         | otherwise = BlockBuffering Nothing

  return (ioref, buffer_mode)

Alternatively, don't use a TTY and change the above to check (say) for an environment variable.

(The confusing behaviour here is that when running executables we get block buffering.)

mgsloan commented 9 years ago

I implemented this a while back: https://github.com/fpco/ide-backend/commit/e9cdb91fe6ac5c4a436706efe7fd405ec17c6e8d