haskell / win32

Haskell support for the Win32 API
http://hackage.haskell.org/package/Win32
Other
97 stars 63 forks source link

Add GetConsoleScreenBufferInfoEx #206

Closed mpilgrem closed 2 years ago

mpilgrem commented 2 years ago

Description

The function retrieves extended information about the specified console screen buffer. See https://docs.microsoft.com/en-us/windows/console/getconsolescreenbufferinfoex.

Also adds getCurrentConsoleScreenBufferInfoEx, corresponding to getCurrentConsoleScreenBufferInfo.

For convenience, re-exports Graphics.Win32.GDI.Types.COLORREF from module System.Win32.Console.

Motivation and Context

Provides access to extended information about the specified console screen buffer.

Types of changes

Checklist:

mpilgrem commented 2 years ago

I do not know why the CI has failed. I cannot get the CI 'Details' links to work (I get 'ERR_CONNECTION_TIMED_OUT' in my browser). However, I have tested locally by: (a) building with stack and lts-19.9 (GHC 9.0.2); and (b) using with this test:

module Main where

import System.IO (stderr, stdout)
import System.Win32.Console (CONSOLE_SCREEN_BUFFER_INFOEX (..),
  getCurrentConsoleScreenBufferInfoEx, getConsoleScreenBufferInfoEx)
import System.Win32.Types (withHandleToHANDLE)
import Text.Printf (printf)

main :: IO ()
main = do
  mapM_ (\h -> withHandleToHANDLE h $ \h' -> do
    output =<< getConsoleScreenBufferInfoEx h')
    [stdout, stderr]
  output =<< getCurrentConsoleScreenBufferInfoEx

output :: CONSOLE_SCREEN_BUFFER_INFOEX -> IO ()
output csbix = do
  print csbix
  let ct = colorTable csbix
  putStr "Colour table: "
  mapM_ (printf "%06x ") ct
  putStr "\n"
Mistuke commented 2 years ago

Hi, thanks for the PR! sorry for the delay getting to it. I'm on vacation and will be back tomorrow and will review it then.

Mistuke commented 2 years ago

Hi, Sorry for the delay, the internal CI is failing because Win32 tries to maintain compatibility with GHC's as old as 7.6

To that end the change is failing due to

In file included from Process.hsc:76:0:
include/tlhelp32_compat.h:17:0: warning: "TH32CS_SNAPHEAPLIST" redefined
e:\ghc\i386\ghc-7.8.4\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/tlhelp32.h:28:0: note: this is the location of the previous definition
include/tlhelp32_compat.h:18:0: warning: "TH32CS_SNAPPROCESS" redefined
e:\ghc\i386\ghc-7.8.4\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/tlhelp32.h:29:0: note: this is the location of the previous definition
include/tlhelp32_compat.h:19:0: warning: "TH32CS_SNAPTHREAD" redefined
e:\ghc\i386\ghc-7.8.4\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/tlhelp32.h:30:0: note: this is the location of the previous definition
include/tlhelp32_compat.h:20:0: warning: "TH32CS_SNAPMODULE" redefined
e:\ghc\i386\ghc-7.8.4\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../include/tlhelp32.h:31:0: note: this is the location of the previous definition
Console.hsc: In function 'main':
Console.hsc:192:5: error: 'CONSOLE_SCREEN_BUFFER_INFOEX' undeclared (first use in this function)
Console.hsc:192:5: note: each undeclared identifier is reported only once for each function it appears in
Console.hsc:193:5: error: expected specifier-qualifier-list before 'CONSOLE_SCREEN_BUFFER_INFOEX'
Console.hsc:193:5: error: 'struct <anonymous>' has no member named 'y__'
Console.hsc:195:5: error: expected specifier-qualifier-list before 'CONSOLE_SCREEN_BUFFER_INFOEX'
Console.hsc:195:5: error: expected ';' before ')' token

So CONSOLE_SCREEN_BUFFER_INFOEX is undefined in that version. The way we work around these issues is by defining a compat file with the structure definition in it. See e.g. https://github.com/haskell/win32/pull/63/files

The idea is we add header files like winternl_compat.h which get included in those versions that require it.

Mistuke commented 2 years ago

The external CI also showed the same errors https://ci.appveyor.com/project/hvr/win32 but it looks like the github integration is broken. Will look into that.

mpilgrem commented 2 years ago

Thank you. I will amend the pull request to try and accommodate that.

mpilgrem commented 2 years ago

@Mistuke, I've made changes for that and the CI now passes.

Mistuke commented 2 years ago

Great, thank you!