Skip to content

Commit 75c28e4

Browse files
committed
build: bootstrap prompts use colors
1 parent e7e3ef5 commit 75c28e4

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

bootstrap.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ def prompt_string(self, prompt, default):
189189
: param default: The default value to use if the user does not provide input.
190190
:return:
191191
"""
192+
prompt = prompt.strip()
193+
if prompt.endswith('.'):
194+
prompt = prompt[:-1]
195+
prompt = prompt.strip()
196+
BLUE = "\033[94m"
197+
RESET = "\033[0m"
198+
if self.supports_ansi():
199+
prompt = f"{BLUE}{prompt}{RESET}"
192200
inp = input(f"{prompt} ({default}): ")
193201
result = inp.strip() or default
194202
return result
@@ -201,6 +209,14 @@ def prompt_boolean(self, prompt, default = None):
201209
:param default: The default value to return if the user does not provide input.
202210
:return: bool: True if the user answers yes, False otherwise.
203211
"""
212+
prompt = prompt.strip()
213+
if prompt.endswith('.'):
214+
prompt = prompt[:-1]
215+
prompt = prompt.strip()
216+
BLUE = "\033[94m"
217+
RESET = "\033[0m"
218+
if self.supports_ansi():
219+
prompt = f"{BLUE}{prompt}{RESET}"
204220
while True:
205221
answer = input(f"{prompt} ({'y/n' if default is None else 'yes' if default else 'no'}): ").strip().lower()
206222
if answer in ('y', 'yes'):
@@ -338,17 +354,10 @@ def run_cmd(self, cmd, cwd=None):
338354
"""
339355
BLUE = "\033[94m"
340356
RESET = "\033[0m"
341-
def supports_ansi():
342-
if os.name == "posix":
343-
return True
344-
if os.name == "nt":
345-
return "WT_SESSION" in os.environ or sys.stdout.isatty()
346-
return False
347-
348357
if cwd is None:
349358
cwd = os.getcwd()
350-
color = BLUE if supports_ansi() else ""
351-
reset = RESET if supports_ansi() else ""
359+
color = BLUE if self.supports_ansi() else ""
360+
reset = RESET if self.supports_ansi() else ""
352361
if isinstance(cmd, list):
353362
print(f"{color}{cwd}> {' '.join(cmd)}{reset}")
354363
else:

0 commit comments

Comments
 (0)