diff options
| author | tv <tv@krebsco.de> | 2026-03-14 11:40:37 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-03-19 23:07:42 +0100 |
| commit | e2c0cc11a71c785b268f31f60bed2a79e00a4d61 (patch) | |
| tree | ce92ccb8200cfdba9785f32c99215fba9414cb05 /src/Terminal.hs | |
Diffstat (limited to 'src/Terminal.hs')
| -rw-r--r-- | src/Terminal.hs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Terminal.hs b/src/Terminal.hs new file mode 100644 index 0000000..607ca23 --- /dev/null +++ b/src/Terminal.hs @@ -0,0 +1,41 @@ +{-# LANGUAGE RecordWildCards #-} +module Terminal + ( Config(..) + , setConfig + , withConfig + ) + where + +import Control.Exception +import Data.List +import System.IO + +data Config = Config + { hin :: Handle + , hout :: Handle + , hinEcho :: Bool + , hinBufferMode :: BufferMode + , houtBufferMode :: BufferMode + , decsetPm :: [Int] + , decrstPm :: [Int] + } + +setConfig :: Config -> IO Config +setConfig Config{..} = get <* set where + get = Config <$> pure hin + <*> pure hout + <*> hGetEcho hin + <*> hGetBuffering hin + <*> hGetBuffering hout + <*> pure decrstPm + <*> pure decsetPm + set = do + hSetEcho hin hinEcho + hSetBuffering hin hinBufferMode + hSetBuffering hout houtBufferMode + hPutStr hout $ "\ESC[?" <> intercalate ";" (map show decsetPm) <> "h" + hPutStr hout $ "\ESC[?" <> intercalate ";" (map show decrstPm) <> "l" + hFlush hout + +withConfig :: Config -> IO a -> IO a +withConfig s = bracket (setConfig s) setConfig . const |
