Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package ghc-terminal-size for openSUSE:Factory checked in at 2023-04-04 21:23:45 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-terminal-size (Old) and /work/SRC/openSUSE:Factory/.ghc-terminal-size.new.19717 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-terminal-size" Tue Apr 4 21:23:45 2023 rev:7 rq:1076070 version:0.3.4 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-terminal-size/ghc-terminal-size.changes 2022-08-01 21:29:07.397436878 +0200 +++ /work/SRC/openSUSE:Factory/.ghc-terminal-size.new.19717/ghc-terminal-size.changes 2023-04-04 21:24:05.634445117 +0200 @@ -1,0 +2,14 @@ +Thu Mar 30 17:08:33 UTC 2023 - Peter Simons <[email protected]> + +- Updated spec file to conform with ghc-rpm-macros-2.5.2. + +------------------------------------------------------------------- +Mon Mar 13 14:27:31 UTC 2023 - Peter Simons <[email protected]> + +- Update terminal-size to version 0.3.4. + 0.3.4 + ===== + + * Provided `hSize` on Windows. (https://github.com/biegunka/terminal-size/pull/18) + +------------------------------------------------------------------- Old: ---- terminal-size-0.3.3.tar.gz New: ---- terminal-size-0.3.4.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-terminal-size.spec ++++++ --- /var/tmp/diff_new_pack.eM1kWZ/_old 2023-04-04 21:24:06.254448628 +0200 +++ /var/tmp/diff_new_pack.eM1kWZ/_new 2023-04-04 21:24:06.258448651 +0200 @@ -1,7 +1,7 @@ # # spec file for package ghc-terminal-size # -# Copyright (c) 2022 SUSE LLC +# Copyright (c) 2023 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,14 +17,17 @@ %global pkg_name terminal-size +%global pkgver %{pkg_name}-%{version} Name: ghc-%{pkg_name} -Version: 0.3.3 +Version: 0.3.4 Release: 0 Summary: Get terminal window height and width License: BSD-3-Clause URL: https://hackage.haskell.org/package/%{pkg_name} Source0: https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz BuildRequires: ghc-Cabal-devel +BuildRequires: ghc-base-devel +BuildRequires: ghc-base-prof BuildRequires: ghc-rpm-macros ExcludeArch: %{ix86} @@ -41,6 +44,22 @@ %description devel This package provides the Haskell %{pkg_name} library development files. +%package -n ghc-%{pkg_name}-doc +Summary: Haskell %{pkg_name} library documentation +Requires: ghc-filesystem +BuildArch: noarch + +%description -n ghc-%{pkg_name}-doc +This package provides the Haskell %{pkg_name} library documentation. + +%package -n ghc-%{pkg_name}-prof +Summary: Haskell %{pkg_name} profiling library +Requires: ghc-%{pkg_name}-devel = %{version}-%{release} +Supplements: (ghc-%{pkg_name}-devel and ghc-prof) + +%description -n ghc-%{pkg_name}-prof +This package provides the Haskell %{pkg_name} profiling library. + %prep %autosetup -n %{pkg_name}-%{version} @@ -62,4 +81,9 @@ %files devel -f %{name}-devel.files %doc CHANGELOG.markdown README.markdown +%files -n ghc-%{pkg_name}-doc -f ghc-%{pkg_name}-doc.files +%license LICENSE + +%files -n ghc-%{pkg_name}-prof -f ghc-%{pkg_name}-prof.files + %changelog ++++++ terminal-size-0.3.3.tar.gz -> terminal-size-0.3.4.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/terminal-size-0.3.3/CHANGELOG.markdown new/terminal-size-0.3.4/CHANGELOG.markdown --- old/terminal-size-0.3.3/CHANGELOG.markdown 2022-03-20 21:33:56.000000000 +0100 +++ new/terminal-size-0.3.4/CHANGELOG.markdown 2023-03-13 11:59:33.000000000 +0100 @@ -1,3 +1,8 @@ +0.3.4 +===== + + * Provided `hSize` on Windows. (https://github.com/biegunka/terminal-size/pull/18) + 0.3.3 ===== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/terminal-size-0.3.3/README.markdown new/terminal-size-0.3.4/README.markdown --- old/terminal-size-0.3.3/README.markdown 2022-03-20 21:15:15.000000000 +0100 +++ new/terminal-size-0.3.4/README.markdown 2023-03-13 11:57:10.000000000 +0100 @@ -1,7 +1,7 @@ terminal-size ============= -[](https://hackage.haskell.org/package/terminal-size) +[](https://hackage.haskell.org/package/terminal-size) [](https://travis-ci.org/biegunka/terminal-size) Get terminal window width and height @@ -14,3 +14,44 @@ >>> size Just (Window {height = 60, width = 112}) ``` + +Test +---- + +Compile test.hs and run it in a terminal. Here is what I get on Linux: + +``` +> ghc test.hs +> ./test +With redirected stdin + hSize stdin = Nothing + hSize stdout = Just (Window {height = 19, width = 87}) + hSize stderr = Just (Window {height = 19, width = 87}) +With redirected stdout + hSize stdin = Just (Window {height = 19, width = 87}) + hSize stdout = Nothing + hSize stderr = Just (Window {height = 19, width = 87}) +With redirected stderr + hSize stdin = Just (Window {height = 19, width = 87}) + hSize stdout = Just (Window {height = 19, width = 87}) + hSize stderr = Nothing +``` + +On MINGW/MSYS the output is the same. + +On Windows with cmd.exe I get + +``` +With redirected stdin + hSize stdin = Nothing + hSize stdout = Just (Window {height = 40, width = 164}) + hSize stderr = Just (Window {height = 40, width = 164}) +With redirected stdout + hSize stdin = Nothing + hSize stdout = Nothing + hSize stderr = Just (Window {height = 40, width = 164}) +With redirected stderr + hSize stdin = Nothing + hSize stdout = Just (Window {height = 40, width = 164}) + hSize stderr = Nothing +``` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/terminal-size-0.3.3/src/System/Console/Terminal/Size.hs new/terminal-size-0.3.4/src/System/Console/Terminal/Size.hs --- old/terminal-size-0.3.3/src/System/Console/Terminal/Size.hs 2022-03-20 21:15:15.000000000 +0100 +++ new/terminal-size-0.3.4/src/System/Console/Terminal/Size.hs 2023-03-13 11:57:10.000000000 +0100 @@ -9,8 +9,8 @@ , size #if !defined(mingw32_HOST_OS) , fdSize - , hSize #endif + , hSize ) where import System.Console.Terminal.Common @@ -19,8 +19,8 @@ #else import qualified System.Console.Terminal.Posix as Host import System.Posix.Types(Fd) -import System.IO(Handle) #endif +import System.IO(Handle) -- | Get terminal window width and height for @stdout@. @@ -45,9 +45,13 @@ -- Nothing fdSize :: Integral n => Fd -> IO (Maybe (Window n)) fdSize = Host.fdSize +#endif --- | /Not available on Windows:/ --- Same as 'fdSize', but takes 'Handle' instead of 'Fd' (file descriptor). +-- | Same as 'fdSize', but takes 'Handle' instead of 'Fd' (file descriptor). +-- +-- Note that on Windows with shells that use the native console API (cmd.exe, +-- PowerShell) this works only for output handles like 'stdout' and 'stderr'; +-- for input handles like 'stdin' it always returns 'Nothing'. -- -- >>> import System.Console.Terminal.Size -- >>> import System.IO @@ -55,4 +59,3 @@ -- Just (Window {height = 56, width = 85}) hSize :: Integral n => Handle -> IO (Maybe (Window n)) hSize = Host.hSize -#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/terminal-size-0.3.3/src/System/Console/Terminal/Windows.hs new/terminal-size-0.3.4/src/System/Console/Terminal/Windows.hs --- old/terminal-size-0.3.3/src/System/Console/Terminal/Windows.hs 2022-03-20 21:15:15.000000000 +0100 +++ new/terminal-size-0.3.4/src/System/Console/Terminal/Windows.hs 2023-03-13 11:57:10.000000000 +0100 @@ -1,63 +1,48 @@ - -module System.Console.Terminal.Windows(size) where +module System.Console.Terminal.Windows(size, hSize) where import System.Console.Terminal.Common -import Control.Monad -import Data.Word -import Foreign.Ptr -import Foreign.Storable -import Foreign.Marshal.Alloc import System.Exit import System.IO +import System.IO.Error (catchIOError) import System.Process - -type HANDLE = Ptr () - -data CONSOLE_SCREEN_BUFFER_INFO - -sizeCONSOLE_SCREEN_BUFFER_INFO :: Int -sizeCONSOLE_SCREEN_BUFFER_INFO = 22 - -posCONSOLE_SCREEN_BUFFER_INFO_srWindow :: Int -posCONSOLE_SCREEN_BUFFER_INFO_srWindow = 10 -- 4 x Word16 Left,Top,Right,Bottom - -c_STD_OUTPUT_HANDLE :: Word32 -c_STD_OUTPUT_HANDLE = -11 - -foreign import stdcall unsafe "windows.h GetConsoleScreenBufferInfo" - c_GetConsoleScreenBufferInfo :: HANDLE -> Ptr CONSOLE_SCREEN_BUFFER_INFO -> IO Bool - -foreign import stdcall unsafe "windows.h GetStdHandle" - c_GetStdHandle :: Word32 -> IO HANDLE - +import System.Win32.Console + ( CONSOLE_SCREEN_BUFFER_INFO(srWindow) + , SMALL_RECT(..) + , getConsoleScreenBufferInfo + ) +import System.Win32.Types (HANDLE, withHandleToHANDLE) size :: Integral n => IO (Maybe (Window n)) -size = do - hdl <- c_GetStdHandle c_STD_OUTPUT_HANDLE - allocaBytes sizeCONSOLE_SCREEN_BUFFER_INFO $ \p -> do - b <- c_GetConsoleScreenBufferInfo hdl p - if not b - then do -- This could happen on Cygwin or MSYS - let stty = (shell "stty size") { - std_in = UseHandle stdin - , std_out = CreatePipe - , std_err = CreatePipe - } - (_, mbStdout, _, rStty) <- createProcess stty - exStty <- waitForProcess rStty - case exStty of - ExitFailure _ -> return Nothing - ExitSuccess -> - maybe (return Nothing) - (\hSize -> do - sizeStr <- hGetContents hSize - let [r, c] = map read $ words sizeStr :: [Int] - return $ Just $ Window (fromIntegral r) (fromIntegral c) - ) - mbStdout - else do - [left,top,right,bottom] <- forM [0..3] $ \i -> do - v <- peekByteOff p ((i*2) + posCONSOLE_SCREEN_BUFFER_INFO_srWindow) - return $ fromIntegral (v :: Word16) - return $ Just $ Window (1+bottom-top) (1+right-left) +size = hSize stdout + +hSize :: Integral n => Handle -> IO (Maybe (Window n)) +hSize hdl = + withHandleToHANDLE hdl nativeSize + `catchIOError` \_ -> do + -- Fallback to use for Cygwin or MSYS + let stty = (shell "stty size") { + std_in = UseHandle hdl + , std_out = CreatePipe + , std_err = CreatePipe + } + (_, mbStdout, _, rStty) <- createProcess stty + exStty <- waitForProcess rStty + case exStty of + ExitFailure _ -> return Nothing + ExitSuccess -> + maybe (return Nothing) + (\out -> do + sizeStr <- hGetContents out + let [r, c] = map read $ words sizeStr :: [Int] + return $ Just $ Window (fromIntegral r) (fromIntegral c) + ) + mbStdout + +nativeSize :: Integral n => HANDLE -> IO (Maybe (Window n)) +nativeSize hdl = do + rect <- srWindow <$> getConsoleScreenBufferInfo hdl + return $ Just $ Window + { height = fromIntegral (1 + bottomPos rect - topPos rect) + , width = fromIntegral (1 + rightPos rect - leftPos rect) + } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/terminal-size-0.3.3/terminal-size.cabal new/terminal-size-0.3.4/terminal-size.cabal --- old/terminal-size-0.3.3/terminal-size.cabal 2022-03-20 21:32:33.000000000 +0100 +++ new/terminal-size-0.3.4/terminal-size.cabal 2023-03-13 11:59:37.000000000 +0100 @@ -1,5 +1,5 @@ name: terminal-size -version: 0.3.3 +version: 0.3.4 synopsis: Get terminal window height and width description: Get terminal window height and width without ncurses dependency. @@ -21,7 +21,7 @@ source-repository this type: git location: https://github.com/biegunka/terminal-size - tag: 0.3.3 + tag: 0.3.4 library default-language: @@ -34,7 +34,8 @@ ghc-prim if os(windows) build-depends: - process + process, + Win32 >= 2.13.2.0 && < 2.14 build-tools: hsc2hs
