on master help sign in
do not differentiate the terminal to use based on TERM_PROGRAM when on Mac OS X #68
commit475c45d9d00e3a028e23cd347cb528b2ad16905a authorCorey O'Connor <coreyoconnor@gmail.com> dateSun 15 Mar 2015, 23:27 (12 years ago) parentebeafdd
5 files changed+10−104
CHANGELOG+7 src/Graphics/Vty/Output.hs+2−28 src/Graphics/Vty/Output/MacOSX.hs−63 test/VerifyOutput.hs−11 vty.cabal+1−2
CHANGELOG+7
@@ -1,3 +1,10 @@
1+5.2.8
2+ - blaze-builder, lens, utf8-string version constraint bump
3+ - Thanks glguy
4+ - https://github.com/coreyoconnor/vty/pull/67
5+ - Do not differentiate based on TERM_PROGRAM
6+ - https://github.com/coreyoconnor/vty/issues/68
7+
185.2.7
29 - lens and deepseq constraint bump + misc
310 - Thanks ethercrow
src/Graphics/Vty/Output.hs+2−28
@@ -33,7 +33,6 @@ import Graphics.Vty.Prelude
3333import Graphics.Vty.Config
3434
3535import Graphics.Vty.Output.Interface
36−import Graphics.Vty.Output.MacOSX as MacOSX
3736import Graphics.Vty.Output.XTermColor as XTermColor
3837import Graphics.Vty.Output.TerminfoBased as TerminfoBased
3938
@@ -58,40 +57,15 @@ import System.Posix.Env (getEnv)
5857--
5958-- Selection of a terminal is done as follows:
6059--
61−-- * If TERM == xterm
62−-- then the terminal might be one of the Mac OS X .app terminals. Check if that might be
63−-- the case and use MacOSX if so.
64−-- otherwise use XTermColor.
65−--
60+-- * If TERM == xterm use XTermColor.
6661-- * for any other TERM value TerminfoBased is used.
6762--
68−-- To differentiate between Mac OS X terminals this uses the TERM_PROGRAM environment variable.
69−-- However, an xterm started by Terminal or iTerm *also* has TERM_PROGRAM defined since the
70−-- environment variable is not reset/cleared by xterm. However a Terminal.app or iTerm.app started
71−-- from an xterm under X11 on mac os x will likely be done via open. Since this does not propogate
72−-- environment variables (I think?) this assumes that XTERM_VERSION will never be set for a true
73−-- Terminal.app or iTerm.app session.
74−--
7563-- \todo add an implementation for windows that does not depend on terminfo. Should be installable
7664-- with only what is provided in the haskell platform. Use ansi-terminal
7765outputForConfig :: Config -> IO Output
7866outputForConfig Config{ outputFd = Just fd, termName = Just termName, .. } = do
7967 t <- if "xterm" `isPrefixOf` termName
80− then do
81− -- the explicit nature of the code below was nice for development, not needed anymore.
82− maybeTerminalApp <- getEnv "TERM_PROGRAM"
83− case maybeTerminalApp of
84− Nothing
85− -> XTermColor.reserveTerminal termName fd
86− Just v | v == "Apple_Terminal" || v == "iTerm.app"
87− -> do
88− maybeXterm <- getEnv "XTERM_VERSION"
89− case maybeXterm of
90− Nothing -> MacOSX.reserveTerminal v fd
91− Just _ -> XTermColor.reserveTerminal termName fd
92− -- Assume any other terminal that sets TERM_PROGRAM to not be an OS X terminal.app
93− -- like terminal?
94− _ -> XTermColor.reserveTerminal termName fd
68+ then XTermColor.reserveTerminal termName fd
9569 -- Not an xterm-like terminal. try for generic terminfo.
9670 else TerminfoBased.reserveTerminal termName fd
9771 return t
src/Graphics/Vty/Output/MacOSX.hsdeleted−63
@@ -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−
test/VerifyOutput.hs−11
@@ -27,22 +27,11 @@ tests = concat <$> forM terminalsOfInterest (\termName -> do
2727 Left (_ :: SomeException) -> return []
2828 Right _ -> return [ verify ("verify " ++ termName ++ " could output a picture")
2929 (smokeTestTermNonMac termName)
30− -- this is excessive.
31− , verify ("verify " ++ termName ++ " could output a picture on a Mac.")
32− (smokeTestTermMac termName)
3330 ]
3431 )
3532
3633smokeTestTermNonMac :: String -> Image -> Property
3734smokeTestTermNonMac termName i = liftIOResult $ do
38− -- unset the TERM_PROGRAM environment variable if set.
39− -- Required to execute regression test for #42 on a mac
40− unsetEnv "TERM_PROGRAM"
41− smokeTestTerm termName i
42−
43−smokeTestTermMac :: String -> Image -> Property
44−smokeTestTermMac termName i = liftIOResult $ do
45− setEnv "TERM_PROGRAM" "Apple_Terminal" True
4635 smokeTestTerm termName i
4736
4837smokeTestTerm :: String -> Image -> IO Result
vty.cabal+1−2
@@ -1,5 +1,5 @@
11name: vty
2−version: 5.2.7
2+version: 5.2.8
33license: BSD3
44license-file: LICENSE
55author: AUTHORS
@@ -90,7 +90,6 @@ library
9090 Graphics.Vty.Span
9191 Graphics.Vty.Output.Mock
9292 Graphics.Vty.Output.Interface
93− Graphics.Vty.Output.MacOSX
9493 Graphics.Vty.Output.XTermColor
9594 Graphics.Vty.Output.TerminfoBased
9695