Skip to content

Doesn't work with Windows terminals #17

Closed

Description

@wisplite

I'm trying to benchmark the Windows Command Prompt/Windows Terminal, and no matter which I choose it seems to think the screen is much smaller than it is (I have it set to 120x30, it thinks it's running at 30x2), and the rendering is completely broken. The README states that it works on Windows, but while it can technically compile and run on Windows, it doesn't actually run properly, so I feel that is a little misleading.

Activity

  1. wisplite commented on Dec 25, 2024

    @wisplite
    Author

    After further testing, this seems to be a general issue on Windows for whatever reason, regardless of terminal emulator. VSCode exhibits the same behavior, while the README says it has been tested and should work well.

  2. lucyyyyyyy commented on Jan 1, 2025

    @lucyyyyyyy

    Alacritty on Windows also exhibits the same behaviour

  3. const-void commented on Jan 1, 2025

    @const-void
    Owner
  4. self-assigned this
    on Jan 1, 2025
  5. const-void commented on Jan 1, 2025

    @const-void
    Owner

    Looking into the issue, Windows was reportedly compatible at one point. No doubt something snapped loose along the way. Stand by!

  6. const-void commented on Jan 3, 2025

    @const-void
    Owner

    I will be committing a partial Windows fix sometime in the next 2-3 days so that at least the test operates. For whatever reason a prior MR is trying to calculate the H + W vs polling the terminal directly via WinAPI.

    That is simple enough, however - CMD.EXE and Win VSCode both are unhappy w/ANSI sequences; CMD.EXE refuses to acknowledge them, at all, and VSCode is rendering odd font characters in the flame portion. I will have to experiment a bit to determine what CMD.EXE expects vs OSX/Linux. This may take a bit more time but that is part of the fun!

  7. added
    bug
    on Jan 3, 2025
  8. pinned this issue on Jan 3, 2025
  9. n-prat commented on Jan 13, 2025

    @n-prat

    I have managed to make it sort of run with a small patch (ChatGPT 🫣):

    index 8acdd9c..69d3416 100644
    --- a/src/main.zig
    +++ b/src/main.zig
    @@ -153,12 +153,13 @@ pub fn getTermSz(tty: std.posix.fd_t) !TermSz {
         if (builtin.os.tag == .windows) {
             //Microsoft Windows Case
             var info: win32.CONSOLE_SCREEN_BUFFER_INFO = undefined;
    -        if (0 == win32.GetConsoleScreenBufferInfo(tty, &info)) switch (std.os.windows.kernel32.GetLastError()) {
    +        const hConsole = std.os.windows.GetStdHandle(win32.STD_OUTPUT_HANDLE) catch return std.os.windows.unexpectedError(std.os.windows.kernel32.GetLastError()
    );
    +        if (0 == win32.GetConsoleScreenBufferInfo(hConsole, &info)) switch (std.os.windows.kernel32.GetLastError()) {
                 else => |e| return std.os.windows.unexpectedError(e),
             };
             return TermSz{
    -            .height = @intCast(info.srWindow.Bottom - info.srWindow.Top + 1),
    -            .width = @intCast(info.srWindow.Right - info.srWindow.Left + 1),
    +            .height = @intCast(info.dwSize.Y),
    +            .width = @intCast(info.dwSize.X),
             };
         } else {
             //Linux-MacOS Case
    @@ -704,6 +705,8 @@ pub fn main() anyerror!void {
     const win32 = struct {
         pub const BOOL = i32;
         pub const HANDLE = std.os.windows.HANDLE;
    +    // https://learn.microsoft.com/en-us/windows/console/getstdhandle#parameters
    +    pub const STD_OUTPUT_HANDLE: u32 = 0xFFFFFFF5; // 0xFFFFFFF5 == -11
         pub const COORD = extern struct {
             X: i16,
             Y: i16,
    

    With this: mode con and "Screen size: 198w x 58h" match

    Tested with Wezterm and Windows Terminal

    edit: using bisect:

    git bisect bad
    342c47eb1ba371d37b9cbd1a1db85f7bbe3b6adf is the first bad commit
    commit 342c47eb1ba371d37b9cbd1a1db85f7bbe3b6adf
    Author: Sylvain Rabot <[email protected]>
    Date:   Fri Nov 15 14:19:22 2024 +0100
    

    Which is weird, b/c this commit only changed a bunch of u16 to u32; still need to understand why some cast fail???

    edit2: the bad commit "works" when resetting CONSOLE_SCREEN_BUFFER_INFO.wAttributes to be u16 which it is supposed to be
    cf windows-data-types
    but that is still (probably) not the best way to compute .height and .width on Win32

  10. const-void commented on Feb 1, 2025

    @const-void
    Owner

    I have managed to make it sort of run with a small patch (ChatGPT 🫣):

    Thank you for the patch! This is perfect. I am retooling the windows portion in "win32" so we can find/replace without mangling how windows terminal works.

    Almost there :)

    Time is of course in short supply for us all, so thank you for sharing your findings...just what is needed!

  11. const-void commented on Feb 1, 2025

    @const-void
    Owner

    Merged into main. VS Code works, ish, however CMD and Powershell do not. Will need more research to understand why CMD.EXE doesn't just "work" with the ANSI commands that function with no issues in OSX, and maybe no issues with Linux.

    Leaving open, more is needed!

  12. n-prat commented on Feb 1, 2025

    @n-prat

    Thanks for that!

    What are you testing with on Windows? Wezterm is working, Windows Terminal+CMD is OK(but really slow) and Windows Terminal+Powershell seems to work-ish [the setup looks weird but it renders fine].
    Note that I have not tried on Linux or Mac, so I don't really have a reference for how it supposed to look like.

    Image

    Image

  13. const-void commented on Feb 8, 2025

    @const-void
    Owner

    Yes; testing on Windows, CMD, Stock Terminal and VSCode.

    The output is broken, no question. It's better--code compiles + runs, we get colors...and it usually does something...but it doesn't do it correctly.

    There are two modes - the first is a really basic "terminal test". When it works properly, you see:

    1. Terminal Size
    2. 16 colors
    3. 216 colors
    4. Grayscale
    5. Animation test - various quotes fade in and out from view.

    Press return, and the actual fire begins.

    With CMD and Powershell, the Animation test fails - instead of repainting quotes with more visible, then less visible, text, the terminal is scrolling each quote.

    The windows build is now 100% win32 API driven; no "boilerplate" zig is in the loop. So one would think, DOOM-fire-zig should work OTB. However, I suspect something in the text output is causing the more stock Windows terminals to ignore the ANSI commands. I am wondering if it is newline.

    When running from inside VS Code, you get a better representation (most of the time).

    In contrast, on MacOS, on alacrity, a full screen fire (221 x 56) pushes 180kb per frame at 250+ fps.

    MacOS stock Terminal performs terribly (<24fps); so terrible performance in stock Windows is expected. However, the Animation test should animate vs scroll! After that, performance is a function of the terminal.

  14. const-void commented on Feb 8, 2025

    @const-void
    Owner

    Digging more deeply, one bug is the below - CONSOLE_SCREEN_BUFFER_INFO.dwSize is the buffer size, which is HUGE compared to the window size. For height, it is reporting over 9000 lines!!!! Or whatever buffer value we happen to have for our windows console / terminal...which for me, 9k lines is NOT ENOUGH!

    I expect out of memory errors before I run out of vertical buffer :)

    Bug:

            return TermSz{
                .height = @intCast(info.dwSize.Y),
                .width = @intCast(info.dwSize.X),
            };

    I will be reverting back to the prior calculation, where the viewable portion of the buffer can be used to calculate the "terminal" dimensions.

        return TermSz{
                .height = @intCast(info.srWindow.Bottom - info.srWindow.Top + 1),
                .width = @intCast(info.srWindow.Right - info.srWindow.Left + 1),
            };
  15. const-void commented on Feb 8, 2025

    @const-void
    Owner

    The win-fix branch appears to function 99% in windows - need to test MacOS before it goes into main. All are welcome to try it out - zig 0.13, VS Code, and Windows 10 - CMD + Powershell + VS Terminal, all worked...20 fps?

    https://github.com/const-void/DOOM-fire-zig/tree/win-fix

    The missing component right now appears to be UTF-8 glyphs, which is very odd.

  16. linked a pull request that will close this issueMicrosoft Windows Fix #27on Feb 9, 2025
  17. const-void commented on Feb 9, 2025

    @const-void
    Owner

    Windows fixes have been merged into the main branch; if you find issues, feel free to reopen this issue or create a new one. I did not intend to close issue #17, but maybe it's okay. Hopefully, DOOM-fire-zig.exe functions for all!

  18. unpinned this issue on Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions