-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Pseudo terminal interaction with subprocesses.
--   
--   This package simplifies the creation of subprocesses that interact
--   with their parent via a pseudo terminal (see <tt>man pty</tt>).
@package posix-pty
@version 0.2.2


-- | A module for interacting with subprocesses through a pseudo terminal
--   (pty). Provides functions for reading from, writing to and resizing
--   pseudo terminals. Re-exports most of <a>System.Posix.Terminal</a>,
--   providing wrappers that work with the <a>Pty</a> type where necessary.
module System.Posix.Pty

-- | Create a new process that is connected to the current process through
--   a pseudo terminal. If an environment is specified, then only the
--   specified environment variables will be set. If no environment is
--   specified the process will inherit its environment from the current
--   process. Example:
--   
--   <pre>
--   pty &lt;- spawnWithPty (Just [("SHELL", "tcsh")]) True "ls" ["-l"] (20, 10)
--   </pre>
--   
--   This searches the user's PATH for a binary called <tt>ls</tt>, then
--   runs this binary with the commandline argument <tt>-l</tt> in a
--   terminal that is 20 characters wide and 10 characters high. The
--   environment of <tt>ls</tt> will contains one variable, SHELL, which
--   will be set to the value "tcsh".
spawnWithPty :: Maybe [(String, String)] -> Bool -> FilePath -> [String] -> (Int, Int) -> IO (Pty, ProcessHandle)

-- | Abstract pseudo terminal type.
data Pty

-- | Pseudo terminal control information.
--   
--   <ul>
--   <li><i>Terminal read queue</i> The terminal read queue contains the
--   data that was written from the master terminal to the slave terminal,
--   which was not read from the slave yet.</li>
--   <li><i>Terminal write queue</i> The terminal write queue contains the
--   data that was written from the slave terminal, which was not sent to
--   the master yet.</li>
--   </ul>
data PtyControlCode

-- | Terminal read queue was flushed.
FlushRead :: PtyControlCode

-- | Terminal write queue was flushed.
FlushWrite :: PtyControlCode

-- | Terminal output was stopped.
OutputStopped :: PtyControlCode

-- | Terminal output was restarted.
OutputStarted :: PtyControlCode

-- | Terminal stop and start characters are <tt>^S</tt> and <tt>^Q</tt>
--   respectively.
DoStop :: PtyControlCode

-- | Terminal stop and start characters are NOT <tt>^S</tt> and
--   <tt>^Q</tt>.
NoStop :: PtyControlCode

-- | Produces a <a>Pty</a> if the file descriptor is associated with a
--   terminal and Nothing if not.
createPty :: Fd -> IO (Maybe Pty)

-- | Close this pseudo terminal.
closePty :: Pty -> IO ()

-- | Attempt to read data from a pseudo terminal. Produces either the data
--   read or a list of <a>PtyControlCode</a><tt>s</tt> indicating which
--   control status events that have happened on the slave terminal.
--   
--   Throws an <a>IOError</a> of type <a>eofErrorType</a> when the terminal
--   has been closed, for example when the subprocess has terminated.
tryReadPty :: Pty -> IO (Either [PtyControlCode] ByteString)

-- | The same as <a>tryReadPty</a>, but discards any control status events.
readPty :: Pty -> IO ByteString

-- | Write a <a>ByteString</a> to the pseudo terminal, throws an
--   <a>IOError</a> when the terminal has been closed, for example when the
--   subprocess has terminated.
writePty :: Pty -> ByteString -> IO ()

-- | Set the pseudo terminal's dimensions to the specified width and
--   height.
resizePty :: Pty -> (Int, Int) -> IO ()

-- | Produces the pseudo terminal's current dimensions.
ptyDimensions :: Pty -> IO (Int, Int)

-- | Equivalent to <a>threadWaitRead</a>.
threadWaitReadPty :: Pty -> IO ()

-- | Equivalent to <a>threadWaitWrite</a>.
threadWaitWritePty :: Pty -> IO ()

-- | Equivalent to <a>threadWaitReadSTM</a>.
threadWaitReadPtySTM :: Pty -> IO (STM (), IO ())

-- | Equivalent to <a>threadWaitWriteSTM</a>.
threadWaitWritePtySTM :: Pty -> IO (STM (), IO ())

-- | See <a>getTerminalAttributes</a>.
getTerminalAttributes :: Pty -> IO TerminalAttributes

-- | See <a>setTerminalAttributes</a>.
setTerminalAttributes :: Pty -> TerminalAttributes -> TerminalState -> IO ()

-- | See <a>sendBreak</a>.
sendBreak :: Pty -> Int -> IO ()

-- | See <a>drainOutput</a>.
drainOutput :: Pty -> IO ()

-- | See <a>discardData</a>.
discardData :: Pty -> QueueSelector -> IO ()

-- | See <a>controlFlow</a>.
controlFlow :: Pty -> FlowAction -> IO ()

-- | See <a>getTerminalProcessGroupID</a>.
getTerminalProcessGroupID :: Pty -> IO ProcessGroupID

-- | See <a>getTerminalName</a>.
getTerminalName :: Pty -> IO FilePath

-- | See <a>getSlaveTerminalName</a>.
getSlaveTerminalName :: Pty -> IO FilePath
data FlowAction

-- | TCOOFF
SuspendOutput :: FlowAction

-- | TCOON
RestartOutput :: FlowAction

-- | TCIOFF
TransmitStop :: FlowAction

-- | TCION
TransmitStart :: FlowAction
data QueueSelector
InputQueue :: QueueSelector
OutputQueue :: QueueSelector
BothQueues :: QueueSelector
data TerminalState
Immediately :: TerminalState
WhenDrained :: TerminalState
WhenFlushed :: TerminalState

-- | Serial line baudrate. The set of supported speeds is system-dependent.
--   Portable use of the provided pattern synonyms that are outside the
--   list mandated by POSIX requires <tt>#ifdef</tt> guards.
--   
--   Applications may need to be prepared to encounter speeds not known at
--   compile time, these can be handled generically via the <a>BaudRate</a>
--   constructor. In other words, the provided pattern synonyms are not
--   necessarily a <tt>COMPLETE</tt> set.
--   
--   All non-zero <i>pseudo-terminal</i> baud rates are functionally
--   equivalent, and the <tt>pty</tt> driver may accept any speed within a
--   suitable range. Requested speeds may be rounded up or down to fit into
--   the supported range.
newtype BaudRate
BaudRate :: CSpeed -> BaudRate

-- | 4000000 baud, non-POSIX system-dependent extension
pattern B4000000 :: BaudRate

-- | 3500000 baud, non-POSIX system-dependent extension
pattern B3500000 :: BaudRate

-- | 3000000 baud, non-POSIX system-dependent extension
pattern B3000000 :: BaudRate

-- | 2500000 baud, non-POSIX system-dependent extension
pattern B2500000 :: BaudRate

-- | 2000000 baud, non-POSIX system-dependent extension
pattern B2000000 :: BaudRate

-- | 1500000 baud, non-POSIX system-dependent extension
pattern B1500000 :: BaudRate

-- | 1152000 baud, non-POSIX system-dependent extension
pattern B1152000 :: BaudRate

-- | 1000000 baud, non-POSIX system-dependent extension
pattern B1000000 :: BaudRate

-- | 921600 baud, non-POSIX system-dependent extension
pattern B921600 :: BaudRate

-- | 576000 baud, non-POSIX system-dependent extension
pattern B576000 :: BaudRate

-- | 500000 baud, non-POSIX system-dependent extension
pattern B500000 :: BaudRate

-- | 460800 baud, non-POSIX system-dependent extension
pattern B460800 :: BaudRate

-- | 230400 baud, non-POSIX system-dependent extension
pattern B230400 :: BaudRate

-- | 115200 baud, non-POSIX system-dependent extension
pattern B115200 :: BaudRate

-- | 76800 baud, non-POSIX system-dependent extension
pattern B76800 :: BaudRate

-- | 57600 baud, non-POSIX system-dependent extension
pattern B57600 :: BaudRate

-- | 28800 baud, non-POSIX system-dependent extension
pattern B28800 :: BaudRate

-- | 14400 baud, non-POSIX system-dependent extension
pattern B14400 :: BaudRate

-- | 7200 baud, non-POSIX system-dependent extension
pattern B7200 :: BaudRate

-- | 38400 baud
pattern B38400 :: BaudRate

-- | 19200 baud
pattern B19200 :: BaudRate

-- | 9600 baud
pattern B9600 :: BaudRate

-- | 4800 baud
pattern B4800 :: BaudRate

-- | 2400 baud
pattern B2400 :: BaudRate

-- | 1800 baud
pattern B1800 :: BaudRate

-- | 1200 baud
pattern B1200 :: BaudRate

-- | 600 baud
pattern B600 :: BaudRate

-- | 300 baud
pattern B300 :: BaudRate

-- | 200 baud
pattern B200 :: BaudRate

-- | 150 baud
pattern B150 :: BaudRate

-- | <ol>
--   <li>5 baud</li>
--   </ol>
pattern B134 :: BaudRate

-- | 110 baud
pattern B110 :: BaudRate

-- | 75 baud
pattern B75 :: BaudRate

-- | 50 baud
pattern B50 :: BaudRate

-- | Hang up
pattern B0 :: BaudRate
data ControlCharacter
EndOfFile :: ControlCharacter
EndOfLine :: ControlCharacter
Erase :: ControlCharacter
Interrupt :: ControlCharacter
Kill :: ControlCharacter
Quit :: ControlCharacter
Start :: ControlCharacter
Stop :: ControlCharacter
Suspend :: ControlCharacter
data TerminalMode

-- | <tt>BRKINT</tt> - Signal interrupt on break
InterruptOnBreak :: TerminalMode

-- | <tt>ICRNL</tt> - Map CR to NL on input
MapCRtoLF :: TerminalMode

-- | <tt>IGNBRK</tt> - Ignore break condition
IgnoreBreak :: TerminalMode

-- | <tt>IGNCR</tt> - Ignore CR
IgnoreCR :: TerminalMode

-- | <tt>IGNPAR</tt> - Ignore characters with parity errors
IgnoreParityErrors :: TerminalMode

-- | <tt>INLCR</tt> - Map NL to CR on input
MapLFtoCR :: TerminalMode

-- | <tt>INPCK</tt> - Enable input parity check
CheckParity :: TerminalMode

-- | <tt>ISTRIP</tt> - Strip character
StripHighBit :: TerminalMode

-- | <tt>IXANY</tt> - Enable any character to restart output
RestartOnAny :: TerminalMode

-- | <tt>IXOFF</tt> - Enable start/stop input control
StartStopInput :: TerminalMode

-- | <tt>IXON</tt> - Enable start/stop output control
StartStopOutput :: TerminalMode

-- | <tt>PARMRK</tt> - Mark parity errors
MarkParityErrors :: TerminalMode

-- | <tt>OPOST</tt> - Post-process output
ProcessOutput :: TerminalMode

-- | <tt>ONLCR</tt> - (XSI) Map NL to CR-NL on output
MapLFtoCRLF :: TerminalMode

-- | <tt>OCRNL</tt> - (XSI) Map CR to NL on output
OutputMapCRtoLF :: TerminalMode

-- | <tt>ONOCR</tt> - (XSI) No CR output at column 0
NoCRAtColumnZero :: TerminalMode

-- | <tt>ONLRET</tt> - (XSI) NL performs CR function
ReturnMeansLF :: TerminalMode

-- | <tt>TABDLY(TAB0)</tt> - (XSI) Select horizontal-tab delays: type 0
TabDelayMask0 :: TerminalMode

-- | <tt>TABDLY(TAB3)</tt> - (XSI) Select horizontal-tab delays: type 3
TabDelayMask3 :: TerminalMode

-- | <tt>CLOCAL</tt> - Ignore modem status lines
LocalMode :: TerminalMode

-- | <tt>CREAD</tt> - Enable receiver
ReadEnable :: TerminalMode

-- | <tt>CSTOPB</tt> - Send two stop bits, else one
TwoStopBits :: TerminalMode

-- | <tt>HUPCL</tt> - Hang up on last close
HangupOnClose :: TerminalMode

-- | <tt>PARENB</tt> - Parity enable
EnableParity :: TerminalMode

-- | <tt>PARODD</tt> - Odd parity, else even
OddParity :: TerminalMode

-- | <tt>ECHO</tt> - Enable echo
EnableEcho :: TerminalMode

-- | <tt>ECHOE</tt> - Echo erase character as error-correcting backspace
EchoErase :: TerminalMode

-- | <tt>ECHOK</tt> - Echo KILL
EchoKill :: TerminalMode

-- | <tt>ECHONL</tt> - Echo NL
EchoLF :: TerminalMode

-- | <tt>ICANON</tt> - Canonical input (erase and kill processing)
ProcessInput :: TerminalMode

-- | <tt>IEXTEN</tt> - Enable extended input character processing
ExtendedFunctions :: TerminalMode

-- | <tt>ISIG</tt> - Enable signals
KeyboardInterrupts :: TerminalMode

-- | <tt>NOFLSH</tt> - Disable flush after interrupt or quit
NoFlushOnInterrupt :: TerminalMode

-- | <tt>TOSTOP</tt> - Send <tt>SIGTTOU</tt> for background output
BackgroundWriteInterrupt :: TerminalMode
data TerminalAttributes
withoutMode :: TerminalAttributes -> TerminalMode -> TerminalAttributes
withMode :: TerminalAttributes -> TerminalMode -> TerminalAttributes
terminalMode :: TerminalMode -> TerminalAttributes -> Bool
bitsPerByte :: TerminalAttributes -> Int
withBits :: TerminalAttributes -> Int -> TerminalAttributes
controlChar :: TerminalAttributes -> ControlCharacter -> Maybe Char
withCC :: TerminalAttributes -> (ControlCharacter, Char) -> TerminalAttributes
withoutCC :: TerminalAttributes -> ControlCharacter -> TerminalAttributes
inputTime :: TerminalAttributes -> Int
withTime :: TerminalAttributes -> Int -> TerminalAttributes
minInput :: TerminalAttributes -> Int
withMinInput :: TerminalAttributes -> Int -> TerminalAttributes
inputSpeed :: TerminalAttributes -> BaudRate
withInputSpeed :: TerminalAttributes -> BaudRate -> TerminalAttributes
outputSpeed :: TerminalAttributes -> BaudRate
withOutputSpeed :: TerminalAttributes -> BaudRate -> TerminalAttributes

-- | <tt>getControllingTerminalName</tt> calls <tt>ctermid</tt> to obtain a
--   name associated with the controlling terminal for the process. If a
--   controlling terminal exists, <tt>getControllingTerminalName</tt>
--   returns the name of the controlling terminal.
--   
--   Throws <a>IOError</a> ("unsupported operation") if platform does not
--   provide <tt>ctermid(3)</tt> (use <tt>#if HAVE_CTERMID</tt> CPP guard
--   to detect availability).
getControllingTerminalName :: IO FilePath
instance GHC.Classes.Eq System.Posix.Pty.PtyControlCode
instance GHC.Internal.Read.Read System.Posix.Pty.PtyControlCode
instance GHC.Internal.Show.Show System.Posix.Pty.PtyControlCode
