packages feed

ansi-terminal 0.11 → 0.11.1

raw patch · 9 files changed

+130/−51 lines, 9 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- System.Console.ANSI.Types: instance GHC.Arr.Ix System.Console.ANSI.Types.BlinkSpeed
- System.Console.ANSI.Types: instance GHC.Arr.Ix System.Console.ANSI.Types.Color
- System.Console.ANSI.Types: instance GHC.Arr.Ix System.Console.ANSI.Types.ColorIntensity
- System.Console.ANSI.Types: instance GHC.Arr.Ix System.Console.ANSI.Types.ConsoleIntensity
- System.Console.ANSI.Types: instance GHC.Arr.Ix System.Console.ANSI.Types.ConsoleLayer
- System.Console.ANSI.Types: instance GHC.Arr.Ix System.Console.ANSI.Types.Underlining
+ System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.BlinkSpeed
+ System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.Color
+ System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.ColorIntensity
+ System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.ConsoleIntensity
+ System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.ConsoleLayer
+ System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.Underlining

Files

CHANGELOG.md view
@@ -1,6 +1,14 @@ Changes
 =======
 
+Version 0.11.1
+--------------
+
+* On Windows, fix compatability with the Windows I/O Manager (WinIO) introduced
+  in GHC 9.0.1, by incorporating changes made in package `Win32-2.13.2.0` in
+  that regard.
+* Improvements to Haddock documentation.
+
 Version 0.11
 ------------
 
@@ -10,7 +18,6 @@ * On Unix-like operating systems, fix a bug in `getCursorPosition` and
   `hGetCursorPosition`, where the console input stream was was not always
   clear before the cursor position was emitted into it.
-
 
 Version 0.10.3
 --------------
README.md view
@@ -1,4 +1,4 @@-ansi-terminal+ansi-terminal [![GitHub CI](https://github.com/UnkindPartition/ansi-terminal/workflows/CI/badge.svg)](https://github.com/UnkindPartition/ansi-terminal/actions) =============  A Haskell package providing support for 'ANSI' control character sequences for@@ -60,7 +60,7 @@ -------  A full example is-[available](https://github.com/feuerbach/ansi-terminal/blob/master/app/Example.hs),+[available](https://github.com/UnkindPartition/ansi-terminal/blob/master/app/Example.hs), but for a taste of how the library works try the following code:  ``` haskell@@ -98,7 +98,7 @@ Maintainers ----------- -[Mike Pilgrem](https://github.com/mpilgrem) and [Roman Cheplyaka](https://github.com/feuerbach) are the primary maintainers.+[Mike Pilgrem](https://github.com/mpilgrem) and [Roman Cheplyaka](https://github.com/UnkindPartition) are the primary maintainers.  [Oliver Charles](https://github.com/ocharles) is the backup maintainer. Please get in touch with him if the primary maintainers cannot be reached.
ansi-terminal.cabal view
@@ -1,5 +1,5 @@ Name:                ansi-terminal
-Version:             0.11
+Version:             0.11.1
 Cabal-Version:       >= 1.10
 Category:            User Interfaces
 Synopsis:            Simple ANSI terminal support, with Windows compatibility
@@ -10,7 +10,7 @@ License-File:        LICENSE
 Author:              Max Bolingbroke
 Maintainer:          Mike Pilgrem <public@pilgrem.com>, Roman Cheplyaka <roma@ro-che.info>
-Homepage:            https://github.com/feuerbach/ansi-terminal
+Homepage:            https://github.com/UnkindPartition/ansi-terminal
 Build-Type:          Simple
 
 Extra-Source-Files:     src/includes/Common-Include.hs
@@ -23,7 +23,7 @@ 
 Source-repository head
   type:     git
-  location: git://github.com/feuerbach/ansi-terminal.git
+  location: git://github.com/UnkindPartition/ansi-terminal.git
 
 Flag Example
         Description:    Build the example application
src/System/Console/ANSI.hs view
@@ -119,7 +119,7 @@ >   setSGR [Reset]  -- reset to default colour scheme
 
 For many more examples, see the project's extensive
-<https://github.com/feuerbach/ansi-terminal/blob/master/app/Example.hs Example.hs> file.
+<https://github.com/UnkindPartition/ansi-terminal/blob/master/app/Example.hs Example.hs> file.
 -}
 #if defined(WINDOWS)
 module System.Console.ANSI
src/System/Console/ANSI/Windows/Emulator.hs view
@@ -509,5 +509,5 @@ getCPExceptionHandler e = error msg
  where
   msg = "Error: " ++ show e ++ "\nThis error may be avoided by using a " ++
-        "console based on the Win32 console of the Windows API, such as " ++
-        "Command Prompt or PowerShell."
+        "console based on the Windows' Console API, such as Command Prompt " ++
+        "or PowerShell."
src/System/Console/ANSI/Windows/Foreign.hs view
@@ -327,7 +327,7 @@     "Prompt or PowerShell). That may occur, for example, if output has\n" ++
     "been redirected to a file.\n\n" ++
     "If that is unexpected, please post an issue at:\n" ++
-    "https://github.com/feuerbach/ansi-terminal/issues\n"
+    "https://github.com/UnkindPartition/ansi-terminal/issues\n"
   show (ConsoleException errCode) = "ConsoleException " ++ show errCode
 
 instance Exception ConsoleException
src/System/Win32/Compat.hs view
@@ -9,6 +9,10 @@ functionality first added to Win32-2.5.0.0 or Win32-2.5.1.0 (from ansi-terminal
 itself).
 
+Win32-2.9.0.0 introduced support for the Windows I/O Manager, introduced with
+GHC 9.0.1. However, before Win32-2.13.2.0, this changed the behaviour of
+`withHandleFromHANDLE`.
+
 This module provides functions available in those later versions of Win32 to a
 wider range of compilers, reducing the use of CPP pragmas in other modules.
 -}
@@ -32,45 +36,88 @@   , withTString
   ) where
 
-#if !MIN_VERSION_Win32(2,5,0)
-import Foreign.C.Types (CShort (..))
+import System.Win32.Types (BOOL, DWORD, ErrCode, HANDLE, LPCTSTR, LPDWORD,
+  TCHAR, UINT, WORD, failIfFalse_, getLastError, iNVALID_HANDLE_VALUE,
+  nullHANDLE, withTString)
+
+-- Circumstances in which the patching of Win32 package is required
+#if !MIN_VERSION_Win32(2,5,1)||(defined(__IO_MANAGER_WINIO__)&&!MIN_VERSION_Win32(2,13,2))
+#define PATCHING_WIN32_PACKAGE
 #endif
 
-#if !MIN_VERSION_Win32(2,5,1)
+#if !defined(PATCHING_WIN32_PACKAGE)
+
+import System.Win32.Types (SHORT, withHandleToHANDLE)
+
+#else
+
 import Control.Concurrent.MVar (readMVar)
 import Control.Exception (bracket)
-import Foreign.C.Types (CInt (..))
-import Foreign.StablePtr (StablePtr, freeStablePtr, newStablePtr)
 import Data.Typeable (cast)
-import GHC.IO.FD (FD(..)) -- A wrapper around an Int32
+import Foreign.StablePtr (StablePtr, freeStablePtr, newStablePtr)
 import GHC.IO.Handle.Types (Handle (..), Handle__ (..))
-#endif
 
-import System.Win32.Types (BOOL, DWORD, ErrCode, HANDLE, LPCTSTR, LPDWORD,
-  TCHAR, UINT, WORD, failIfFalse_, getLastError, iNVALID_HANDLE_VALUE,
-  nullHANDLE, withTString)
+#if defined(__IO_MANAGER_WINIO__)&&!MIN_VERSION_Win32(2,13,2)
+import GHC.IO.Exception (IOErrorType (InappropriateType), IOException (IOError),
+  ioException)
+import GHC.IO.SubSystem ((<!>))
+import GHC.IO.Windows.Handle (ConsoleHandle, Io, NativeHandle, toHANDLE)
+import System.Win32.Types (withHandleToHANDLEPosix)
+#endif
 
-#if MIN_VERSION_Win32(2,5,0)
+#if !MIN_VERSION_Win32(2,5,0)
+import Foreign.C.Types (CShort (..))
+#else
 import System.Win32.Types (SHORT)
 #endif
 
-#if MIN_VERSION_Win32(2,5,1)
-import System.Win32.Types (withHandleToHANDLE)
+#if !MIN_VERSION_Win32(2,5,1)
+import Foreign.C.Types (CInt (..))
+import GHC.IO.FD (FD(..)) -- A wrapper around an Int32
 #endif
 
+#endif
+
+#if defined(PATCHING_WIN32_PACKAGE)
+
 #if !MIN_VERSION_Win32(2,5,0)
 type SHORT = CShort
 #endif
 
-#if !MIN_VERSION_Win32(2,5,1)
+withStablePtr :: a -> (StablePtr a -> IO b) -> IO b
+withStablePtr value = bracket (newStablePtr value) freeStablePtr
 
-#if defined(i386_HOST_ARCH)
-#define WINDOWS_CCONV stdcall
-#elif defined(x86_64_HOST_ARCH)
-#define WINDOWS_CCONV ccall
+#if defined(__IO_MANAGER_WINIO__)&&!MIN_VERSION_Win32(2,13,2)
+
+withHandleToHANDLE :: Handle -> (HANDLE -> IO a) -> IO a
+withHandleToHANDLE = withHandleToHANDLEPosix <!> withHandleToHANDLENative
+
+-- | `withHandleToHANDLENative` does not behave as expected for GHC option
+-- -with-rtsopts=--io-manager=native when Win32 < 2.13.2. Taken from
+-- package Win32-2.13.2.0 `System.Win32.Types.withHandleToHANDLENative`.
+
+withHandleToHANDLENative :: Handle -> (HANDLE -> IO a) -> IO a
+withHandleToHANDLENative haskell_handle action =
+  withStablePtr haskell_handle $ const $ do
+    let write_handle_mvar = case haskell_handle of
+            FileHandle _ handle_mvar     -> handle_mvar
+            DuplexHandle _ _ handle_mvar -> handle_mvar
+    windows_handle <- readMVar write_handle_mvar >>= handle_ToHANDLE
+    action windows_handle
+ where
+  handle_ToHANDLE :: Handle__ -> IO HANDLE
+  handle_ToHANDLE (Handle__{haDevice = dev}) =
+    case ( cast dev :: Maybe (Io NativeHandle)
+         , cast dev :: Maybe (Io ConsoleHandle)) of
+      (Just hwnd, Nothing) -> return $ toHANDLE hwnd
+      (Nothing, Just hwnd) -> return $ toHANDLE hwnd
+      _                    -> throwErr "not a known HANDLE"
+
+  throwErr msg = ioException $ IOError (Just haskell_handle)
+    InappropriateType "withHandleToHANDLENative" msg Nothing Nothing
+
+-- defined(__IO_MANAGER_WINIO__)&&!MIN_VERSION_Win32(2,13,2)
 #else
-#error Unknown mingw32 arch
-#endif
 
 -- | This bit is all highly dubious. The problem is that we want to output ANSI
 -- to arbitrary Handles rather than forcing people to use stdout.  However, the
@@ -101,12 +148,22 @@     -- Do what the user originally wanted
     action windows_handle
 
+#if defined(i386_HOST_ARCH)
+#define WINDOWS_CCONV stdcall
+#elif defined(x86_64_HOST_ARCH)
+#define WINDOWS_CCONV ccall
+#else
+#error Unknown mingw32 arch
+#endif
+
 -- This essential function comes from the C runtime system. It is certainly
 -- provided by msvcrt, and also seems to be provided by the mingw C library -
 -- hurrah!
 foreign import WINDOWS_CCONV unsafe "_get_osfhandle"
   cget_osfhandle :: CInt -> IO HANDLE
 
-withStablePtr :: a -> (StablePtr a -> IO b) -> IO b
-withStablePtr value = bracket (newStablePtr value) freeStablePtr
+-- defined(__IO_MANAGER_WINIO__)&&!MIN_VERSION_Win32(2,13,2)
+#endif
+
+-- defined(PATCHING_WIN32_PACKAGE)
 #endif
src/includes/Common-Include.hs view
@@ -220,8 +220,8 @@ -- >   getReportedCursorPosition
 --
 -- On Windows operating systems, the function is not supported on consoles, such
--- as mintty, that are not based on the Win32 console of the Windows API.
--- (Command Prompt and PowerShell are based on the Win32 console.)
+-- as mintty, that are not based on the Windows' Console API. (Command Prompt
+-- and PowerShell are based on the Console API.)
 --
 -- @since 0.7.1
 getReportedCursorPosition :: IO String
@@ -238,8 +238,8 @@ -- general function.
 --
 -- On Windows operating systems, the function is not supported on consoles, such
--- as mintty, that are not based on the Win32 console of the Windows API.
--- (Command Prompt and PowerShell are based on the Win32 console.)
+-- as mintty, that are not based on the Windows' Console API. (Command Prompt
+-- and PowerShell are based on the Console API.)
 --
 -- @since 0.10.3
 getCursorPosition :: IO (Maybe (Int, Int))
@@ -256,35 +256,50 @@ -- parsed by 'cursorPosition'.
 --
 -- On Windows operating systems, the function is not supported on consoles, such
--- as mintty, that are not based on the Win32 console of the Windows API.
--- (Command Prompt and PowerShell are based on the Win32 console.)
+-- as mintty, that are not based on the Windows' Console API. (Command Prompt
+-- and PowerShell are based on the Console API.)
 --
 -- @since 0.10.1
 hGetCursorPosition :: Handle -> IO (Maybe (Int, Int))
 
 -- | Attempts to get the current terminal size (height in rows, width in
--- columns), by using 'getCursorPosition' to query the console input stream
--- after attempting to set the cursor position beyond the bottom right corner of
--- the terminal. Uses 'stdout'. If 'stdout' will be redirected, see
--- 'hGetTerminalSize' for a more general function.
+-- columns).
 --
+-- There is no \'ANSI\' control character sequence that reports the terminal
+-- size. So, it attempts to set the cursor position beyond the bottom right
+-- corner of the terminal and then use 'getCursorPosition' to query the console
+-- input stream. It works only on terminals that support each step. Uses
+-- 'stdout'. If 'stdout' will be redirected, see 'hGetTerminalSize' for a more
+-- general function.
+--
 -- On Windows operating systems, the function is not supported on consoles, such
--- as mintty, that are not based on the Win32 console of the Windows API.
--- (Command Prompt and PowerShell are based on the Win32 console.)
+-- as mintty, that are not based on Windows' Console API. (Command Prompt and
+-- PowerShell are based on the Console API.)
 --
+-- For a different approach, one that does not use control character sequences,
+-- see the
+-- <https://hackage.haskell.org/package/terminal-size terminal-size> package.
+--
 -- @since 0.9
 getTerminalSize :: IO (Maybe (Int, Int))
 getTerminalSize = hGetTerminalSize stdout
 
 -- | Attempts to get the current terminal size (height in rows, width in
 -- columns), by writing control character sequences to the specified handle
--- (which will typically be 'stdout' or 'stderr') and using 'hGetCursorPosition'
--- to query the console input stream after attempting to set the cursor position
--- beyond the bottom right corner of the terminal.
+-- (which will typically be 'stdout' or 'stderr').
 --
+-- There is no \'ANSI\' control character sequence that reports the terminal
+-- size. So, it attempts to set the cursor position beyond the bottom right
+-- corner of the terminal and then use 'hGetCursorPosition' to query the console
+-- input stream. It works only on terminals that support each step.
+--
 -- On Windows operating systems, the function is not supported on consoles, such
--- as mintty, that are not based on the Win32 console of the Windows API.
--- (Command Prompt and PowerShell are based on the Win32 console.)
+-- as mintty, that are not based on the Windows' Console API. (Command Prompt
+-- and PowerShell are based on the Console API.)
+--
+-- For a different approach, one that does not use control character sequences,
+-- see the
+-- <https://hackage.haskell.org/package/terminal-size terminal-size> package.
 --
 -- @since 0.10.1
 hGetTerminalSize :: Handle -> IO (Maybe (Int, Int))
src/includes/Exports-Include.hs view
@@ -26,7 +26,7 @@     -- the same.
     --
     -- Also keep in mind that @*Line@ functions are not as portable. See
-    -- <https://github.com/feuerbach/ansi-terminal/issues/10> for the details.
+    -- <https://github.com/UnkindPartition/ansi-terminal/issues/10> for the details.
   , cursorUpLine
   , cursorDownLine
   , hCursorUpLine