Skip to content

Commit

Permalink
[cli] Add prompt command for CLI logger. (#9897)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Liaw <[email protected]>
  • Loading branch information
robertnishihara and richardliaw committed Aug 31, 2020
1 parent 5d4d67c commit 0bba548
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion python/ray/autoscaler/cli_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ def confirm(self,
confirm_str = cf.underlined("Confirm [" + yn_str + "]:") + " "

rendered_message = _format_msg(msg, *args, **kwargs)
if rendered_message and rendered_message[-1] != "\n":
# the rendered message ends with ascii coding
if rendered_message and not msg.endswith("\n"):
rendered_message += " "

msg_len = len(rendered_message.split("\n")[-1])
Expand Down Expand Up @@ -602,6 +603,35 @@ def confirm(self,

return res

def prompt(self, msg: str, *args, **kwargs):
"""Prompt the user for some text input.
Args:
msg (str): The mesage to display to the user before the prompt.
Returns:
The string entered by the user.
"""
if self.old_style:
return

complete_str = cf.underlined(msg)
rendered_message = _format_msg(complete_str, *args, **kwargs)
# the rendered message ends with ascii coding
if rendered_message and not msg.endswith("\n"):
rendered_message += " "
self._print(rendered_message, linefeed=False)

res = ""
try:
ans = sys.stdin.readline()
ans = ans.lower()
res = ans.strip()
except KeyboardInterrupt:
self.newline()

return res

def old_confirm(self, msg: str, yes: bool):
"""Old confirm dialog proxy.
Expand Down

0 comments on commit 0bba548

Please sign in to comment.