mirror of
https://github.com/esphome/esphome.git
synced 2025-09-10 07:12:21 +01:00
Wizard: fix colored text in input prompts (#5313)
This commit is contained in:
committed by
GitHub
parent
2c2821cd96
commit
056a28906b
@@ -57,7 +57,7 @@ class SimpleRegistry(dict):
|
||||
return decorator
|
||||
|
||||
|
||||
def safe_print(message=""):
|
||||
def safe_print(message="", end="\n"):
|
||||
from esphome.core import CORE
|
||||
|
||||
if CORE.dashboard:
|
||||
@@ -67,20 +67,26 @@ def safe_print(message=""):
|
||||
pass
|
||||
|
||||
try:
|
||||
print(message)
|
||||
print(message, end=end)
|
||||
return
|
||||
except UnicodeEncodeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
print(message.encode("utf-8", "backslashreplace"))
|
||||
print(message.encode("utf-8", "backslashreplace"), end=end)
|
||||
except UnicodeEncodeError:
|
||||
try:
|
||||
print(message.encode("ascii", "backslashreplace"))
|
||||
print(message.encode("ascii", "backslashreplace"), end=end)
|
||||
except UnicodeEncodeError:
|
||||
print("Cannot print line because of invalid locale!")
|
||||
|
||||
|
||||
def safe_input(prompt=""):
|
||||
if prompt:
|
||||
safe_print(prompt, end="")
|
||||
return input()
|
||||
|
||||
|
||||
def shlex_quote(s):
|
||||
if not s:
|
||||
return "''"
|
||||
|
Reference in New Issue
Block a user