Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetConsoleWindowInfo + cmd/powershell yields invisible prompt #255

Closed
rprichard opened this issue Sep 17, 2018 · 2 comments
Closed

SetConsoleWindowInfo + cmd/powershell yields invisible prompt #255

rprichard opened this issue Sep 17, 2018 · 2 comments
Labels
Product-Conhost For issues in the Console codebase Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Milestone

Comments

@rprichard
Copy link

  • Your Windows build number: [Version 10.0.17760.1]

What you're doing and what's happening:

Steps:

  1. Create a new console.
  2. In the new console, reduce the height of the console window using SetConsoleWindowInfo.
  3. Spawn cmd.exe or powershell.exe

The prompt appears in the console buffer, but the console scrolls down so that the cursor and the prompt are both invisible:

invisible-prompt

What's wrong / what should be happening instead:

The window should remain at the top of the console buffer, so that the cursor and prompt are still visible.

This issue explains at least some of the winpty breakage reported at microsoft/vscode#57803. Any time the console window moves down, winpty assumes that something has been written to the bottommost line of the window. (e.g. In this case, it sees a window full of blank lines.) The console window is blank, so the winpty terminal output is also blank.

The problem doesn't affect the Python 3.7 REPL. I haven't tested other command-line shells/interpreters.

Test case:

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <process.h>

static int childProcess() {
    // Divide the console window height in half using SetConsoleWindowInfo.
    // Using SetConsoleScreenBufferInfoEx instead seems to avoid this problem,
    // but it has other problems.
    HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFOEX info = { sizeof(info) };
    GetConsoleScreenBufferInfoEx(conout, &info);
    const int h = info.srWindow.Bottom - info.srWindow.Top + 1;

    // Make the console buffer smaller so the problem is more apparent.
    SetConsoleScreenBufferSize(conout, COORD {
        (SHORT)(info.srWindow.Right - info.srWindow.Left + 1),
        (SHORT)(h + 100),
    });

    // Reduce the window height by half.
    info.srWindow.Bottom = info.srWindow.Top + h / 2 - 1;
    SetConsoleWindowInfo(conout, TRUE, &info.srWindow);

    // At this point, the console window is still at the top of the buffer.

    // Run cmd.exe (or powershell.exe). The shell prompt appears at the
    // expected place in the console buffer, but the window is moved below the
    // prompt and below the cursor, making them invisible.
    _execl("C:\\Windows\\system32\\cmd.exe", "C:\\Windows\\system32\\cmd.exe", NULL);
    return 0;
}

int main(int argc, char *argv[]) {
    if (argc == 2 && !strcmp(argv[1], "child")) {
        return childProcess();
    }

    char cmdline[4096];
    snprintf(cmdline, sizeof(cmdline), "\"%s\" child", argv[0]);
    STARTUPINFOA sui = { sizeof(sui) };
    PROCESS_INFORMATION pi = {};
    CreateProcessA(argv[0], cmdline, nullptr, nullptr, TRUE,
                   CREATE_NEW_CONSOLE, nullptr, nullptr, &sui, &pi);
    return 0;
}
@zadjii-msft
Copy link
Member

Thanks! Filed MSFT:19013571 to track internally.

@zadjii-msft zadjii-msft added Work-Item It's being tracked by an actual work item internally. (to be removed soon) Product-Conhost For issues in the Console codebase labels Sep 17, 2018
@zadjii-msft zadjii-msft added this to the 19H1 milestone Sep 17, 2018
@zadjii-msft
Copy link
Member

I believe this is #270. Just tried it out - on RS5, this is definitely broken, but this is working as expected on newer builds.

As always, thanks for giving exact repro steps with a code sample. Really makes this a pleasure to debug ❤️

@zadjii-msft zadjii-msft added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Work-Item It's being tracked by an actual work item internally. (to be removed soon) labels Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Product-Conhost For issues in the Console codebase Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

2 participants