Can't show ansi color on windows if use git bash
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- bash, python
- Lĩnh vực
- cli, operating-systems
Hướng nghiên cứu
Bắt đầu trong formatting_windows.py tại initialize_or_disable và kiểm tra cách các môi trường Windows hiện quyết định có khởi tạo colorama hay không. Tái hiện hành vi trong Git Bash, sau đó xác minh rằng Git Bash tránh việc wrapping không cần thiết trong khi các shell Windows khác vẫn giữ nguyên cách xử lý hiện tại. Phạm vi và hành vi của tùy chọn cấu hình được yêu cầu cũng cần được xác định.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
When using fire in Git Bash on Windows, the initialize_or_disable function in the formatting_windows.py unnecessarily invokes colorama.init(wrap=True) even though Git Bash already supports native ANSI escape sequences. This behavior causes issues, such as double-wrapped output or incorrect handling of ANSI sequences, which can lead to degraded user experience or unexpected output.
Steps to Reproduce
-
Use Git Bash on a Windows system.
-
Run a script that uses
firewith formatting enabled. -
Observe that the output is handled incorrectly due to the invocation of
colorama.init(wrap=True).
Root Cause Analysis
The initialize_or_disable function currently does not differentiate between Git Bash and other Windows environments like cmd.exe or powershell.exe. Specifically:
-
Git Bash natively supports ANSI escape sequences.
-
The function does not explicitly check for Git Bash and thus assumes it must handle formatting via
colorama. -
This leads to
colorama.init(wrap=True)being invoked unnecessarily, causing redundant processing and potential output issues.
Proposed Solution
Add an explicit check for Git Bash environments in the initialize_or_disable function. This can be achieved by inspecting environment variables such as MSYSTEM or TERM, which are typically set in Git Bash.
Additionally, provide a configuration option to control whether the formatting_windows functionality is enabled or disabled. This will allow users to explicitly manage how formatting is handled.
Suggested Changes
Modify initialize_or_disable to detect Git Bash:
def initialize_or_disable():
is_git_bash = os.environ.get('MSYSTEM') or os.environ.get('TERM') in ['xterm', 'xterm-256color']
if is_git_bash:
print("Detected Git Bash, skipping colorama.init")
return # Skip colorama initialization for Git Bash
# Existing logic for colorama and ANSI initialization
Add a configuration flag to enable or disable the formatting_windows logic explicitly. For example:
ENABLE_FORMATTING_WINDOWS = os.environ.get('ENABLE_FORMATTING_WINDOWS', '1') == '1'
if ENABLE_FORMATTING_WINDOWS:
initialize_or_disable()
else:
print("Formatting for Windows is disabled")
Please consider implementing the above solution
- Ngôn ngữ chính
- Python
- Star
- 28.2k
- Fork
- 1.5k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/python-fire
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
google/python-fire#693 ·
-
Release 0.7.2? Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
google/python-fire#698 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
google/python-fire#672 · 5 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
google/python-fire#665 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
google/python-fire#659 · 1 bình luận ·
Tất cả issue của google/python-fire
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
canonical/paas-charm#368 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
tech debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
addition to tracking list Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
StevenBlack/hosts#3256 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
qualcomm/qai-appbuilder#275 ·