forked from Mirror/pmbootstrap
pmbootstrap: add color support (MR 2090)
Can be disabled by setting the $NO_COLOR environment variable
This commit is contained in:
parent
e1aef47271
commit
87dd1d0961
3 changed files with 52 additions and 6 deletions
|
@ -50,13 +50,17 @@ def ask(args, question="Continue?", choices=["y", "n"], default="n",
|
|||
:param validation_regex: if set, keep asking until regex matches
|
||||
:param complete: set to a list to enable tab completion
|
||||
"""
|
||||
styles = pmb.config.styles
|
||||
|
||||
while True:
|
||||
date = datetime.datetime.now().strftime("%H:%M:%S")
|
||||
question_full = "[" + date + "] " + question
|
||||
line = question
|
||||
if choices:
|
||||
question_full += " (" + str.join("/", choices) + ")"
|
||||
line += f" ({str.join('/', choices)})"
|
||||
if default:
|
||||
question_full += " [" + str(default) + "]"
|
||||
line += f" [{default}]"
|
||||
line_color = f"[{date}] {styles['BOLD']}{line}{styles['END']}"
|
||||
line = f"[{date}] {line}"
|
||||
|
||||
if complete:
|
||||
readline.parse_and_bind('tab: complete')
|
||||
|
@ -67,7 +71,7 @@ def ask(args, question="Continue?", choices=["y", "n"], default="n",
|
|||
readline.set_completer(
|
||||
ReadlineTabCompleter(complete).completer_func)
|
||||
|
||||
ret = input(question_full + ": ")
|
||||
ret = input(f"{line_color}: ")
|
||||
|
||||
# Stop completing (question is answered)
|
||||
if complete:
|
||||
|
@ -79,7 +83,7 @@ def ask(args, question="Continue?", choices=["y", "n"], default="n",
|
|||
if ret == "":
|
||||
ret = str(default)
|
||||
|
||||
args.logfd.write(question_full + " " + ret + "\n")
|
||||
args.logfd.write(f"{line}: {ret}\n")
|
||||
args.logfd.flush()
|
||||
|
||||
# Validate with regex
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue