-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- if timeout happens we try 5 times before sending Timeout error to users. - improve user experience when timeout occurs - Added console source tree for handling messages Resolves: #693 Signed-off-by: Douglas Schilling Landgraf <[email protected]> Signed-off-by: Douglas Schilling Landgraf <[email protected]>
- Loading branch information
Showing
3 changed files
with
96 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import sys | ||
import locale | ||
import logging | ||
|
||
def is_locale_utf8(): | ||
"""Check if the system locale is UTF-8.""" | ||
return 'UTF-8' in os.getenv('LC_CTYPE', '') or 'UTF-8' in os.getenv('LANG', '') | ||
|
||
def supports_emoji(): | ||
"""Detect if the terminal supports emoji output.""" | ||
term = os.getenv("TERM") | ||
if not term or term in ("dumb", "linux"): | ||
return False | ||
|
||
return is_locale_utf8() | ||
|
||
# Allow users to override emoji support via an environment variable | ||
# If RAMALAMA_FORCE_EMOJI is not set, it defaults to checking supports_emoji() | ||
RAMALAMA_FORCE_EMOJI = os.getenv("RAMALAMA_FORCE_EMOJI") | ||
FORCE_EMOJI = RAMALAMA_FORCE_EMOJI.lower() == "true" if RAMALAMA_FORCE_EMOJI else None | ||
EMOJI = FORCE_EMOJI if FORCE_EMOJI is not None else supports_emoji() | ||
|
||
# Define emoji-aware logging messages | ||
def error(msg): | ||
formatted_msg = f"❌ {msg}" if EMOJI else f"[ERROR] {msg}" | ||
logging.error(formatted_msg) | ||
|
||
def warning(msg): | ||
formatted_msg = f"⚠️ {msg}" if EMOJI else f"[WARNING] {msg}" | ||
logging.warning(formatted_msg) | ||
|
||
def info(msg): | ||
formatted_msg = f"ℹ️ {msg}" if EMOJI else f"[INFO] {msg}" | ||
logging.info(formatted_msg) |