packages feed

vty 5.0.2 → 5.1.0

raw patch · 7 files changed

+115/−94 lines, 7 files

Files

CHANGELOG view
@@ -1,67 +1,71 @@+5.1.0+  - vmin and vtime can be specified however the application requires. See Graphics.Vty.Config.+  - fixed the processing of input when vmin is set > 1.+ 5.0.0-    * The naming convention now matches:-        * http://www.haskell.org/haskellwiki/Programming_guidelines#Naming_Conventions-    * all projects using vty for input must be compiled with -threaded. Please notify vty author if-      this is not acceptable.-    * mkVtyEscDelay has been removed. Use "mkVty def". Which initialized vty with the default-      configuration.-    * input handling changes-        * KASCII is now KChar-        * KPN5 is now KCenter-        * tests exist.-        * Applications can add to the input tables by setting inputMap of the Config.-          See Graphics.Vty.Config-        * Users can define input table extensions that will apply to all vty applications.-          See Graphics.Vty.Config-        * terminal timing is now handled by selecting an appropriate VTIME. Previously this was-          implemented within Vty itself. This reduced complexity in vty but provides a different-          meta key behavior and implies a requirement on -threaded.-        * The time vty will wait to verify an ESC byte means a single ESC key is the-          singleEscPeriod of the Input Config structure.-    * removed the typeclass based terminal and display context interface in favor of a data-      structure of properties interface.-    * renamed the Terminal interface to Output-    * The default picture for an image now uses the "clear" background. This background fills-      background spans with spaces or just ends the line.-        * Previously the background defaulted to the space character. This causes issues copying-          text from a text editor. The text would end up with extra spaces at the end of the line.-    * Layer support-        * Each layer is an image.-        * The layers for a picture are a list of images.-        * The first image is the top-most layer. The images are ordered from top to bottom.-        * The transparent areas for a layer are the backgroundFill areas. backgroundFill is-          added to pad images when images of different sizes are joined.-        * If the background is clear there is no background layer.-        * If there is a background character then the bottom layer is the background layer.-        * emptyPicture is a Picture with no layers and no cursor-        * addToTop and addToBottom add a layer to the top and bottom of the given Picture.-    * compatibility improvements:-        * terminfo based terminals with no cursor support are silently accepted. The cursor-          visibility changes in the Picture will have no effect.-        * alternate (setf/setb) color maps supported. Though colors beyond the first 8 are just a-          guess.-        * added "rgbColor" for easy support of RGB specified colors.-        * Both applications and users can add to the mapping used to translate from input bytes to-          events.-    * Additional information about input and output process can be appended to a debug log-        * Set environment variable VTY_DEBUG_LOG to path of debug log-        * Or use "debugLog <path>" config directive-        * Or set 'debugLog' property of the Config provided to mkVty.-    * examples moved to vty-examples package. See test directory for cabal file.-        * vty-interactive-terminal-test-            * interactive test. Useful for building a bug report for vty's author.-            * test/interactive_terminal_test.hs-        * vty-event-echo-            * view a input event log for vty. Example of interacting with user.-            * test/EventEcho.hs-        * vty-rouge-            * The start of a rouge-like game. Example of layers and image build operations.-            * test/Rouge.hs-        * vty-benchmark-            * benchmarks vty. A series of tests that push random pictures to the terminal. The-              random pictures are generated using QuickCheck. The same generators used in the-              automated tests.-            * test/benchmark.hs+  - The naming convention now matches:+    - http://www.haskell.org/haskellwiki/Programming_guidelines#Naming_Conventions+  - all projects using vty for input must be compiled with -threaded. Please notify vty author if+    this is not acceptable.+  - mkVtyEscDelay has been removed. Use "mkVty def". Which initialized vty with the default+    configuration.+  - input handling changes+    - KASCII is now KChar+    - KPN5 is now KCenter+    - tests exist.+    - Applications can add to the input tables by setting inputMap of the Config.+      See Graphics.Vty.Config+    - Users can define input table extensions that will apply to all vty applications.+      See Graphics.Vty.Config+    - terminal timing is now handled by selecting an appropriate VTIME. Previously this was+      implemented within Vty itself. This reduced complexity in vty but provides a different meta+      key behavior and implies a requirement on -threaded.+    - The time vty will wait to verify an ESC byte means a single ESC key is the+      singleEscPeriod of the Input Config structure.+  - removed the typeclass based terminal and display context interface in favor of a data+    structure of properties interface.+  - renamed the Terminal interface to Output+  - The default picture for an image now uses the "clear" background. This background fills+    background spans with spaces or just ends the line.+    - Previously the background defaulted to the space character. This causes issues copying+      text from a text editor. The text would end up with extra spaces at the end of the line.+  - Layer support+    - Each layer is an image.+    - The layers for a picture are a list of images.+    - The first image is the top-most layer. The images are ordered from top to bottom.+    - The transparent areas for a layer are the backgroundFill areas. backgroundFill is+      added to pad images when images of different sizes are joined.+    - If the background is clear there is no background layer.+    - If there is a background character then the bottom layer is the background layer.+    - emptyPicture is a Picture with no layers and no cursor+    - addToTop and addToBottom add a layer to the top and bottom of the given Picture.+  - compatibility improvements:+    - terminfo based terminals with no cursor support are silently accepted. The cursor+      visibility changes in the Picture will have no effect.+    - alternate (setf/setb) color maps supported. Though colors beyond the first 8 are just a+      guess.+    - added "rgbColor" for easy support of RGB specified colors.+    - Both applications and users can add to the mapping used to translate from input bytes to+      events.+  - Additional information about input and output process can be appended to a debug log+    - Set environment variable VTY_DEBUG_LOG to path of debug log+    - Or use "debugLog <path>" config directive+    - Or set 'debugLog' property of the Config provided to mkVty.+  - examples moved to vty-examples package. See test directory for cabal file.+    - vty-interactive-terminal-test+      - interactive test. Useful for building a bug report for vty's author.+      - test/interactive_terminal_test.hs+    - vty-event-echo+      - view a input event log for vty. Example of interacting with user.+      - test/EventEcho.hs+    - vty-rouge+      - The start of a rouge-like game. Example of layers and image build operations.+      - test/Rouge.hs+    - vty-benchmark+      - benchmarks vty. A series of tests that push random pictures to the terminal. The+        random pictures are generated using QuickCheck. The same generators used in the+        automated tests.+      - test/benchmark.hs  4.7.0.0     * API changes:
Demo.hs view
@@ -16,7 +16,9 @@ type App = RWST Vty () (Seq String) IO  main = do-    vty <- mkVty def+    vty <- if True -- change to false for emacs-like input processing+            then mkVty def+            else mkVty (def { vmin = Just 2, vtime = Just 100 } )     _ <- execRWST (vtyInteract False) vty Seq.empty     shutdown vty 
src/Graphics/Vty/Config.hs view
@@ -93,7 +93,8 @@ type InputMap = [(Maybe String, String, Event)]  data Config = Config-    { specifiedEscPeriod :: Maybe Int -- < See 'singleEscPeriod'+    { vmin  :: Maybe Int -- < See 'derivedVmin'+    , vtime :: Maybe Int -- < See 'derivedVtime'     -- | Debug information is appended to this file if not Nothing.     , debugLog           :: Maybe FilePath     -- | The (input byte, output event) pairs extend the internal input table of VTY and the table@@ -103,26 +104,32 @@     , inputMap           :: InputMap     } deriving (Show, Eq) --- | AKA VTIME. The default is 100000 microseconds or 0.1 seconds. Set using the--- 'specifiedEscPeriod' field of 'Config'-singleEscPeriod :: Config -> Int-singleEscPeriod = maybe 100000 id . specifiedEscPeriod+-- | The default is 100 milliseconds, 0.1 seconds.+-- Set using the 'vtime' field of 'Config'+derivedVtime :: Config -> Int+derivedVtime = maybe 100 id . vtime +-- | The default is 1 character.+-- Set using the 'vmin' field of 'Config'+derivedVmin :: Config -> Int+derivedVmin = maybe 1 id . vmin+ instance Default Config where     def = mempty  instance Monoid Config where     mempty = Config-        { specifiedEscPeriod = Nothing-        , debugLog           = mempty-        , inputMap           = mempty+        { vmin      = Nothing+        , vtime     = Nothing+        , debugLog  = mempty+        , inputMap  = mempty         }     mappend c0 c1 = Config-        -- latter config takes priority in specifiedEscPeriod-        { specifiedEscPeriod = specifiedEscPeriod c1 <|> specifiedEscPeriod c0-        -- latter config takes priority in debugInputLog-        , debugLog           = debugLog c1           <|> debugLog c0-        , inputMap           = inputMap c0           <>  inputMap c1+        -- latter config takes priority in vmin, vtime, debugInputLog+        { vmin      = vmin c1     <|> vmin c0+        , vtime     = vtime c1    <|> vtime c0+        , debugLog  = debugLog c1 <|> debugLog c0+        , inputMap  = inputMap c0 <>  inputMap c1         }  type ConfigParser s a = ParsecT s () (Writer Config) a
src/Graphics/Vty/Input/Classify.hs view
@@ -33,11 +33,11 @@     eventForInput = M.fromList table     cl' [] = Prefix     cl' inputBlock = case M.lookup inputBlock eventForInput of+            -- if the inputBlock is exactly what is expected for an event then consume the whole+            -- block and return the event             Just e -> Valid e []             Nothing -> case S.member inputBlock prefixSet of                 True -> Prefix-                -- if the inputBlock is exactly what is expected for an event then consume the whole-                -- block and return the event                 -- look up progressively smaller tails of the input block until an event is found                 -- The assumption is that the event that consumes the most input bytes should be                 -- produced.@@ -45,8 +45,8 @@                 -- H: There will always be one match. The prefixSet contains, by definition, all                 -- prefixes of an event.                  False ->-                    let inputTails = init $ tail $ tails inputBlock-                    in case mapMaybe (\s -> (,) s `fmap` M.lookup s eventForInput) inputTails of+                    let inputPrefixes = reverse $ tail $ inits inputBlock+                    in case mapMaybe (\s -> (,) s `fmap` M.lookup s eventForInput) inputPrefixes of                         (s,e) : _ -> Valid e (drop (length s) inputBlock)                         -- neither a prefix or a full event.                         -- TODO: debug log
src/Graphics/Vty/Input/Loop.hs view
@@ -8,6 +8,8 @@ -- -- This is an example of an algorithm where code coverage could be high, even 100%, but the -- behavior is still under tested. I should collect more of these examples...+--+-- reference: http://www.unixwiz.net/techtips/termios-vmin-vtime.html module Graphics.Vty.Input.Loop where  import Graphics.Vty.Config@@ -30,7 +32,7 @@ import Foreign.C.Types (CInt(..))  import System.IO-import System.Posix.IO (fdReadBuf)+import System.Posix.IO (fdReadBuf, setFdOption, FdOption(..)) import System.Posix.Terminal import System.Posix.Types (Fd(..)) @@ -108,6 +110,7 @@     oldConfig <- use appliedConfig     fd <- view inputFd     when (newConfig /= oldConfig) $ do+        logMsg $ "new config: " ++ show newConfig         liftIO $ applyTimingConfig fd newConfig         appliedConfig .= newConfig     bufferPtr <- use $ inputBuffer.ptr@@ -117,13 +120,12 @@         if bytesRead > 0         then fmap (map $ chr . fromIntegral) $ peekArray (fromIntegral bytesRead) bufferPtr         else return []-    logMsg $ "input bytes: " ++ show stringRep+    when (not $ null stringRep) $ logMsg $ "input bytes: " ++ show stringRep     return stringRep  applyTimingConfig :: Fd -> Config -> IO ()-applyTimingConfig fd config =-    let vtime = min 255 $ singleEscPeriod config `div` 100000-    in setTermTiming fd 1 vtime+applyTimingConfig fd config = setTermTiming fd (derivedVmin config)+                                               (derivedVtime config `div` 100)  parseEvent :: InputM Event parseEvent = do@@ -131,6 +133,8 @@     b <- use unprocessedBytes     case c b of         Valid e remaining -> do+            logMsg $ "valid parse: " ++ show e+            logMsg $ "remaining: " ++ show remaining             unprocessedBytes .= remaining             return e         _                   -> mzero @@ -139,7 +143,9 @@ dropInvalid = do     c <- use classifier     b <- use unprocessedBytes-    when (c b == Invalid) $ unprocessedBytes .= []+    when (c b == Invalid) $ do+        logMsg "dropping input bytes"+        unprocessedBytes .= []  stopIfRequested :: InputM () stopIfRequested = do@@ -166,10 +172,12 @@         unsetAttrs = setTerminalAttributes fd original Immediately     return (setAttrs,unsetAttrs) -logClassifyMap :: Input -> String -> ClassifyMap -> IO()-logClassifyMap input termName classifyTable = case _inputDebug input of+logInitialInputState :: Input -> String -> ClassifyMap -> IO()+logInitialInputState input termName classifyTable = case _inputDebug input of     Nothing -> return ()     Just h  -> do+        config <- readIORef $ _configRef input+        hPrintf h "initial (vmin,vtime): %s\n" (show (vmin config, vtime config))         forM_ classifyTable $ \i -> case i of             (inBytes, EvKey k mods) -> hPrintf h "map %s %s %s %s\n" (show termName)                                                                      (show inBytes)@@ -179,6 +187,7 @@  initInputForFd :: Config -> String -> ClassifyMap -> Fd -> IO Input initInputForFd config termName classifyTable inFd = do+    setFdOption inFd NonBlockingRead False     applyTimingConfig inFd config     stopFlag <- newIORef False     input <- Input <$> newChan@@ -188,7 +197,7 @@                    <*> maybe (return Nothing)                              (\f -> Just <$> openFile f AppendMode)                              (debugLog config)-    logClassifyMap input termName classifyTable+    logInitialInputState input termName classifyTable     _ <- forkOS $ runInputProcessorLoop classifyTable input stopFlag     return input 
test/VerifyConfig.hs view
@@ -30,9 +30,8 @@ |]  exampleConfigConfig :: Config-exampleConfigConfig = Config-    { specifiedEscPeriod = def-    , debugLog = Just "/tmp/vty-debug.txt"+exampleConfigConfig = def+    { debugLog = Just "/tmp/vty-debug.txt"     , inputMap = [ (Nothing, "\ESC[B", EvKey KUp [])                  , (Nothing, "\ESC[1;3B", EvKey KDown [MAlt])                  , (Just "xterm", "\ESC[1;3B", EvKey KDown [MAlt])
vty.cabal view
@@ -1,5 +1,5 @@ name:                vty-version:             5.0.2+version:             5.1.0 license:             BSD3 license-file:        LICENSE author:              AUTHORS