zig icon indicating copy to clipboard operation
zig copied to clipboard

Added Wrappers for Windows API functions `GetConsoleMode` and `SetConsoleMode`

Open SeanTUT opened this issue 1 year ago • 1 comments

  • Added extern SetConsoleMode function to os.windows.kernel32
  • Added GetConsoleMode function to os.windows
  • Added SetConsoleMode function to os.windows
  • Added ConsoleMode type to std.os.windows
    • Returned by os.windows.GetConsoleMode
    • Passed into os.windows.SetConsoleMode
    • This is a packed union backed by a DWORD value
    • Has a field dword which is to be directly used in calls to the above API functions
    • Has a field input representing flags for console input buffers
    • Has a field screenbuf representing flags for console screen buffers
  • Removed ENABLE_VIRTUAL_TERMINAL_PROCESSING from os.windows
    • This is made redundant by ConsoleMode.screenbuf.ENABLE_VIRTUAL_TERMINAL_PROCESSING
  • Tweaked fs.supportsAnsiEscapeCodes to use this new interface

SeanTUT avatar May 08 '24 17:05 SeanTUT

See https://github.com/ziglang/zig/pull/18715 for a related PR and some history of the SetConsoleMode binding.

squeek502 avatar May 09 '24 08:05 squeek502

As it stands, the two main things holding me back from submitting this PR as is are:

  1. Most obviously, the checks for windows don't pass, and the logs for the action provide very little info. Considering that none of these changes should be breaking for the wider std, and that at one point a single Mac check failed but but then resolved itself for no discernible reason, especially given this is Windows specific code, makes me tempted to think that these checks may have failed in some sort of error, but I don't want to be so quick to jump to that conclusion, so I want to find out what might be causing this. However, the previously mentioned lack of detail in the action logs is making this difficult, as it compiles fine on my machine
  2. I simply haven't been able to find any documentation ENABLE_AUTO_POSITION. The closest I've found is a few articles that mention it in passing, only remarking that it in undocumented. If anyone has details about the ENABLE_AUTO_POSITION flag, any information would be appreciated, as I am adding doc comments to each field of ConsoleMode

SeanTUT avatar May 10 '24 03:05 SeanTUT

  1. I simply haven't been able to find any documentation ENABLE_AUTO_POSITION. The closest I've found is a few articles that mention it in passing, only remarking that it in undocumented. If anyone has details about the ENABLE_AUTO_POSITION flag, any information would be appreciated, as I am adding doc comments to each field of ConsoleMode

https://github.com/microsoft/terminal/discussions/15685#discussioncomment-6419528

alexrp avatar May 10 '24 03:05 alexrp

  • I think a change you've made is inadvertently exposing/triggering a bug in the C backend (zig1.exe trying to compile Zig to zig2.c using the C backend is what's failing). I can reproduce the CI failures locally when trying to build Zig from source in this branch.
  • https://github.com/ziglang/zig/pull/18715 has been merged, so you'll need to rebase and fix the conflicts

squeek502 avatar May 10 '24 05:05 squeek502

https://github.com/ziglang/zig/pull/18715 has been merged, so you'll need to rebase and fix the conflicts

While resolving the conflicts, I removed the DISABLE_NEWLINE_AUTO_RETURN declaration, as in this PR, it would be made redundant by the ConsoleMode.screenbuf.DISABLE_NEWLINE_AUTO_RETURN field, although I would like to hear if @Garfield550 wants to weigh in on this

SeanTUT avatar May 13 '24 15:05 SeanTUT

Closing this PR for the time being, as progress has been slow, and it is currently based off of my master branch (I thought this would be much simpler than it turned out to be)

SeanTUT avatar May 16 '24 22:05 SeanTUT