summaryrefslogtreecommitdiffhomepage
path: root/Pty.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-21 19:45:09 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-21 19:45:09 -0400
commit378770cde6fb9fd85983c05eab9eeff2e34398c2 (patch)
tree761273cdf6cc507db3fb1f6d7a2658d1fd799214 /Pty.hs
parenta5f677919c2db47149e545165c9cacbf2c6b07b4 (diff)
downloaddebug-me-378770cde6fb9fd85983c05eab9eeff2e34398c2.tar.gz
working toward getting developer mode connection to server working
Diffstat (limited to 'Pty.hs')
-rw-r--r--Pty.hs52
1 files changed, 33 insertions, 19 deletions
diff --git a/Pty.hs b/Pty.hs
index e1da2b4..7b251e7 100644
--- a/Pty.hs
+++ b/Pty.hs
@@ -1,4 +1,4 @@
-module Pty (Pty, runWithPty, readPty, writePty) where
+module Pty (Pty, runWithPty, readPty, writePty, inRawMode) where
import System.Posix
import System.Posix.Pty
@@ -25,24 +25,7 @@ runWithPty cmd params a = bracket setup cleanup go
-- Set the pty's terminal attributes to the same ones that
-- the outer terminal had.
System.Posix.Pty.setTerminalAttributes p as Immediately
- -- This is similar to cfmakeraw(3).
- let masteras = as
- `withoutMode` IgnoreBreak
- `withoutMode` InterruptOnBreak
- `withoutMode` CheckParity
- `withoutMode` StripHighBit
- `withoutMode` MapLFtoCR
- `withoutMode` IgnoreCR
- `withoutMode` MapCRtoLF
- `withoutMode` StartStopOutput
- `withoutMode` ProcessOutput
- `withoutMode` EnableEcho
- `withoutMode` EchoLF
- `withoutMode` ProcessInput
- `withoutMode` KeyboardInterrupts
- `withoutMode` ExtendedFunctions
- `withoutMode` EnableParity
- System.Posix.setTerminalAttributes stdInput masteras Immediately
+ setRawMode as
return (p, ph, as)
cleanup (p, ph, as) = do
-- Needed in case the provided action throws an exception
@@ -57,3 +40,34 @@ runWithPty cmd params a = bracket setup cleanup go
case msz of
Nothing -> return ()
Just sz -> resizePty p (Console.width sz, Console.height sz)
+
+inRawMode :: IO a -> IO a
+inRawMode a = bracket setup cleanup go
+ where
+ setup = do
+ as <- System.Posix.getTerminalAttributes stdInput
+ setRawMode as
+ return as
+ cleanup as = System.Posix.setTerminalAttributes stdInput as Immediately
+ go _ = a
+
+-- This is similar to cfmakeraw(3).
+setRawMode :: TerminalAttributes -> IO ()
+setRawMode as = do
+ let as' = as
+ `withoutMode` IgnoreBreak
+ `withoutMode` InterruptOnBreak
+ `withoutMode` CheckParity
+ `withoutMode` StripHighBit
+ `withoutMode` MapLFtoCR
+ `withoutMode` IgnoreCR
+ `withoutMode` MapCRtoLF
+ `withoutMode` StartStopOutput
+ `withoutMode` ProcessOutput
+ `withoutMode` EnableEcho
+ `withoutMode` EchoLF
+ `withoutMode` ProcessInput
+ `withoutMode` KeyboardInterrupts
+ `withoutMode` ExtendedFunctions
+ `withoutMode` EnableParity
+ System.Posix.setTerminalAttributes stdInput as' Immediately