Allow/Default use of ANSI color codes on Windows
维护者通常 3 天内回复
评估
- 难度
- 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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
catchorg/Catch2 的其他 Issue
-
Floating point printing should print shortest round-trip value可能已有人在做 @sb123sb123 于 9 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
catchorg/Catch2#3197 · 2 条评论 · 2 个 reaction ·
维护者通常 3 天内回复
-
3rd party bug
难度 4/5 3-5 天 新手友好度 52/100
catchorg/Catch2#3195 · 1 条评论 ·
维护者通常 3 天内回复
-
Feature Request
难度 4/5 3-5 天 新手友好度 48/100
catchorg/Catch2#3185 · 2 条评论 ·
维护者通常 3 天内回复
-
Clock resolution estimation iterations limit可能已有人在做 @Tyagiquamar 于 6 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
catchorg/Catch2#3180 · 1 个 reaction ·
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
维护者通常 3 天内回复
相似的 Issue
-
needs-triage
难度 2/5 1-3 小时 新手友好度 70/100
flashinfer-ai/flashinfer#6212 ·
维护者通常 1 天内回复
-
bug graphics
难度 2/5 1-3 小时 新手友好度 76/100
FlaxEngine/FlaxEngine#4295 · 2 条评论 ·
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
Algorithmiq/monoprop#390 ·
维护者通常 1 天内回复
-
docs
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
8-membered-ring atrop stereo lost in 2026.09.1可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 2/5 半天 新手友好度 86/100
维护者通常 2 天内回复