Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Allow/Default use of ANSI color codes on Windows

Đang mở
#3,003 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@Ext3h đang làm issue này rồi.

Từ ngày 21/7/2025.

  • #3004 của @Ext3h — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
testing-qa

Hướng nghiên cứu

Bắt đầu bằng cách xác định CATCH_INTERNAL_HAS_ISATTY và đường dẫn xử lý màu của Windows, sau đó xem xét cách stdout và các chế độ console được khởi tạo. Kiểm tra hành vi hiện có của Windows và đầu ra ANSI, bao gồm cả stdout được đệm, và xác định là hoàn tất khi các terminal Windows sử dụng màu ANSI một cách đáng tin cậy mà không cần legacy attribute API.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
21.5k
Fork
3.5k
Merge trung bình
3 ngày 5 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của catchorg/Catch2

Tất cả issue của catchorg/Catch2

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.