Can't show ansi color on windows if use git bash
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- bash, python
- Ambito
- cli, operating-systems
Direzione di ricerca
Inizia in formatting_windows.py, in initialize_or_disable, e analizza come gli ambienti Windows decidono attualmente se inizializzare colorama. Riproduci il comportamento in Git Bash, quindi verifica che Git Bash eviti il wrapping non necessario mentre le altre shell Windows mantengano la gestione esistente. È inoltre necessario definire l'ambito e il comportamento dell'opzione di configurazione richiesta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 28.2k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/python-fire
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
google/python-fire#693 ·
-
Release 0.7.2? Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
google/python-fire#698 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
google/python-fire#672 · 5 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
google/python-fire#665 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
google/python-fire#659 · 1 commento ·
Tutte le issue di google/python-fire
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
canonical/paas-charm#368 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
tech debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
addition to tracking list Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
StevenBlack/hosts#3256 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
qualcomm/qai-appbuilder#275 ·