Can't show ansi color on windows if use git bash
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- bash, python
- 領域
- cli, operating-systems
調査の方向性
formatting_windows.py の initialize_or_disable から始め、Windows 環境が現在どのように colorama を初期化するかどうかを判断しているかを調べます。Git Bash での動作を再現し、その後、他の Windows シェルが既存の処理を維持する一方で、Git Bash が不要なラッピングを回避することを確認します。要求された設定オプションのスコープと動作も確定する必要があります。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 28.2k
- フォーク
- 1.5k
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/python-fire のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
google/python-fire#693 ·
-
Release 0.7.2? オープン
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
google/python-fire#698 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
google/python-fire#672 · コメント 5 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
google/python-fire#665 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
google/python-fire#659 · コメント 1 件 ·
google/python-fire の issue をすべて見る
似ている issue
-
Add: hunch オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DiamondLightSource/dodal#2211 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
openml/openml-python#1749 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
sipyourdrink-ltd/bernstein#6191 ·