module Graphics.Vty.Output.MacOSX ( reserveTerminal )
where
import Graphics.Vty.Output.Interface
import qualified Graphics.Vty.Output.TerminfoBased as TerminfoBased
import Control.Applicative
import Control.Monad.Trans
import System.IO
reserveTerminal :: ( Applicative m, MonadIO m ) => String -> Handle -> m Output
reserveTerminal v outHandle = do
let remapTerm "iTerm.app" = "xterm-256color"
remapTerm _ = "xterm"
flushedPut :: String -> IO ()
flushedPut str = do
hPutStr outHandle str
hFlush outHandle
t <- TerminfoBased.reserveTerminal (remapTerm v) outHandle
return $ t { terminalID = terminalID t ++ " (Mac)"
, reserveDisplay = terminalAppReserveDisplay flushedPut
, releaseDisplay = terminalAppReleaseDisplay flushedPut
}
smcupStr, rmcupStr :: String
smcupStr = "\ESC7\ESC[?47h"
rmcupStr = "\ESC[2J\ESC[?47l\ESC8"
terminalAppReserveDisplay :: MonadIO m => (String -> IO ()) -> m ()
terminalAppReserveDisplay flushedPut = liftIO $ do
flushedPut smcupStr
flushedPut clearScreenStr
terminalAppReleaseDisplay :: MonadIO m => (String -> IO ()) -> m ()
terminalAppReleaseDisplay flushedPut = liftIO $ do
flushedPut rmcupStr
clearScreenStr :: String
clearScreenStr = "\ESC[H\ESC[2J"