-
Notifications
You must be signed in to change notification settings - Fork 116
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]>
- Loading branch information
Showing
2 changed files
with
113 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
MIT License | ||
(C) 2024-2025 ramalama developers | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
""" | ||
import os | ||
import sys | ||
import locale | ||
import logging | ||
|
||
def is_locale_utf8(): | ||
"""Check if the system locale is UTF-8.""" | ||
lang = os.getenv("LC_CTYPE", "") or os.getenv("LANG", "") | ||
return "UTF-8" in lang.upper() or "utf8" in lang.lower() | ||
|
||
def supports_emoji(): | ||
"""Detect if the terminal supports emoji output.""" | ||
if not is_locale_utf8(): | ||
return False # Block emoji if UTF-8 is not in locale | ||
|
||
if sys.platform == "win32": # works 32, 64 bits machines | ||
# Windows Terminal, ConEmu, VSCode, and WSL support emoji | ||
if os.getenv("WT_SESSION") or os.getenv("ConEmuANSI") or os.getenv("TERM_PROGRAM") == "vscode": | ||
return True | ||
return False # Legacy cmd.exe and PowerShell lack proper emoji support | ||
|
||
return True # Most Linux/macOS terminals support emoji | ||
|
||
# Allow users to override emoji support via an environment variable | ||
EMOJI = os.getenv("RAMALAMA_FORCE_EMOJI", "1") != "0" and 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) |