google / google/python-fire

formatting_windows.initialize_or_disable breaks ansi escape codes

Đang mở
#339 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
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

Mô tả

A recent modification added a call to `SetConsoleMode` that enables virtual terminal processing on Windows. This change prevents parent processes from receiving ANSI escape codes in the stdout of child processes. The only means to work around this, at the moment, is to comment out the call `initialize_or_disable`. In my opinion, modifying the console mode is outside of the scope and Fire and should not be happening

Below is a script that demonstrates the issue.
```
import fire, subprocess, sys

__color_names__ = ('red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white')

def print_with_colors():
parts = []
color_off = '\x1b[0m'
for index, color_name in enumerate(__color_names__):
color_on = '\x1b[{}m'.format(31+index)
parts.append(f'{color_on}{color_name}{color_off}')
print(' '.join(parts))

def test_case_1():
"""print with ansi colors in the current process"""
print_with_colors()

def test_case_2():
"""print with ansi colors from sub process"""
cmd = [sys.executable, sys.argv[0], 'print_with_colors']
completed = subprocess.run(cmd, check=True, capture_output=True, text=True)
print(completed.stdout)

if __name__ == '__main__':
if len(sys.argv) == 1:
test_case_1()
test_case_2()
else:
fire.Fire()
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

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.