vty-windows 0.2.0.2 → 0.2.0.3
raw patch · 3 files changed
+38/−22 lines, 3 files
Files
- CHANGELOG.md +10/−1
- src/Graphics/Vty/Platform/Windows/WindowsInterfaces.hs +26/−20
- vty-windows.cabal +2/−1
CHANGELOG.md view
@@ -29,4 +29,13 @@ 0.2.0.1 ------- * On shutdown, make sure to shut down output interface before shutting down input interface. - Fixes mouse reset bug.+ Fixes mouse reset bug. + +0.2.0.2 +------- +* Fixed bug in processing response of the ReadConsoleInputW that caused vty-windows to crash. + +0.2.0.3 +------- +* Now vty-windows supports running in MSYS/MSYS2 terminals. This was achieved by modifying + the way the input and output buffers are initialized.
src/Graphics/Vty/Platform/Windows/WindowsInterfaces.hs view
@@ -10,19 +10,20 @@ #include "windows_cconv.h" import Graphics.Vty.Platform.Windows.WindowsConsoleInput -import Graphics.Vty.Input.Events ( Event(EvResize), InternalEvent(InputEvent) ) +import Graphics.Vty.Input.Events (Event(EvResize), InternalEvent(InputEvent)) +import Codec.Binary.UTF8.String (encodeChar) import Control.Concurrent (yield) -import Control.Concurrent.STM ( TChan, atomically, writeTChan ) -import Control.Monad (foldM) +import Control.Concurrent.STM (TChan, atomically, writeTChan) +import Control.Monad (foldM, when) import Data.Bits ((.|.), (.&.), shiftL) -import Codec.Binary.UTF8.String (encodeChar) import Data.Word (Word8) import Foreign.Storable (Storable(..)) -import GHC.Ptr ( Ptr ) -import System.IO ( Handle ) -import System.Win32.Types ( HANDLE, withHandleToHANDLE, DWORD ) +import GHC.Ptr (Ptr) +import System.IO (Handle) +import System.Win32.Types (DWORD, HANDLE, withHandleToHANDLE, iNVALID_HANDLE_VALUE) import System.Win32.Console +import System.Win32.File hiding (copyFile) foreign import ccall "windows.h WaitForSingleObject" c_WaitForSingleObject :: HANDLE -> DWORD -> IO DWORD @@ -77,21 +78,26 @@ mapM_ (\(w, offset') -> pokeElemOff bufferPtr (offset + offset') w) $ zip utf8Char [0..] return (offset + length utf8Char, Nothing) - -- | Configure Windows to correctly handle input for a Vty application configureInput :: Handle -> IO (IO (), IO ()) -configureInput inputHandle = do - withHandleToHANDLE inputHandle $ \wh -> do - original <- getConsoleMode wh - let setMode = setConsoleMode wh $ eNABLE_VIRTUAL_TERMINAL_INPUT .|. eNABLE_EXTENDED_FLAGS - pure (setMode, - setConsoleMode wh original) +configureInput _ = do + inHandle <- configureHandle "CONIN$" + original <- getConsoleMode inHandle + let setMode = setConsoleMode inHandle $ eNABLE_VIRTUAL_TERMINAL_INPUT .|. eNABLE_EXTENDED_FLAGS + pure (setMode, setConsoleMode inHandle original) -- | Configure Windows to correctly handle output for a Vty application configureOutput :: Handle -> IO (IO ()) -configureOutput outputHandle = do - withHandleToHANDLE outputHandle $ \wh -> do - original <- getConsoleMode wh - setConsoleOutputCP 65001 - setConsoleMode wh $ eNABLE_VIRTUAL_TERMINAL_PROCESSING .|. eNABLE_PROCESSED_OUTPUT - pure (setConsoleMode wh original) +configureOutput _ = do + outHandle <- configureHandle "CONOUT$" + original <- getConsoleMode outHandle + setConsoleOutputCP 65001 + setConsoleMode outHandle $ eNABLE_VIRTUAL_TERMINAL_PROCESSING .|. eNABLE_PROCESSED_OUTPUT + pure (setConsoleMode outHandle original) + +configureHandle :: String -> IO HANDLE +configureHandle handleName = do + outHandle <- createFile handleName (gENERIC_WRITE .|. gENERIC_READ) + fILE_SHARE_WRITE Nothing oPEN_EXISTING 0 Nothing + when (outHandle == iNVALID_HANDLE_VALUE) $ fail $ "Unable to configure terminal for input/output with handle: " ++ handleName + return outHandle
vty-windows.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: vty-windows -version: 0.2.0.2 +version: 0.2.0.3 license: BSD-3-Clause license-file: LICENSE author: Chris hackett @@ -11,6 +11,7 @@ build-type: Simple extra-doc-files: CHANGELOG.md extra-source-files: cbits/win_pseudo_console.c +-- documentation: True source-repository head type: git