summaryrefslogtreecommitdiffhomepage
path: root/Pty.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-05-04 15:16:04 -0400
committerJoey Hess <joeyh@joeyh.name>2017-05-04 15:16:04 -0400
commit18e70a49274033d0598fcdfe830f80b0cc3552f0 (patch)
tree435dede3375593cb84453197136c480f2102e749 /Pty.hs
parent62b488cb62a52eac92e6d37932a773ec138a5a2b (diff)
downloaddebug-me-18e70a49274033d0598fcdfe830f80b0cc3552f0.tar.gz
--replay: make Space advance to next output
This commit was sponsored by John Peloquin on Patreon.
Diffstat (limited to 'Pty.hs')
-rw-r--r--Pty.hs65
1 files changed, 40 insertions, 25 deletions
diff --git a/Pty.hs b/Pty.hs
index 35910cc..92ff4e2 100644
--- a/Pty.hs
+++ b/Pty.hs
@@ -3,7 +3,15 @@
- Licensed under the GNU AGPL version 3 or higher.
-}
-module Pty (Pty, runWithPty, readPty, writePty, inRawMode) where
+module Pty (
+ Pty,
+ runWithPty,
+ readPty,
+ writePty,
+ inRawMode,
+ withoutEcho,
+ withTerminalAttributes,
+) where
import System.Posix
import System.Posix.Pty
@@ -30,7 +38,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
- setRawMode as
+ System.Posix.setTerminalAttributes stdInput (setRawMode as) Immediately
return (p, ph, as)
cleanup (p, ph, as) = do
-- Needed in case the provided action throws an exception
@@ -46,33 +54,40 @@ runWithPty cmd params a = bracket setup cleanup go
Nothing -> return ()
Just sz -> resizePty p (Console.width sz, Console.height sz)
-inRawMode :: IO a -> IO a
-inRawMode a = bracket setup cleanup go
+withTerminalAttributes :: (TerminalAttributes -> TerminalAttributes) -> IO a -> IO a
+withTerminalAttributes f a = bracket setup cleanup go
where
setup = do
as <- System.Posix.getTerminalAttributes stdInput
- setRawMode as
+ System.Posix.setTerminalAttributes stdInput (f as) Immediately
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
+-- | This is similar to cfmakeraw(3).
+inRawMode :: IO a -> IO a
+inRawMode = withTerminalAttributes setRawMode
+
+setRawMode :: TerminalAttributes -> TerminalAttributes
+setRawMode 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
+
+-- | Disable terminal echo.
+withoutEcho :: IO a -> IO a
+withoutEcho = withTerminalAttributes $ \as -> as
+ `withoutMode` EnableEcho
+