on master help sign in
do not differentiate the terminal to use based on TERM_PROGRAM when on Mac OS X #68
475c45dCorey O'Connor
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+
15.2.7
85.2.7
2 - lens and deepseq constraint bump + misc
9 - lens and deepseq constraint bump + misc
3 - Thanks ethercrow
10 - Thanks ethercrow
src/Graphics/Vty/Output.hs+2−28
@@ -33,7 +33,6 @@ import Graphics.Vty.Prelude
33import Graphics.Vty.Config
33import Graphics.Vty.Config
34
34
35import Graphics.Vty.Output.Interface
35import Graphics.Vty.Output.Interface
36−import Graphics.Vty.Output.MacOSX as MacOSX
37import Graphics.Vty.Output.XTermColor as XTermColor
36import Graphics.Vty.Output.XTermColor as XTermColor
38import Graphics.Vty.Output.TerminfoBased as TerminfoBased
37import Graphics.Vty.Output.TerminfoBased as TerminfoBased
39
38
@@ -58,40 +57,15 @@ import System.Posix.Env (getEnv)
58--
57--
59-- Selection of a terminal is done as follows:
58-- Selection of a terminal is done as follows:
60--
59--
61−-- * If TERM == xterm
60+-- * If TERM == xterm use XTermColor.
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−--
66-- * for any other TERM value TerminfoBased is used.
61-- * for any other TERM value TerminfoBased is used.
67--
62--
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−--
75-- \todo add an implementation for windows that does not depend on terminfo. Should be installable
63-- \todo add an implementation for windows that does not depend on terminfo. Should be installable
76-- with only what is provided in the haskell platform. Use ansi-terminal
64-- with only what is provided in the haskell platform. Use ansi-terminal
77outputForConfig :: Config -> IO Output
65outputForConfig :: Config -> IO Output
78outputForConfig Config{ outputFd = Just fd, termName = Just termName, .. } = do
66outputForConfig Config{ outputFd = Just fd, termName = Just termName, .. } = do
79 t <- if "xterm" `isPrefixOf` termName
67 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
95 -- Not an xterm-like terminal. try for generic terminfo.
69 -- Not an xterm-like terminal. try for generic terminfo.
96 else TerminfoBased.reserveTerminal termName fd
70 else TerminfoBased.reserveTerminal termName fd
97 return t
71 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
27 Left (_ :: SomeException) -> return []
27 Left (_ :: SomeException) -> return []
28 Right _ -> return [ verify ("verify " ++ termName ++ " could output a picture")
28 Right _ -> return [ verify ("verify " ++ termName ++ " could output a picture")
29 (smokeTestTermNonMac termName)
29 (smokeTestTermNonMac termName)
30− -- this is excessive.
31− , verify ("verify " ++ termName ++ " could output a picture on a Mac.")
32− (smokeTestTermMac termName)
33 ]
30 ]
34 )
31 )
35
32
36smokeTestTermNonMac :: String -> Image -> Property
33smokeTestTermNonMac :: String -> Image -> Property
37smokeTestTermNonMac termName i = liftIOResult $ do
34smokeTestTermNonMac 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
46 smokeTestTerm termName i
35 smokeTestTerm termName i
47
36
48smokeTestTerm :: String -> Image -> IO Result
37smokeTestTerm :: String -> Image -> IO Result
vty.cabal+1−2
@@ -1,5 +1,5 @@
1name: vty
1name: vty
2−version: 5.2.7
2+version: 5.2.8
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5author: AUTHORS
5author: AUTHORS
@@ -90,7 +90,6 @@ library
90 Graphics.Vty.Span
90 Graphics.Vty.Span
91 Graphics.Vty.Output.Mock
91 Graphics.Vty.Output.Mock
92 Graphics.Vty.Output.Interface
92 Graphics.Vty.Output.Interface
93− Graphics.Vty.Output.MacOSX
94 Graphics.Vty.Output.XTermColor
93 Graphics.Vty.Output.XTermColor
95 Graphics.Vty.Output.TerminfoBased
94 Graphics.Vty.Output.TerminfoBased
96
95