@@ -1,63 +0,0 @@
1−-- Copyright Corey O'Connor
2−-- The standard Mac OS X terminals Terminal.app and iTerm both declare themselves to be
3−-- "xterm-color" by default. However the terminfo database for xterm-color included with OS X is
4−-- incomplete.
5−--
6−-- This terminal implementation modifies the standard terminfo terminal as required for complete OS
7−-- X support.
8−{-# LANGUAGE MagicHash #-}
9−{-# LANGUAGE FlexibleInstances #-}
10−{-# LANGUAGE TypeFamilies #-}
11−module Graphics.Vty.Output.MacOSX ( reserveTerminal )
12− where
13−
14−import Graphics.Vty.Output.Interface
15−import qualified Graphics.Vty.Output.TerminfoBased as TerminfoBased
16−
17−import Control.Applicative
18−import Control.Monad (void)
19−import Control.Monad.Trans
20−
21−import System.Posix.IO (fdWrite)
22−import System.Posix.Types (Fd)
23−
24−-- | for Terminal.app the terminal identifier "xterm" is used. For iTerm.app the terminal identifier
25−-- "xterm-256color" is used.
26−--
27−-- This effects the terminfo lookup.
28−reserveTerminal :: ( Applicative m, MonadIO m ) => String -> Fd -> m Output
29−reserveTerminal v outFd = do
30− let remapTerm "iTerm.app" = "xterm-256color"
31− remapTerm _ = "xterm"
32− flushedPut :: String -> IO ()
33− flushedPut = void . fdWrite outFd
34− t <- TerminfoBased.reserveTerminal (remapTerm v) outFd
35− return $ t { terminalID = terminalID t ++ " (Mac)"
36− , reserveDisplay = terminalAppReserveDisplay flushedPut
37− , releaseDisplay = terminalAppReleaseDisplay flushedPut
38− }
39−
40−-- | Terminal.app requires the xterm-color smcup and rmcup caps. Not the generic xterm ones.
41−-- Otherwise, Terminal.app expects the xterm caps.
42−smcupStr, rmcupStr :: String
43−smcupStr = "\ESC7\ESC[?47h"
44−rmcupStr = "\ESC[2J\ESC[?47l\ESC8"
45−
46−-- | always smcup then clear the screen on terminal.app
47−--
48−-- \todo really?
49−terminalAppReserveDisplay :: MonadIO m => (String -> IO ()) -> m ()
50−terminalAppReserveDisplay flushedPut = liftIO $ do
51− flushedPut smcupStr
52− flushedPut clearScreenStr
53−
54−terminalAppReleaseDisplay :: MonadIO m => (String -> IO ()) -> m ()
55−terminalAppReleaseDisplay flushedPut = liftIO $ do
56− flushedPut rmcupStr
57−
58−-- | iTerm needs a clear screen after smcup as well.
59−--
60−-- \todo but we apply to all mac terminals?
61−clearScreenStr :: String
62−clearScreenStr = "\ESC[H\ESC[2J"
63−