Skip to content

Commit

Permalink
do not differentiate the terminal to use based on TERM_PROGRAM when o…
Browse files Browse the repository at this point in the history
…n Mac OS X #68
  • Loading branch information
coreyoconnor committed Mar 16, 2015
1 parent ebeafdd commit 475c45d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 104 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
5.2.8
- blaze-builder, lens, utf8-string version constraint bump
- Thanks glguy
- https://github.com/coreyoconnor/vty/pull/67
- Do not differentiate based on TERM_PROGRAM
- https://github.com/coreyoconnor/vty/issues/68

5.2.7
- lens and deepseq constraint bump + misc
- Thanks ethercrow
Expand Down
30 changes: 2 additions & 28 deletions src/Graphics/Vty/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import Graphics.Vty.Prelude
import Graphics.Vty.Config

import Graphics.Vty.Output.Interface
import Graphics.Vty.Output.MacOSX as MacOSX
import Graphics.Vty.Output.XTermColor as XTermColor
import Graphics.Vty.Output.TerminfoBased as TerminfoBased

Expand All @@ -58,40 +57,15 @@ import System.Posix.Env (getEnv)
--
-- Selection of a terminal is done as follows:
--
-- * If TERM == xterm
-- then the terminal might be one of the Mac OS X .app terminals. Check if that might be
-- the case and use MacOSX if so.
-- otherwise use XTermColor.
--
-- * If TERM == xterm use XTermColor.
-- * for any other TERM value TerminfoBased is used.
--
-- To differentiate between Mac OS X terminals this uses the TERM_PROGRAM environment variable.
-- However, an xterm started by Terminal or iTerm *also* has TERM_PROGRAM defined since the
-- environment variable is not reset/cleared by xterm. However a Terminal.app or iTerm.app started
-- from an xterm under X11 on mac os x will likely be done via open. Since this does not propogate
-- environment variables (I think?) this assumes that XTERM_VERSION will never be set for a true
-- Terminal.app or iTerm.app session.
--
-- \todo add an implementation for windows that does not depend on terminfo. Should be installable
-- with only what is provided in the haskell platform. Use ansi-terminal
outputForConfig :: Config -> IO Output
outputForConfig Config{ outputFd = Just fd, termName = Just termName, .. } = do
t <- if "xterm" `isPrefixOf` termName
then do
-- the explicit nature of the code below was nice for development, not needed anymore.
maybeTerminalApp <- getEnv "TERM_PROGRAM"
case maybeTerminalApp of
Nothing
-> XTermColor.reserveTerminal termName fd
Just v | v == "Apple_Terminal" || v == "iTerm.app"
-> do
maybeXterm <- getEnv "XTERM_VERSION"
case maybeXterm of
Nothing -> MacOSX.reserveTerminal v fd
Just _ -> XTermColor.reserveTerminal termName fd
-- Assume any other terminal that sets TERM_PROGRAM to not be an OS X terminal.app
-- like terminal?
_ -> XTermColor.reserveTerminal termName fd
then XTermColor.reserveTerminal termName fd
-- Not an xterm-like terminal. try for generic terminfo.
else TerminfoBased.reserveTerminal termName fd
return t
Expand Down
63 changes: 0 additions & 63 deletions src/Graphics/Vty/Output/MacOSX.hs

This file was deleted.

11 changes: 0 additions & 11 deletions test/VerifyOutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,11 @@ tests = concat <$> forM terminalsOfInterest (\termName -> do
Left (_ :: SomeException) -> return []
Right _ -> return [ verify ("verify " ++ termName ++ " could output a picture")
(smokeTestTermNonMac termName)
-- this is excessive.
, verify ("verify " ++ termName ++ " could output a picture on a Mac.")
(smokeTestTermMac termName)
]
)

smokeTestTermNonMac :: String -> Image -> Property
smokeTestTermNonMac termName i = liftIOResult $ do
-- unset the TERM_PROGRAM environment variable if set.
-- Required to execute regression test for #42 on a mac
unsetEnv "TERM_PROGRAM"
smokeTestTerm termName i

smokeTestTermMac :: String -> Image -> Property
smokeTestTermMac termName i = liftIOResult $ do
setEnv "TERM_PROGRAM" "Apple_Terminal" True
smokeTestTerm termName i

smokeTestTerm :: String -> Image -> IO Result
Expand Down
3 changes: 1 addition & 2 deletions vty.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: vty
version: 5.2.7
version: 5.2.8
license: BSD3
license-file: LICENSE
author: AUTHORS
Expand Down Expand Up @@ -90,7 +90,6 @@ library
Graphics.Vty.Span
Graphics.Vty.Output.Mock
Graphics.Vty.Output.Interface
Graphics.Vty.Output.MacOSX
Graphics.Vty.Output.XTermColor
Graphics.Vty.Output.TerminfoBased

Expand Down

0 comments on commit 475c45d

Please sign in to comment.