Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Allow/Default use of ANSI color codes on Windows

未关闭
#3,003 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

@Ext3h 已经在做这个了。

开始于 2025年7月21日。

  • #3004 来自 @Ext3h —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
cpp
领域
testing-qa

调研方向

首先定位 CATCH_INTERNAL_HAS_ISATTY 和 Windows 颜色处理路径,然后检查 stdout 和控制台模式是如何初始化的。检查现有的 Windows 和 ANSI 输出行为,包括缓冲的 stdout,并将“Windows 终端能够可靠地使用 ANSI 颜色而不使用旧版属性 API”定义为完成标准。

由索引模型根据 Issue 内容生成。

描述

Description
With a little snippet during initialization, Windows 10 and newer support ANSI color codes out of the box:

#ifdef _WIN32
    HANDLE outputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD mode = 0;
    if (GetConsoleMode(outputHandle, &mode))
    {
        mode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
        SetConsoleMode(outputHandle, mode);
    }
#endif // _WIN32

The CATCH_INTERNAL_HAS_ISATTY is somewhat malformed - Windows has isatty too (in header #include <io.h> instead of #include <unistd.h>) - but what it doesn't have is STDOUT_FILENO so the portable solution for that is isatty(fileno(stdout)).

On Windows 10 or newer (or in case that covers ALL support Windows platforms: For every Windows-platform in general), the ANSI color code support should be preferred unconditionally over the legacy text attribute API.

Additional context
This avoids a lot of issues you'd otherwise have with the Windows terminal handling - among others that setting colors via SetConsoleTextAttribute on Windows breaks horribly when the application under test is enabling output buffering for stdout as the legacy API for color codes only every works as long as stdout is byte-buffered only.

主要语言
C++
星标
21.5k
派生
3.5k
平均合并
2 天 21 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

catchorg/Catch2 的其他 Issue

查看 catchorg/Catch2 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。