packages feed

vty 5.10 → 5.11

raw patch · 3 files changed

+49/−14 lines, 3 files

Files

CHANGELOG view
@@ -1,3 +1,9 @@+5.11+  - Vty now raises a VtyConfigurationError exception when the TERM+    evironment variable is missing (thanks Eric Mertens)+  - Graphics.Vty.Config got an explicit export list to avoid accidentally+    exporting internal types (thanks Eric Mertens)+ 5.10   - Add absolute cursor positioning mode AbsoluteCursor to Cursor. This     mode provides greater control over cursor positioning by bypassing
src/Graphics/Vty/Config.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts, FlexibleInstances #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -64,7 +65,16 @@ -- Set VTY_DEBUG_LOG. Run vty. Check debug log for incorrect mappings. Add corrected mappings to -- .vty/config ---module Graphics.Vty.Config where+module Graphics.Vty.Config+  ( InputMap+  , Config(..)+  , VtyConfigurationError(..)+  , userConfig+  , overrideEnvConfig+  , standardIOConfig+  , runParseConfig+  , parseConfigFile+  ) where  #if __GLASGOW_HASKELL__ > 704 import Prelude@@ -74,12 +84,13 @@  import Control.Applicative hiding (many) -import Control.Exception (catch, IOException)+import Control.Exception (catch, IOException, Exception(..), throwIO) import Control.Monad (liftM, guard, void)  import qualified Data.ByteString as BS import Data.Default import Data.Monoid+import Data.Typeable (Typeable)  import Graphics.Vty.Input.Events @@ -94,6 +105,16 @@ import Text.Parsec.Token ( GenLanguageDef(..) ) import qualified Text.Parsec.Token as P +-- | Type of errors that can be thrown when configuring VTY+data VtyConfigurationError+  = VtyMissingTermEnvVar -- ^ TERM environment variable not set+  deriving (Show, Eq, Typeable)++instance Exception VtyConfigurationError where+#if MIN_VERSION_base(4,8,0)+  displayException VtyMissingTermEnvVar = "TERM environment variable not set"+#endif+ -- | Mappings from input bytes to event in the order specified. Later entries take precedence over -- earlier in the case multiple entries have the same byte string. type InputMap = [(Maybe String, String, Event)]@@ -165,30 +186,38 @@     d <- getEnv "VTY_DEBUG_LOG"     return $ def { debugLog = d } +-- | Configures VTY using defaults suitable for terminals. This action+-- can raise 'VtyConfigurationError'. standardIOConfig :: IO Config standardIOConfig = do-    Just t <- getEnv "TERM"-    return $ def { vmin = Just 1-                 , mouseMode = Just False-                 , bracketedPasteMode = Just False-                 , vtime = Just 100-                 , inputFd = Just stdInput-                 , outputFd = Just stdOutput-                 , termName = Just t-                 }+    mb <- getEnv "TERM"+    case mb of+      Nothing -> throwIO VtyMissingTermEnvVar+      Just t ->+        return def+          { vmin               = Just 1+          , mouseMode          = Just False+          , bracketedPasteMode = Just False+          , vtime              = Just 100+          , inputFd            = Just stdInput+          , outputFd           = Just stdOutput+          , termName           = Just t+          }  parseConfigFile :: FilePath -> IO Config parseConfigFile path = do     catch (runParseConfig path <$> BS.readFile path)           (\(_ :: IOException) -> return def) -type Parser = Parsec BS.ByteString ()- runParseConfig :: String -> BS.ByteString -> Config runParseConfig name cfgTxt =   case runParser parseConfig () name cfgTxt of     Right cfg -> cfg     Left{}    -> def++------------------------------------------------------------------------++type Parser = Parsec BS.ByteString ()  -- I tried to use the haskellStyle here but that was specialized (without requirement?) to the -- String stream type.
vty.cabal view
@@ -1,5 +1,5 @@ name:                vty-version:             5.10+version:             5.11 license:             BSD3 license-file:        LICENSE author:              AUTHORS