msys2 / msys2/msys2-runtime

Virtual terminal processing is disabled on MSYS2 in Windows terminal

Open
#91 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
240
Forks
60
Avg merge
2d 3h
Merged PRs (30d)
1

Description

I have this code:

#include <iostream>
#include <windows.h>

int main()
{
    // Ansi output test
    std::cout << "\033[32mgreen\033[0m" << std::endl;
    // Get the current console mode
    DWORD mode = 0;
    if (GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &mode) == 0)
        std::cout << "failed" << std::endl;

    std::cout << "Mode : " << mode << std::endl;

    // Enable vt100
    SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);

    // Ansi output test
    std::cout << "\033[32mgreen\033[0m" << std::endl;
    // Get the current console mode
    mode = 0;
    if (GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &mode) == 0)
        std::cout << "failed" << std::endl;

    std::cout << "Mode : " << mode << std::endl;

    return 0;
}

When I compile it with the msvc and invoke it from the Windows Terminal then it returns 7.
When I compile it with the ucrt64 g++/clang++ and invoke it from the wterminal then it returns 3.

Here are defines for the return value:

#define ENABLE_PROCESSED_OUTPUT             0x0001
#define ENABLE_WRAP_AT_EOL_OUTPUT           0x0002
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING  0x0004

Problem is that the vt100 support (ENABLE_VIRTUAL_TERMINAL_PROCESSING flag) is disabled when compiled with the ucrt64 g++/clang++ although the terminal obviously supports vt100 processing.

The question is does MSYS2 have any effect on this? Or does MSYS2 modify these flags or it is completely on the winapi, why it is disabled by default on msys2 and enabled on msvc.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided C++ reproducer and run it under MSVC and the ucrt64 g++/clang++ environment in Windows Terminal. Compare the GetConsoleMode and SetConsoleMode results, then trace whether MSYS2 changes the console handle or mode. Done means identifying the cause of the differing flags and defining the required MSYS2 behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.